Skip to content
This repository was archived by the owner on Oct 15, 2024. It is now read-only.

Commit 1546f86

Browse files
msfjarvisfmeum
andcommitted
Wire in fallback key selection flow (#958)
Co-authored-by: Fabian Henneke <[email protected]> (cherry picked from commit 084b833)
1 parent 859da9d commit 1546f86

File tree

5 files changed

+242
-135
lines changed

5 files changed

+242
-135
lines changed

app/src/main/AndroidManifest.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,11 @@
8181
android:parentActivityName=".PasswordStore"
8282
android:windowSoftInputMode="adjustResize" />
8383

84+
<activity
85+
android:name=".crypto.GetKeyIdsActivity"
86+
android:parentActivityName=".PasswordStore"
87+
android:theme="@style/NoBackgroundTheme" />
88+
8489
<service
8590
android:name=".autofill.AutofillService"
8691
android:enabled="@bool/enable_accessibility_autofill"
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*
2+
* Copyright © 2014-2020 The Android Password Store Authors. All Rights Reserved.
3+
* SPDX-License-Identifier: GPL-3.0-only
4+
*/
5+
6+
package com.zeapo.pwdstore.crypto
7+
8+
import android.content.Intent
9+
import android.os.Bundle
10+
import androidx.activity.result.IntentSenderRequest
11+
import androidx.activity.result.contract.ActivityResultContracts.StartIntentSenderForResult
12+
import androidx.lifecycle.lifecycleScope
13+
import com.github.ajalt.timberkt.e
14+
import kotlinx.coroutines.Dispatchers
15+
import kotlinx.coroutines.launch
16+
import me.msfjarvis.openpgpktx.util.OpenPgpApi
17+
import me.msfjarvis.openpgpktx.util.OpenPgpUtils
18+
import org.openintents.openpgp.IOpenPgpService2
19+
20+
class GetKeyIdsActivity : BasePgpActivity() {
21+
22+
private val userInteractionRequiredResult = registerForActivityResult(StartIntentSenderForResult()) { result ->
23+
if (result.data == null || result.resultCode == RESULT_CANCELED) {
24+
setResult(RESULT_CANCELED, result.data)
25+
finish()
26+
return@registerForActivityResult
27+
}
28+
getKeyIds(result.data!!)
29+
}
30+
31+
override fun onCreate(savedInstanceState: Bundle?) {
32+
super.onCreate(savedInstanceState)
33+
bindToOpenKeychain(this)
34+
}
35+
36+
override fun onBound(service: IOpenPgpService2) {
37+
super.onBound(service)
38+
getKeyIds()
39+
}
40+
41+
override fun onError(e: Exception) {
42+
e(e)
43+
}
44+
45+
/**
46+
* Get the Key ids from OpenKeychain
47+
*/
48+
private fun getKeyIds(data: Intent = Intent()) {
49+
data.action = OpenPgpApi.ACTION_GET_KEY_IDS
50+
lifecycleScope.launch(Dispatchers.IO) {
51+
api?.executeApiAsync(data, null, null) { result ->
52+
when (result?.getIntExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_ERROR)) {
53+
OpenPgpApi.RESULT_CODE_SUCCESS -> {
54+
try {
55+
val ids = result.getLongArrayExtra(OpenPgpApi.RESULT_KEY_IDS)?.map {
56+
OpenPgpUtils.convertKeyIdToHex(it)
57+
} ?: emptyList()
58+
val keyResult = Intent().putExtra(OpenPgpApi.EXTRA_KEY_IDS, ids.toTypedArray())
59+
setResult(RESULT_OK, keyResult)
60+
finish()
61+
} catch (e: Exception) {
62+
e(e)
63+
}
64+
}
65+
OpenPgpApi.RESULT_CODE_USER_INTERACTION_REQUIRED -> {
66+
val sender = getUserInteractionRequestIntent(result)
67+
userInteractionRequiredResult.launch(IntentSenderRequest.Builder(sender).build())
68+
}
69+
OpenPgpApi.RESULT_CODE_ERROR -> handleError(result)
70+
}
71+
}
72+
}
73+
}
74+
}

0 commit comments

Comments
 (0)