Use binder to get AIDL descriptor in Rust
Using the binder object we can directly get names of interfaces
rather than hardcoding the strings. This allows for lookup to be easier.
Test: atest keystore2_test and atest CtsKeystoreTestCases
Bug: 249096262
Change-Id: I74bc696b860e2c08286b1d5175378e8d44728858
diff --git a/keystore2/src/shared_secret_negotiation.rs b/keystore2/src/shared_secret_negotiation.rs
index 739f4ba..4839546 100644
--- a/keystore2/src/shared_secret_negotiation.rs
+++ b/keystore2/src/shared_secret_negotiation.rs
@@ -19,7 +19,8 @@
use android_hardware_security_keymint::aidl::android::hardware::security::keymint::SecurityLevel::SecurityLevel;
use android_hardware_security_keymint::binder::Strong;
use android_hardware_security_sharedsecret::aidl::android::hardware::security::sharedsecret::{
- ISharedSecret::ISharedSecret, SharedSecretParameters::SharedSecretParameters,
+ ISharedSecret::BpSharedSecret, ISharedSecret::ISharedSecret,
+ SharedSecretParameters::SharedSecretParameters,
};
use android_security_compat::aidl::android::security::compat::IKeystoreCompatService::IKeystoreCompatService;
use anyhow::Result;
@@ -63,11 +64,9 @@
impl Display for SharedSecretParticipant {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
match self {
- Self::Aidl(instance) => write!(
- f,
- "{}.{}/{}",
- SHARED_SECRET_PACKAGE_NAME, SHARED_SECRET_INTERFACE_NAME, instance
- ),
+ Self::Aidl(instance) => {
+ write!(f, "{}/{}", <BpSharedSecret as ISharedSecret>::get_descriptor(), instance)
+ }
Self::Hidl { is_strongbox, version: (ma, mi) } => write!(
f,
"{}@V{}.{}::{}/{}",
@@ -110,10 +109,6 @@
static KEYMASTER_PACKAGE_NAME: &str = "android.hardware.keymaster";
static KEYMASTER_INTERFACE_NAME: &str = "IKeymasterDevice";
-static SHARED_SECRET_PACKAGE_NAME: &str = "android.hardware.security.sharedsecret";
-static SHARED_SECRET_INTERFACE_NAME: &str = "ISharedSecret";
-static SHARED_SECRET_PACKAGE_AND_INTERFACE_NAME: &str =
- "android.hardware.security.sharedsecret.ISharedSecret";
static COMPAT_PACKAGE_NAME: &str = "android.security.compat";
/// Lists participants.
@@ -144,7 +139,7 @@
.collect::<Vec<SharedSecretParticipant>>()
})
.chain({
- get_declared_instances(SHARED_SECRET_PACKAGE_AND_INTERFACE_NAME)
+ get_declared_instances(<BpSharedSecret as ISharedSecret>::get_descriptor())
.unwrap()
.into_iter()
.map(SharedSecretParticipant::Aidl)
@@ -166,8 +161,9 @@
match e {
SharedSecretParticipant::Aidl(instance_name) => {
let service_name = format!(
- "{}.{}/{}",
- SHARED_SECRET_PACKAGE_NAME, SHARED_SECRET_INTERFACE_NAME, instance_name
+ "{}/{}",
+ <BpSharedSecret as ISharedSecret>::get_descriptor(),
+ instance_name
);
match map_binder_status_code(binder::get_interface(&service_name)) {
Err(e) => {