diff options
author | 2024-11-11 01:10:56 +0000 | |
---|---|---|
committer | 2024-11-12 22:14:10 +0000 | |
commit | 6a5f6c8b106447220162568a79534e675d08e304 (patch) | |
tree | c0d3618e0ad722b1daf50dbc8f4b86de820be905 /framework-s/java | |
parent | 8f45dc40b9d97827f7fa63b79c4fd0292d9ed6c1 (diff) |
Move UserHandleCompat to framework-s for more convenient accessed
NO_IFTTT=Does not modify RoleParser logic
RelNote: N/A
Bug: 376728836
Flag: EXEMPT refactor
Test: build
Change-Id: I603adc9e8e584bbadda49903bca6c3aba30cad89
Diffstat (limited to 'framework-s/java')
-rw-r--r-- | framework-s/java/android/permission/internal/compat/UserHandleCompat.java | 66 | ||||
-rw-r--r-- | framework-s/java/android/permission/internal/compat/package-info.java | 22 |
2 files changed, 88 insertions, 0 deletions
diff --git a/framework-s/java/android/permission/internal/compat/UserHandleCompat.java b/framework-s/java/android/permission/internal/compat/UserHandleCompat.java new file mode 100644 index 000000000..8a3ec444d --- /dev/null +++ b/framework-s/java/android/permission/internal/compat/UserHandleCompat.java @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2021 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.permission.internal.compat; + +import android.annotation.UserIdInt; +import android.os.UserHandle; + +/** + * Helper for accessing features in {@link UserHandle}. + */ +public final class UserHandleCompat { + /** + * A user ID to indicate all users on the device. + */ + public static final int USER_ALL = UserHandle.ALL.getIdentifier(); + + /** + * A user ID to indicate an undefined user of the device. + * + * @see UserHandle#USER_NULL + */ + public static final @UserIdInt int USER_NULL = -10000; + + /** + * A user ID to indicate the "system" user of the device. + */ + public static final int USER_SYSTEM = UserHandle.SYSTEM.getIdentifier(); + + private UserHandleCompat() {} + + /** + * Get the user ID of a given UID. + * + * @param uid the UID + * @return the user ID + */ + @UserIdInt + public static int getUserId(int uid) { + return UserHandle.getUserHandleForUid(uid).getIdentifier(); + } + + /** + * Get the UID from the give user ID and app ID + * + * @param userId the user ID + * @param appId the app ID + * @return the UID + */ + public static int getUid(@UserIdInt int userId, int appId) { + return UserHandle.of(userId).getUid(appId); + } +} diff --git a/framework-s/java/android/permission/internal/compat/package-info.java b/framework-s/java/android/permission/internal/compat/package-info.java new file mode 100644 index 000000000..b78aac878 --- /dev/null +++ b/framework-s/java/android/permission/internal/compat/package-info.java @@ -0,0 +1,22 @@ +/* + * Copyright (C) 2021 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @hide + * TODO(b/146466118) remove this javadoc tag + */ +@android.annotation.Hide +package android.permission.internal.compat; |