diff --git a/app/src/main/java/io/github/vvb2060/keyattestation/home/HomeFragment.kt b/app/src/main/java/io/github/vvb2060/keyattestation/home/HomeFragment.kt index f614dac..cb64595 100644 --- a/app/src/main/java/io/github/vvb2060/keyattestation/home/HomeFragment.kt +++ b/app/src/main/java/io/github/vvb2060/keyattestation/home/HomeFragment.kt @@ -43,7 +43,11 @@ class HomeFragment : AppFragment(), HomeAdapter.Listener, MenuProvider { } private val save = registerForActivityResult(CreateDocument("application/x-pkcs7-certificates")) { - viewModel.save(requireContext().contentResolver, it) + viewModel.save(requireContext().contentResolver, it, "PKCS7") + } + + private val save2 = registerForActivityResult(CreateDocument("application/pkix-pkipath")) { + viewModel.save(requireContext().contentResolver, it, "PkiPath") } private val load = registerForActivityResult(OpenDocument()) { @@ -167,6 +171,7 @@ class HomeFragment : AppFragment(), HomeAdapter.Listener, MenuProvider { isChecked = viewModel.preferShowAll } menu.findItem(R.id.menu_save).isVisible = viewModel.currentCerts != null + menu.findItem(R.id.menu_save2).isVisible = viewModel.currentCerts != null } override fun onCreateMenu(menu: Menu, menuInflater: MenuInflater) { @@ -202,6 +207,9 @@ class HomeFragment : AppFragment(), HomeAdapter.Listener, MenuProvider { R.id.menu_save -> { save.launch("${Build.PRODUCT}-${AppApplication.TAG}.p7b") } + R.id.menu_save2 -> { + save2.launch("${Build.PRODUCT}-${AppApplication.TAG}.pkipath") + } R.id.menu_load -> { load.launch(arrayOf("application/*")) } diff --git a/app/src/main/java/io/github/vvb2060/keyattestation/home/HomeViewModel.kt b/app/src/main/java/io/github/vvb2060/keyattestation/home/HomeViewModel.kt index d83c32f..13e4401 100644 --- a/app/src/main/java/io/github/vvb2060/keyattestation/home/HomeViewModel.kt +++ b/app/src/main/java/io/github/vvb2060/keyattestation/home/HomeViewModel.kt @@ -185,7 +185,7 @@ class HomeViewModel(pm: PackageManager, private val sp: SharedPreferences) : Vie return parseCertificateChain(certs) } - fun save(cr: ContentResolver, uri: Uri?) = AppApplication.executor.execute { + fun save(cr: ContentResolver, uri: Uri?, encoding: String) = AppApplication.executor.execute { val certs = currentCerts if (uri == null || certs == null) return@execute var name = uri.toString() @@ -199,7 +199,7 @@ class HomeViewModel(pm: PackageManager, private val sp: SharedPreferences) : Vie try { val cf = CertificateFactory.getInstance("X.509") cr.openOutputStream(uri)?.use { - it.write(cf.generateCertPath(certs).getEncoded("PKCS7")) + it.write(cf.generateCertPath(certs).getEncoded(encoding)) } ?: throw IOException("openOutputStream $uri failed") AppApplication.mainHandler.post { Toast.makeText(AppApplication.app, name, Toast.LENGTH_SHORT).show() diff --git a/app/src/main/res/menu/home.xml b/app/src/main/res/menu/home.xml index 63f468d..790988b 100644 --- a/app/src/main/res/menu/home.xml +++ b/app/src/main/res/menu/home.xml @@ -30,6 +30,11 @@ android:showAsAction="never" android:title="@string/save_certs" /> + + 认证设备属性 显示全部 从文件加载 - 保存到文件 + 保存到文件(p7b) + 保存到文件(pkipath) 关于 Attest device props Show all Load from file - Save to file + Save to file (p7b) + Save to file (pkipath) About