Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7993deb2 authored by Palak Chaudhary's avatar Palak Chaudhary
Browse files

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
parent ad326459
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -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();
+21 −0
Original line number Diff line number Diff line
@@ -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.
     */