From 6a5f6c8b106447220162568a79534e675d08e304 Mon Sep 17 00:00:00 2001 From: Richard MacGregor Date: Mon, 11 Nov 2024 01:10:56 +0000 Subject: 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 --- .../internal/compat/UserHandleCompat.java | 66 ++++++++++++++++++++++ .../permission/internal/compat/package-info.java | 22 ++++++++ 2 files changed, 88 insertions(+) create mode 100644 framework-s/java/android/permission/internal/compat/UserHandleCompat.java create mode 100644 framework-s/java/android/permission/internal/compat/package-info.java (limited to 'framework-s/java') 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; -- cgit v1.2.3-59-g8ed1b