blob: 0c8cc5ec35efc8f1528eb1a6f49727d3c5ffadd7 [file] [log] [blame]
Joel Galensone1f608a2021-07-30 07:38:37 -07001// 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
17pub use cutils_bindgen::AID_KEYSTORE;
Alan Stokes78ad0a82021-11-16 15:16:06 +000018pub use cutils_bindgen::AID_ROOT;
19pub use cutils_bindgen::AID_SHELL;
20pub use cutils_bindgen::AID_SYSTEM;
Joel Galensone1f608a2021-07-30 07:38:37 -070021pub use cutils_bindgen::AID_USER_OFFSET;
22
23/// Gets the user id from a uid.
24pub fn multiuser_get_user_id(uid: u32) -> u32 {
25 uid / AID_USER_OFFSET
26}
27
28/// Gets the app id from a uid.
29pub 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.
34pub fn multiuser_get_uid(user_id: u32, app_id: u32) -> u32 {
35 (user_id * AID_USER_OFFSET) + (app_id % AID_USER_OFFSET)
36}