keystore2: Use libbinder_rs Strong references for Binder objects
Update keystore2 to use libbinder_rs Strong<> and Weak<> references for
Binder objects rather than just Box<dyn Interface>.
Bug: 175584883
Test: atest keystore2_test
Change-Id: Ic234ce5ed007a265769a72043d77eb817a21b8ea
diff --git a/keystore2/src/operation.rs b/keystore2/src/operation.rs
index 18ea19f..c98a76b 100644
--- a/keystore2/src/operation.rs
+++ b/keystore2/src/operation.rs
@@ -137,7 +137,7 @@
IKeystoreOperation::BnKeystoreOperation, IKeystoreOperation::IKeystoreOperation,
};
use anyhow::{anyhow, Context, Result};
-use binder::{IBinder, Interface};
+use binder::IBinder;
use std::{
collections::HashMap,
sync::{Arc, Mutex, MutexGuard, Weak},
@@ -184,7 +184,7 @@
/// Constructor
pub fn new(
index: usize,
- km_op: Box<dyn IKeyMintOperation>,
+ km_op: binder::Strong<dyn IKeyMintOperation>,
owner: u32,
auth_info: AuthInfo,
) -> Self {
@@ -247,13 +247,14 @@
}
*locked_outcome = Outcome::Pruned;
- let km_op: Box<dyn IKeyMintOperation> = match self.km_op.get_interface() {
- Ok(km_op) => km_op,
- Err(e) => {
- log::error!("In prune: Failed to get KeyMintOperation interface.\n {:?}", e);
- return Err(Error::sys());
- }
- };
+ let km_op: binder::public_api::Strong<dyn IKeyMintOperation> =
+ match self.km_op.get_interface() {
+ Ok(km_op) => km_op,
+ Err(e) => {
+ log::error!("In prune: Failed to get KeyMintOperation interface.\n {:?}", e);
+ return Err(Error::sys());
+ }
+ };
// We abort the operation. If there was an error we log it but ignore it.
if let Err(e) = map_km_error(km_op.abort()) {
@@ -334,7 +335,7 @@
let mut out_params: Option<KeyParameterArray> = None;
let mut output: Option<ByteArray> = None;
- let km_op: Box<dyn IKeyMintOperation> =
+ let km_op: binder::public_api::Strong<dyn IKeyMintOperation> =
self.km_op.get_interface().context("In update: Failed to get KeyMintOperation.")?;
let (hat, tst) = self
@@ -369,7 +370,7 @@
let mut out_params: Option<KeyParameterArray> = None;
- let km_op: Box<dyn IKeyMintOperation> =
+ let km_op: binder::public_api::Strong<dyn IKeyMintOperation> =
self.km_op.get_interface().context("In update: Failed to get KeyMintOperation.")?;
let (hat, tst) = self
@@ -426,7 +427,7 @@
let mut out_params: Option<KeyParameterArray> = None;
- let km_op: Box<dyn IKeyMintOperation> =
+ let km_op: binder::public_api::Strong<dyn IKeyMintOperation> =
self.km_op.get_interface().context("In finish: Failed to get KeyMintOperation.")?;
let (hat, tst, confirmation_token) = self
@@ -475,7 +476,7 @@
fn abort(&self, outcome: Outcome) -> Result<()> {
let mut locked_outcome = self.check_active().context("In abort")?;
*locked_outcome = outcome;
- let km_op: Box<dyn IKeyMintOperation> =
+ let km_op: binder::public_api::Strong<dyn IKeyMintOperation> =
self.km_op.get_interface().context("In abort: Failed to get KeyMintOperation.")?;
map_km_error(km_op.abort()).context("In abort: KeyMint::abort failed.")
@@ -514,7 +515,7 @@
/// owner uid and returns a new Operation wrapped in a `std::sync::Arc`.
pub fn create_operation(
&self,
- km_op: Box<dyn IKeyMintOperation>,
+ km_op: binder::public_api::Strong<dyn IKeyMintOperation>,
owner: u32,
auth_info: AuthInfo,
) -> Arc<Operation> {
@@ -770,7 +771,9 @@
/// BnKeystoreOperation proxy object. It also
/// calls `IBinder::set_requesting_sid` on the new interface, because
/// we need it for checking Keystore permissions.
- pub fn new_native_binder(operation: Arc<Operation>) -> impl IKeystoreOperation + Send {
+ pub fn new_native_binder(
+ operation: Arc<Operation>,
+ ) -> binder::public_api::Strong<dyn IKeystoreOperation> {
let result =
BnKeystoreOperation::new_binder(Self { operation: Mutex::new(Some(operation)) });
result.as_binder().set_requesting_sid(true);