Replace uid_to_android_user with libcutils_bindgen.
Fixes: 175619259
Test: keystore2_test
Change-Id: Ib105ae39c73edfcdd61c8428695e853232756298
diff --git a/keystore2/Android.bp b/keystore2/Android.bp
index c69774d..7d2d8de 100644
--- a/keystore2/Android.bp
+++ b/keystore2/Android.bp
@@ -39,6 +39,7 @@
"android.system.keystore2-V1-rust",
"libanyhow",
"libbinder_rs",
+ "libcutils_bindgen",
"libkeystore2_aaid-rust",
"libkeystore2_apc_compat-rust",
"libkeystore2_crypto_rust",
@@ -54,6 +55,9 @@
"librusqlite",
"libthiserror",
],
+ shared_libs: [
+ "libcutils",
+ ],
}
rust_library {
diff --git a/keystore2/src/utils.rs b/keystore2/src/utils.rs
index 2748025..7b58205 100644
--- a/keystore2/src/utils.rs
+++ b/keystore2/src/utils.rs
@@ -215,12 +215,12 @@
}
/// AID offset for uid space partitioning.
-/// TODO: Replace with bindgen generated from libcutils. b/175619259
-pub const AID_USER_OFFSET: u32 = 100000;
+pub const AID_USER_OFFSET: u32 = cutils_bindgen::AID_USER_OFFSET;
/// Extracts the android user from the given uid.
pub fn uid_to_android_user(uid: u32) -> u32 {
- uid / AID_USER_OFFSET
+ // Safety: No memory access
+ unsafe { cutils_bindgen::multiuser_get_user_id(uid) }
}
#[cfg(test)]