|
@@ -10,6 +10,7 @@ import android.service.autofill.FillResponse
|
|
import android.view.autofill.AutofillId
|
|
import android.view.autofill.AutofillId
|
|
import android.view.autofill.AutofillValue
|
|
import android.view.autofill.AutofillValue
|
|
import android.widget.RemoteViews
|
|
import android.widget.RemoteViews
|
|
|
|
+import com.fastest.pass.R
|
|
import com.fastest.pass.home.domain.model.AddPassword
|
|
import com.fastest.pass.home.domain.model.AddPassword
|
|
import com.fastest.pass.sharedpref.CredentialManager
|
|
import com.fastest.pass.sharedpref.CredentialManager
|
|
|
|
|
|
@@ -32,9 +33,9 @@ class FastestPassAutofillService : AutofillService() {
|
|
}
|
|
}
|
|
|
|
|
|
// Fetch credentials matching the package name or domain
|
|
// Fetch credentials matching the package name or domain
|
|
- /* val data = getCredentials().filter {
|
|
|
|
- it.url.contains(packageName)
|
|
|
|
- }*/
|
|
|
|
|
|
+ /* val data = getCredentials().filter {
|
|
|
|
+ it.url.contains(packageName)
|
|
|
|
+ }*/
|
|
val data = getCredentials()
|
|
val data = getCredentials()
|
|
|
|
|
|
if (data.isEmpty()) {
|
|
if (data.isEmpty()) {
|
|
@@ -46,48 +47,48 @@ class FastestPassAutofillService : AutofillService() {
|
|
for (i in 0 until structure.windowNodeCount) {
|
|
for (i in 0 until structure.windowNodeCount) {
|
|
val windowNode = structure.getWindowNodeAt(i)
|
|
val windowNode = structure.getWindowNodeAt(i)
|
|
val viewNode = windowNode.rootViewNode
|
|
val viewNode = windowNode.rootViewNode
|
|
- parseViewNode(viewNode, data, fillResponseBuilder)
|
|
|
|
|
|
+ parseViewNode(viewNode, data, fillResponseBuilder)
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- callback.onSuccess(fillResponseBuilder.build())
|
|
|
|
|
|
+ callback.onSuccess(fillResponseBuilder.build())
|
|
}
|
|
}
|
|
|
|
|
|
override fun onSaveRequest(
|
|
override fun onSaveRequest(
|
|
request: android.service.autofill.SaveRequest,
|
|
request: android.service.autofill.SaveRequest,
|
|
callback: android.service.autofill.SaveCallback
|
|
callback: android.service.autofill.SaveCallback
|
|
) {
|
|
) {
|
|
- /* val credentialManager = CredentialManager(applicationContext)
|
|
|
|
|
|
+ /* val credentialManager = CredentialManager(applicationContext)
|
|
|
|
|
|
- // Extracting the FillContexts from the SaveRequest
|
|
|
|
- val fillContexts = request.fillContexts
|
|
|
|
|
|
+ // Extracting the FillContexts from the SaveRequest
|
|
|
|
+ val fillContexts = request.fillContexts
|
|
|
|
|
|
- // For each field in the SaveRequest, extract the autofill values (email and password)
|
|
|
|
- val credentials = mutableListOf<AddPassword>()
|
|
|
|
|
|
+ // For each field in the SaveRequest, extract the autofill values (email and password)
|
|
|
|
+ val credentials = mutableListOf<AddPassword>()
|
|
|
|
|
|
- for (context in fillContexts) {
|
|
|
|
- val structure = context.structure
|
|
|
|
|
|
+ for (context in fillContexts) {
|
|
|
|
+ val structure = context.structure
|
|
|
|
|
|
- // Loop through the views in the structure and extract the autofill values
|
|
|
|
- for (i in 0 until structure.windowNodeCount) {
|
|
|
|
- val windowNode = structure.getWindowNodeAt(i)
|
|
|
|
- val rootNode = windowNode.rootViewNode
|
|
|
|
|
|
+ // Loop through the views in the structure and extract the autofill values
|
|
|
|
+ for (i in 0 until structure.windowNodeCount) {
|
|
|
|
+ val windowNode = structure.getWindowNodeAt(i)
|
|
|
|
+ val rootNode = windowNode.rootViewNode
|
|
|
|
|
|
- // Extract the values from the autofill fields
|
|
|
|
- val title = extractAutofillValue(rootNode, "personFirstName") ?: ""
|
|
|
|
- val url = extractAutofillValue(rootNode, "personLastName") ?: ""
|
|
|
|
- val username = extractAutofillValue(rootNode, "username") ?: ""
|
|
|
|
- val password = extractAutofillValue(rootNode, "password") ?: ""
|
|
|
|
- val notes = extractAutofillValue(rootNode, "addressStreet") ?: ""
|
|
|
|
|
|
+ // Extract the values from the autofill fields
|
|
|
|
+ val title = extractAutofillValue(rootNode, "personFirstName") ?: ""
|
|
|
|
+ val url = extractAutofillValue(rootNode, "personLastName") ?: ""
|
|
|
|
+ val username = extractAutofillValue(rootNode, "username") ?: ""
|
|
|
|
+ val password = extractAutofillValue(rootNode, "password") ?: ""
|
|
|
|
+ val notes = extractAutofillValue(rootNode, "addressStreet") ?: ""
|
|
|
|
|
|
- // Create a new Credential object and add it to the list
|
|
|
|
- val credential = AddPassword(title, url, username, password, notes)
|
|
|
|
- credentials.add(credential)
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ // Create a new Credential object and add it to the list
|
|
|
|
+ val credential = AddPassword(title, url, username, password, notes)
|
|
|
|
+ credentials.add(credential)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
- // Save the credentials in SharedPreferences
|
|
|
|
- credentialManager.saveCredentials(credentials)*/
|
|
|
|
|
|
+ // Save the credentials in SharedPreferences
|
|
|
|
+ credentialManager.saveCredentials(credentials)*/
|
|
|
|
|
|
callback.onSuccess()
|
|
callback.onSuccess()
|
|
}
|
|
}
|
|
@@ -132,13 +133,11 @@ class FastestPassAutofillService : AutofillService() {
|
|
|
|
|
|
if (username != null || emailAddress != null || passwordId != null) {
|
|
if (username != null || emailAddress != null || passwordId != null) {
|
|
credentials.forEach { credential ->
|
|
credentials.forEach { credential ->
|
|
- val presentation =
|
|
|
|
- RemoteViews(packageName, android.R.layout.simple_list_item_1).apply {
|
|
|
|
- setTextViewText(
|
|
|
|
- android.R.id.text1,
|
|
|
|
- "${credential.username} @ ${credential.url}"
|
|
|
|
- )
|
|
|
|
- }
|
|
|
|
|
|
+ val presentation = RemoteViews(packageName, R.layout.item_auto_fill).apply {
|
|
|
|
+ // Set the TextView text for the suggestion
|
|
|
|
+ setTextViewText(R.id.text, "${credential.username} @ ${credential.url}")
|
|
|
|
+ // Optionally, set an icon/image
|
|
|
|
+ }
|
|
val datasetBuilder = Dataset.Builder()
|
|
val datasetBuilder = Dataset.Builder()
|
|
emailAddress?.let {
|
|
emailAddress?.let {
|
|
datasetBuilder.setValue(
|
|
datasetBuilder.setValue(
|
|
@@ -170,7 +169,7 @@ class FastestPassAutofillService : AutofillService() {
|
|
|
|
|
|
// Recursively parse child nodes
|
|
// Recursively parse child nodes
|
|
for (i in 0 until node.childCount) {
|
|
for (i in 0 until node.childCount) {
|
|
- parseViewNode(node.getChildAt(i), credentials, fillResponseBuilder)
|
|
|
|
|
|
+ parseViewNode(node.getChildAt(i), credentials, fillResponseBuilder)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|