From 7993deb28c2c38edff04eb1b181f26619d5987e1 Mon Sep 17 00:00:00 2001 From: Palak Chaudhary Date: Thu, 4 Jan 2024 11:59:52 +0000 Subject: [PATCH] API to get the sdk sandbox uid for an app uid There is an existing API, Process#toSdkSandboxUid() which is a system API and we want to make it public. But the naming is not consistent with the Process#getAppUidForSdkSandboxUid() API. To fix this inconsistency, a new API is added. Creates Process#getSdkSandboxUidForAppUid API which returns the sdk sandbox process uid for the app uid. Bug: 318486754 Test: atest ProcessTest Change-Id: I6dfd2cfbba608c88321d688632196bb4e1e877d1 --- core/api/current.txt | 1 + core/java/android/os/Process.java | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/core/api/current.txt b/core/api/current.txt index c7b921c8f6d5..6b2f95070f8c 100644 --- a/core/api/current.txt +++ b/core/api/current.txt @@ -33406,6 +33406,7 @@ package android.os { method public static final long getElapsedCpuTime(); method public static final int[] getExclusiveCores(); method public static final int getGidForName(String); + method @FlaggedApi("com.android.sdksandbox.flags.sdk_sandbox_uid_to_app_uid_api") public static final int getSdkSandboxUidForAppUid(int); method public static long getStartElapsedRealtime(); method public static long getStartRequestedElapsedRealtime(); method public static long getStartRequestedUptimeMillis(); diff --git a/core/java/android/os/Process.java b/core/java/android/os/Process.java index f952fcf36e60..dd0436cbb2f2 100644 --- a/core/java/android/os/Process.java +++ b/core/java/android/os/Process.java @@ -19,6 +19,7 @@ package android.os; import static android.annotation.SystemApi.Client.MODULE_LIBRARIES; import android.annotation.ElapsedRealtimeLong; +import android.annotation.FlaggedApi; import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.SuppressLint; @@ -37,6 +38,7 @@ import android.webkit.WebViewZygote; import com.android.internal.os.SomeArgs; import com.android.internal.util.Preconditions; +import com.android.sdksandbox.flags.Flags; import dalvik.system.VMRuntime; @@ -1016,10 +1018,29 @@ public class Process { @SystemApi(client = MODULE_LIBRARIES) @TestApi @android.ravenwood.annotation.RavenwoodKeep + // TODO(b/318651609): Deprecate once Process#getSdkSandboxUidForAppUid is rolled out to 100% public static final int toSdkSandboxUid(int uid) { return uid + (FIRST_SDK_SANDBOX_UID - FIRST_APPLICATION_UID); } + /** + * Returns the sdk sandbox uid corresponding to an app uid. + * @see android.app.sdksandbox.SdkSandboxManager + * + * @param uid the app uid + * @return the sdk sandbox uid for the given app uid + * + * @throws IllegalArgumentException if input is not an app uid + */ + @FlaggedApi(Flags.FLAG_SDK_SANDBOX_UID_TO_APP_UID_API) + @android.ravenwood.annotation.RavenwoodKeep + public static final int getSdkSandboxUidForAppUid(int uid) { + if (!isApplicationUid(uid)) { + throw new IllegalArgumentException("Input UID is not an app UID"); + } + return uid + (FIRST_SDK_SANDBOX_UID - FIRST_APPLICATION_UID); + } + /** * Returns whether the current process is a sdk sandbox process. */