1 // Copyright (C) 2021 The Android Open Source Project 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 //! Provides utilities for Android user ids. 16 17 pub use cutils_bindgen::AID_KEYSTORE; 18 pub use cutils_bindgen::AID_ROOT; 19 pub use cutils_bindgen::AID_SHELL; 20 pub use cutils_bindgen::AID_SYSTEM; 21 pub use cutils_bindgen::AID_USER_OFFSET; 22 23 /// Gets the user id from a uid. multiuser_get_user_id(uid: u32) -> u3224pub fn multiuser_get_user_id(uid: u32) -> u32 { 25 uid / AID_USER_OFFSET 26 } 27 28 /// Gets the app id from a uid. multiuser_get_app_id(uid: u32) -> u3229pub fn multiuser_get_app_id(uid: u32) -> u32 { 30 uid % AID_USER_OFFSET 31 } 32 33 /// Gets the uid from a user id and app id. multiuser_get_uid(user_id: u32, app_id: u32) -> u3234pub fn multiuser_get_uid(user_id: u32, app_id: u32) -> u32 { 35 (user_id * AID_USER_OFFSET) + (app_id % AID_USER_OFFSET) 36 } 37