Joel Galenson | e1f608a | 2021-07-30 07:38:37 -0700 | [diff] [blame] | 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; |
Alan Stokes | 78ad0a8 | 2021-11-16 15:16:06 +0000 | [diff] [blame] | 18 | pub use cutils_bindgen::AID_ROOT; |
| 19 | pub use cutils_bindgen::AID_SHELL; |
| 20 | pub use cutils_bindgen::AID_SYSTEM; |
Joel Galenson | e1f608a | 2021-07-30 07:38:37 -0700 | [diff] [blame] | 21 | pub use cutils_bindgen::AID_USER_OFFSET; |
| 22 | |
| 23 | /// Gets the user id from a uid. |
| 24 | pub fn multiuser_get_user_id(uid: u32) -> u32 { |
| 25 | uid / AID_USER_OFFSET |
| 26 | } |
| 27 | |
| 28 | /// Gets the app id from a uid. |
| 29 | pub 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. |
| 34 | pub fn multiuser_get_uid(user_id: u32, app_id: u32) -> u32 { |
| 35 | (user_id * AID_USER_OFFSET) + (app_id % AID_USER_OFFSET) |
| 36 | } |