Loading core/java/android/os/Build.java +0 −6 Original line number Original line Diff line number Diff line Loading @@ -36,8 +36,6 @@ import android.util.ArraySet; import android.util.Slog; import android.util.Slog; import android.view.View; import android.view.View; import com.android.internal.ravenwood.RavenwoodEnvironment; import dalvik.system.VMRuntime; import dalvik.system.VMRuntime; import java.util.ArrayList; import java.util.ArrayList; Loading @@ -51,10 +49,6 @@ import java.util.stream.Collectors; */ */ @RavenwoodKeepWholeClass @RavenwoodKeepWholeClass public class Build { public class Build { static { // Set up the default system properties. RavenwoodEnvironment.ensureRavenwoodInitialized(); } private static final String TAG = "Build"; private static final String TAG = "Build"; /** Value used for when a build property is unknown. */ /** Value used for when a build property is unknown. */ Loading core/java/android/os/ParcelFileDescriptor.java +0 −8 Original line number Original line Diff line number Diff line Loading @@ -41,7 +41,6 @@ import android.content.ContentResolver; import android.net.Uri; import android.net.Uri; import android.os.MessageQueue.OnFileDescriptorEventListener; import android.os.MessageQueue.OnFileDescriptorEventListener; import android.ravenwood.annotation.RavenwoodKeepWholeClass; import android.ravenwood.annotation.RavenwoodKeepWholeClass; import android.ravenwood.annotation.RavenwoodReplace; import android.ravenwood.annotation.RavenwoodThrow; import android.ravenwood.annotation.RavenwoodThrow; import android.system.ErrnoException; import android.system.ErrnoException; import android.system.Os; import android.system.Os; Loading @@ -51,8 +50,6 @@ import android.util.CloseGuard; import android.util.Log; import android.util.Log; import android.util.Slog; import android.util.Slog; import com.android.internal.ravenwood.RavenwoodEnvironment; import dalvik.system.VMRuntime; import dalvik.system.VMRuntime; import libcore.io.IoUtils; import libcore.io.IoUtils; Loading Loading @@ -1254,15 +1251,10 @@ public class ParcelFileDescriptor implements Parcelable, Closeable { } } } } @RavenwoodReplace private static boolean isAtLeastQ() { private static boolean isAtLeastQ() { return (VMRuntime.getRuntime().getTargetSdkVersion() >= Build.VERSION_CODES.Q); return (VMRuntime.getRuntime().getTargetSdkVersion() >= Build.VERSION_CODES.Q); } } private static boolean isAtLeastQ$ravenwood() { return RavenwoodEnvironment.workaround().isTargetSdkAtLeastQ(); } private static int ifAtLeastQ(int value) { private static int ifAtLeastQ(int value) { return isAtLeastQ() ? value : 0; return isAtLeastQ() ? value : 0; } } Loading core/java/android/os/Process.java +27 −97 Original line number Original line Diff line number Diff line Loading @@ -29,6 +29,11 @@ import android.annotation.TestApi; import android.annotation.UptimeMillisLong; import android.annotation.UptimeMillisLong; import android.compat.annotation.UnsupportedAppUsage; import android.compat.annotation.UnsupportedAppUsage; import android.os.Build.VERSION_CODES; import android.os.Build.VERSION_CODES; import android.ravenwood.annotation.RavenwoodKeep; import android.ravenwood.annotation.RavenwoodKeepPartialClass; import android.ravenwood.annotation.RavenwoodRedirect; import android.ravenwood.annotation.RavenwoodRedirectionClass; import android.ravenwood.annotation.RavenwoodReplace; import android.sysprop.MemoryProperties; import android.sysprop.MemoryProperties; import android.system.ErrnoException; import android.system.ErrnoException; import android.system.Os; import android.system.Os; Loading @@ -37,8 +42,6 @@ import android.system.StructPollfd; import android.util.Pair; import android.util.Pair; import android.webkit.WebViewZygote; import android.webkit.WebViewZygote; import com.android.internal.os.SomeArgs; import com.android.internal.util.Preconditions; import com.android.sdksandbox.flags.Flags; import com.android.sdksandbox.flags.Flags; import dalvik.system.VMDebug; import dalvik.system.VMDebug; Loading @@ -55,6 +58,8 @@ import java.util.concurrent.TimeoutException; /** /** * Tools for managing OS processes. * Tools for managing OS processes. */ */ @RavenwoodKeepPartialClass @RavenwoodRedirectionClass("Process_ravenwood") public class Process { public class Process { private static final String LOG_TAG = "Process"; private static final String LOG_TAG = "Process"; Loading Loading @@ -672,7 +677,6 @@ public class Process { */ */ public static final ZygoteProcess ZYGOTE_PROCESS = new ZygoteProcess(); public static final ZygoteProcess ZYGOTE_PROCESS = new ZygoteProcess(); /** /** * The process name set via {@link #setArgV0(String)}. * The process name set via {@link #setArgV0(String)}. */ */ Loading Loading @@ -846,47 +850,20 @@ public class Process { /** /** * Returns true if the current process is a 64-bit runtime. * Returns true if the current process is a 64-bit runtime. */ */ @android.ravenwood.annotation.RavenwoodKeep @RavenwoodKeep public static final boolean is64Bit() { public static final boolean is64Bit() { return VMRuntime.getRuntime().is64Bit(); return VMRuntime.getRuntime().is64Bit(); } } private static volatile ThreadLocal<SomeArgs> sIdentity$ravenwood; /** @hide */ @android.ravenwood.annotation.RavenwoodKeep public static void init$ravenwood(final int uid, final int pid) { sIdentity$ravenwood = ThreadLocal.withInitial(() -> { final SomeArgs args = SomeArgs.obtain(); args.argi1 = uid; args.argi2 = pid; args.argi3 = Long.hashCode(Thread.currentThread().getId()); args.argi4 = THREAD_PRIORITY_DEFAULT; args.arg1 = Boolean.TRUE; // backgroundOk return args; }); } /** @hide */ @android.ravenwood.annotation.RavenwoodKeep public static void reset$ravenwood() { sIdentity$ravenwood = null; } /** /** * Returns the identifier of this process, which can be used with * Returns the identifier of this process, which can be used with * {@link #killProcess} and {@link #sendSignal}. * {@link #killProcess} and {@link #sendSignal}. */ */ @android.ravenwood.annotation.RavenwoodReplace @RavenwoodKeep public static final int myPid() { public static final int myPid() { return Os.getpid(); return Os.getpid(); } } /** @hide */ public static final int myPid$ravenwood() { return Preconditions.requireNonNullViaRavenwoodRule(sIdentity$ravenwood).get().argi2; } /** /** * Returns the identifier of this process' parent. * Returns the identifier of this process' parent. * @hide * @hide Loading @@ -900,39 +877,29 @@ public class Process { * Returns the identifier of the calling thread, which be used with * Returns the identifier of the calling thread, which be used with * {@link #setThreadPriority(int, int)}. * {@link #setThreadPriority(int, int)}. */ */ @android.ravenwood.annotation.RavenwoodReplace @RavenwoodKeep public static final int myTid() { public static final int myTid() { return Os.gettid(); return Os.gettid(); } } /** @hide */ public static final int myTid$ravenwood() { return Preconditions.requireNonNullViaRavenwoodRule(sIdentity$ravenwood).get().argi3; } /** /** * Returns the identifier of this process's uid. This is the kernel uid * Returns the identifier of this process's uid. This is the kernel uid * that the process is running under, which is the identity of its * that the process is running under, which is the identity of its * app-specific sandbox. It is different from {@link #myUserHandle} in that * app-specific sandbox. It is different from {@link #myUserHandle} in that * a uid identifies a specific app sandbox in a specific user. * a uid identifies a specific app sandbox in a specific user. */ */ @android.ravenwood.annotation.RavenwoodReplace @RavenwoodKeep public static final int myUid() { public static final int myUid() { return Os.getuid(); return Os.getuid(); } } /** @hide */ public static final int myUid$ravenwood() { return Preconditions.requireNonNullViaRavenwoodRule(sIdentity$ravenwood).get().argi1; } /** /** * Returns this process's user handle. This is the * Returns this process's user handle. This is the * user the process is running under. It is distinct from * user the process is running under. It is distinct from * {@link #myUid()} in that a particular user will have multiple * {@link #myUid()} in that a particular user will have multiple * distinct apps running under it each with their own uid. * distinct apps running under it each with their own uid. */ */ @android.ravenwood.annotation.RavenwoodKeep @RavenwoodKeep public static UserHandle myUserHandle() { public static UserHandle myUserHandle() { return UserHandle.of(UserHandle.getUserId(myUid())); return UserHandle.of(UserHandle.getUserId(myUid())); } } Loading @@ -941,7 +908,7 @@ public class Process { * Returns whether the given uid belongs to a system core component or not. * Returns whether the given uid belongs to a system core component or not. * @hide * @hide */ */ @android.ravenwood.annotation.RavenwoodKeep @RavenwoodKeep public static boolean isCoreUid(int uid) { public static boolean isCoreUid(int uid) { return UserHandle.isCore(uid); return UserHandle.isCore(uid); } } Loading @@ -952,7 +919,7 @@ public class Process { * @return Whether the uid corresponds to an application sandbox running in * @return Whether the uid corresponds to an application sandbox running in * a specific user. * a specific user. */ */ @android.ravenwood.annotation.RavenwoodKeep @RavenwoodKeep public static boolean isApplicationUid(int uid) { public static boolean isApplicationUid(int uid) { return UserHandle.isApp(uid); return UserHandle.isApp(uid); } } Loading @@ -960,7 +927,7 @@ public class Process { /** /** * Returns whether the current process is in an isolated sandbox. * Returns whether the current process is in an isolated sandbox. */ */ @android.ravenwood.annotation.RavenwoodKeep @RavenwoodKeep public static final boolean isIsolated() { public static final boolean isIsolated() { return isIsolated(myUid()); return isIsolated(myUid()); } } Loading @@ -972,7 +939,7 @@ public class Process { @Deprecated @Deprecated @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.TIRAMISU, @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.TIRAMISU, publicAlternatives = "Use {@link #isIsolatedUid(int)} instead.") publicAlternatives = "Use {@link #isIsolatedUid(int)} instead.") @android.ravenwood.annotation.RavenwoodKeep @RavenwoodKeep public static final boolean isIsolated(int uid) { public static final boolean isIsolated(int uid) { return isIsolatedUid(uid); return isIsolatedUid(uid); } } Loading @@ -980,7 +947,7 @@ public class Process { /** /** * Returns whether the process with the given {@code uid} is an isolated sandbox. * Returns whether the process with the given {@code uid} is an isolated sandbox. */ */ @android.ravenwood.annotation.RavenwoodKeep @RavenwoodKeep public static final boolean isIsolatedUid(int uid) { public static final boolean isIsolatedUid(int uid) { uid = UserHandle.getAppId(uid); uid = UserHandle.getAppId(uid); return (uid >= FIRST_ISOLATED_UID && uid <= LAST_ISOLATED_UID) return (uid >= FIRST_ISOLATED_UID && uid <= LAST_ISOLATED_UID) Loading @@ -992,7 +959,7 @@ public class Process { * @see android.app.sdksandbox.SdkSandboxManager * @see android.app.sdksandbox.SdkSandboxManager */ */ @SuppressLint("UnflaggedApi") // promoting from @SystemApi. @SuppressLint("UnflaggedApi") // promoting from @SystemApi. @android.ravenwood.annotation.RavenwoodKeep @RavenwoodKeep public static final boolean isSdkSandboxUid(int uid) { public static final boolean isSdkSandboxUid(int uid) { uid = UserHandle.getAppId(uid); uid = UserHandle.getAppId(uid); return (uid >= FIRST_SDK_SANDBOX_UID && uid <= LAST_SDK_SANDBOX_UID); return (uid >= FIRST_SDK_SANDBOX_UID && uid <= LAST_SDK_SANDBOX_UID); Loading @@ -1008,7 +975,7 @@ public class Process { * @throws IllegalArgumentException if input is not an sdk sandbox uid * @throws IllegalArgumentException if input is not an sdk sandbox uid */ */ @SuppressLint("UnflaggedApi") // promoting from @SystemApi. @SuppressLint("UnflaggedApi") // promoting from @SystemApi. @android.ravenwood.annotation.RavenwoodKeep @RavenwoodKeep public static final int getAppUidForSdkSandboxUid(int uid) { public static final int getAppUidForSdkSandboxUid(int uid) { if (!isSdkSandboxUid(uid)) { if (!isSdkSandboxUid(uid)) { throw new IllegalArgumentException("Input UID is not an SDK sandbox UID"); throw new IllegalArgumentException("Input UID is not an SDK sandbox UID"); Loading @@ -1024,7 +991,7 @@ public class Process { */ */ @SystemApi(client = MODULE_LIBRARIES) @SystemApi(client = MODULE_LIBRARIES) @TestApi @TestApi @android.ravenwood.annotation.RavenwoodKeep @RavenwoodKeep // TODO(b/318651609): Deprecate once Process#getSdkSandboxUidForAppUid is rolled out to 100% // TODO(b/318651609): Deprecate once Process#getSdkSandboxUidForAppUid is rolled out to 100% public static final int toSdkSandboxUid(int uid) { public static final int toSdkSandboxUid(int uid) { return uid + (FIRST_SDK_SANDBOX_UID - FIRST_APPLICATION_UID); return uid + (FIRST_SDK_SANDBOX_UID - FIRST_APPLICATION_UID); Loading @@ -1040,7 +1007,7 @@ public class Process { * @throws IllegalArgumentException if input is not an app uid * @throws IllegalArgumentException if input is not an app uid */ */ @FlaggedApi(Flags.FLAG_SDK_SANDBOX_UID_TO_APP_UID_API) @FlaggedApi(Flags.FLAG_SDK_SANDBOX_UID_TO_APP_UID_API) @android.ravenwood.annotation.RavenwoodKeep @RavenwoodKeep public static final int getSdkSandboxUidForAppUid(int uid) { public static final int getSdkSandboxUidForAppUid(int uid) { if (!isApplicationUid(uid)) { if (!isApplicationUid(uid)) { throw new IllegalArgumentException("Input UID is not an app UID"); throw new IllegalArgumentException("Input UID is not an app UID"); Loading @@ -1051,7 +1018,7 @@ public class Process { /** /** * Returns whether the current process is a sdk sandbox process. * Returns whether the current process is a sdk sandbox process. */ */ @android.ravenwood.annotation.RavenwoodKeep @RavenwoodKeep public static final boolean isSdkSandbox() { public static final boolean isSdkSandbox() { return isSdkSandboxUid(myUid()); return isSdkSandboxUid(myUid()); } } Loading Loading @@ -1128,28 +1095,11 @@ public class Process { * not have permission to modify the given thread, or to use the given * not have permission to modify the given thread, or to use the given * priority. * priority. */ */ @android.ravenwood.annotation.RavenwoodReplace @RavenwoodRedirect public static final native void setThreadPriority(int tid, public static final native void setThreadPriority(int tid, @IntRange(from = -20, to = THREAD_PRIORITY_LOWEST) int priority) @IntRange(from = -20, to = THREAD_PRIORITY_LOWEST) int priority) throws IllegalArgumentException, SecurityException; throws IllegalArgumentException, SecurityException; /** @hide */ public static final void setThreadPriority$ravenwood(int tid, int priority) { final SomeArgs args = Preconditions.requireNonNullViaRavenwoodRule(sIdentity$ravenwood).get(); if (args.argi3 == tid) { boolean backgroundOk = (args.arg1 == Boolean.TRUE); if (priority >= THREAD_PRIORITY_BACKGROUND && !backgroundOk) { throw new IllegalArgumentException( "Priority " + priority + " blocked by setCanSelfBackground()"); } args.argi4 = priority; } else { throw new UnsupportedOperationException( "Cross-thread priority management not yet available in Ravenwood"); } } /** /** * Call with 'false' to cause future calls to {@link #setThreadPriority(int)} to * Call with 'false' to cause future calls to {@link #setThreadPriority(int)} to * throw an exception if passed a background-level thread priority. This is only * throw an exception if passed a background-level thread priority. This is only Loading @@ -1157,16 +1107,9 @@ public class Process { * * * @hide * @hide */ */ @android.ravenwood.annotation.RavenwoodReplace @RavenwoodRedirect public static final native void setCanSelfBackground(boolean backgroundOk); public static final native void setCanSelfBackground(boolean backgroundOk); /** @hide */ public static final void setCanSelfBackground$ravenwood(boolean backgroundOk) { final SomeArgs args = Preconditions.requireNonNullViaRavenwoodRule(sIdentity$ravenwood).get(); args.arg1 = Boolean.valueOf(backgroundOk); } /** /** * Sets the scheduling group for a thread. * Sets the scheduling group for a thread. * @hide * @hide Loading Loading @@ -1295,13 +1238,12 @@ public class Process { * * * @see #setThreadPriority(int, int) * @see #setThreadPriority(int, int) */ */ @android.ravenwood.annotation.RavenwoodReplace @RavenwoodReplace public static final native void setThreadPriority( public static final native void setThreadPriority( @IntRange(from = -20, to = THREAD_PRIORITY_LOWEST) int priority) @IntRange(from = -20, to = THREAD_PRIORITY_LOWEST) int priority) throws IllegalArgumentException, SecurityException; throws IllegalArgumentException, SecurityException; /** @hide */ private static void setThreadPriority$ravenwood(int priority) { public static final void setThreadPriority$ravenwood(int priority) { setThreadPriority(myTid(), priority); setThreadPriority(myTid(), priority); } } Loading @@ -1318,23 +1260,11 @@ public class Process { * @throws IllegalArgumentException Throws IllegalArgumentException if * @throws IllegalArgumentException Throws IllegalArgumentException if * <var>tid</var> does not exist. * <var>tid</var> does not exist. */ */ @android.ravenwood.annotation.RavenwoodReplace @RavenwoodRedirect @IntRange(from = -20, to = THREAD_PRIORITY_LOWEST) @IntRange(from = -20, to = THREAD_PRIORITY_LOWEST) public static final native int getThreadPriority(int tid) public static final native int getThreadPriority(int tid) throws IllegalArgumentException; throws IllegalArgumentException; /** @hide */ public static final int getThreadPriority$ravenwood(int tid) { final SomeArgs args = Preconditions.requireNonNullViaRavenwoodRule(sIdentity$ravenwood).get(); if (args.argi3 == tid) { return args.argi4; } else { throw new UnsupportedOperationException( "Cross-thread priority management not yet available in Ravenwood"); } } /** /** * Return the current scheduling policy of a thread, based on Linux. * Return the current scheduling policy of a thread, based on Linux. * * Loading core/java/com/android/internal/ravenwood/RavenwoodEnvironment.java +2 −49 Original line number Original line Diff line number Diff line Loading @@ -28,19 +28,9 @@ import android.ravenwood.annotation.RavenwoodReplace; public final class RavenwoodEnvironment { public final class RavenwoodEnvironment { public static final String TAG = "RavenwoodEnvironment"; public static final String TAG = "RavenwoodEnvironment"; private static final RavenwoodEnvironment sInstance; private static RavenwoodEnvironment sInstance = new RavenwoodEnvironment(); private static final Workaround sWorkaround; private RavenwoodEnvironment() { private static RuntimeException notSupportedOnDevice() { } static { sInstance = new RavenwoodEnvironment(); sWorkaround = new Workaround(); ensureRavenwoodInitialized(); } public static RuntimeException notSupportedOnDevice() { return new UnsupportedOperationException("This method can only be used on Ravenwood"); return new UnsupportedOperationException("This method can only be used on Ravenwood"); } } Loading @@ -51,15 +41,6 @@ public final class RavenwoodEnvironment { return sInstance; return sInstance; } } /** * Initialize the ravenwood environment if it hasn't happened already, if running on Ravenwood. * * No-op if called on the device side. */ @RavenwoodRedirect public static void ensureRavenwoodInitialized() { } /** /** * USE IT SPARINGLY! Returns true if it's running on Ravenwood, hostside test environment. * USE IT SPARINGLY! Returns true if it's running on Ravenwood, hostside test environment. * * Loading Loading @@ -90,18 +71,6 @@ public final class RavenwoodEnvironment { throw notSupportedOnDevice(); throw notSupportedOnDevice(); } } /** * See {@link Workaround}. It's only usable on Ravenwood. */ @RavenwoodReplace public static Workaround workaround() { throw notSupportedOnDevice(); } private static Workaround workaround$ravenwood() { return sWorkaround; } /** /** * @return the "ravenwood-runtime" directory. * @return the "ravenwood-runtime" directory. */ */ Loading @@ -109,20 +78,4 @@ public final class RavenwoodEnvironment { public String getRavenwoodRuntimePath() { public String getRavenwoodRuntimePath() { throw notSupportedOnDevice(); throw notSupportedOnDevice(); } } /** * A set of APIs used to work around missing features on Ravenwood. Ideally, this class should * be empty, and all its APIs should be able to be implemented properly. */ public static class Workaround { Workaround() { } /** * @return whether the app's target SDK level is at least Q. */ public boolean isTargetSdkAtLeastQ() { return true; } } } } ravenwood/junit-impl-src/android/platform/test/ravenwood/RavenwoodRuntimeEnvironmentController.java +7 −3 Original line number Original line Diff line number Diff line Loading @@ -40,6 +40,7 @@ import android.os.Build; import android.os.Bundle; import android.os.Bundle; import android.os.HandlerThread; import android.os.HandlerThread; import android.os.Looper; import android.os.Looper; import android.os.Process_ravenwood; import android.os.ServiceManager; import android.os.ServiceManager; import android.os.SystemProperties; import android.os.SystemProperties; import android.provider.DeviceConfig_host; import android.provider.DeviceConfig_host; Loading @@ -52,6 +53,7 @@ import androidx.test.platform.app.InstrumentationRegistry; import com.android.hoststubgen.hosthelper.HostTestUtils; import com.android.hoststubgen.hosthelper.HostTestUtils; import com.android.internal.os.RuntimeInit; import com.android.internal.os.RuntimeInit; import com.android.ravenwood.RavenwoodRuntimeNative; import com.android.ravenwood.RavenwoodRuntimeNative; import com.android.ravenwood.RavenwoodRuntimeState; import com.android.ravenwood.common.RavenwoodCommonUtils; import com.android.ravenwood.common.RavenwoodCommonUtils; import com.android.ravenwood.common.RavenwoodRuntimeException; import com.android.ravenwood.common.RavenwoodRuntimeException; import com.android.ravenwood.common.SneakyThrow; import com.android.ravenwood.common.SneakyThrow; Loading Loading @@ -223,7 +225,9 @@ public class RavenwoodRuntimeEnvironmentController { Thread.setDefaultUncaughtExceptionHandler(sUncaughtExceptionHandler); Thread.setDefaultUncaughtExceptionHandler(sUncaughtExceptionHandler); } } android.os.Process.init$ravenwood(config.mUid, config.mPid); RavenwoodRuntimeState.sUid = config.mUid; RavenwoodRuntimeState.sPid = config.mPid; RavenwoodRuntimeState.sTargetSdkLevel = config.mTargetSdkLevel; sOriginalIdentityToken = Binder.clearCallingIdentity(); sOriginalIdentityToken = Binder.clearCallingIdentity(); reinit(); reinit(); setSystemProperties(config.mSystemProperties); setSystemProperties(config.mSystemProperties); Loading Loading @@ -350,8 +354,8 @@ public class RavenwoodRuntimeEnvironmentController { if (sOriginalIdentityToken != -1) { if (sOriginalIdentityToken != -1) { Binder.restoreCallingIdentity(sOriginalIdentityToken); Binder.restoreCallingIdentity(sOriginalIdentityToken); } } android.os.Process.reset$ravenwood(); RavenwoodRuntimeState.reset(); Process_ravenwood.reset(); DeviceConfig_host.reset(); DeviceConfig_host.reset(); try { try { Loading Loading
core/java/android/os/Build.java +0 −6 Original line number Original line Diff line number Diff line Loading @@ -36,8 +36,6 @@ import android.util.ArraySet; import android.util.Slog; import android.util.Slog; import android.view.View; import android.view.View; import com.android.internal.ravenwood.RavenwoodEnvironment; import dalvik.system.VMRuntime; import dalvik.system.VMRuntime; import java.util.ArrayList; import java.util.ArrayList; Loading @@ -51,10 +49,6 @@ import java.util.stream.Collectors; */ */ @RavenwoodKeepWholeClass @RavenwoodKeepWholeClass public class Build { public class Build { static { // Set up the default system properties. RavenwoodEnvironment.ensureRavenwoodInitialized(); } private static final String TAG = "Build"; private static final String TAG = "Build"; /** Value used for when a build property is unknown. */ /** Value used for when a build property is unknown. */ Loading
core/java/android/os/ParcelFileDescriptor.java +0 −8 Original line number Original line Diff line number Diff line Loading @@ -41,7 +41,6 @@ import android.content.ContentResolver; import android.net.Uri; import android.net.Uri; import android.os.MessageQueue.OnFileDescriptorEventListener; import android.os.MessageQueue.OnFileDescriptorEventListener; import android.ravenwood.annotation.RavenwoodKeepWholeClass; import android.ravenwood.annotation.RavenwoodKeepWholeClass; import android.ravenwood.annotation.RavenwoodReplace; import android.ravenwood.annotation.RavenwoodThrow; import android.ravenwood.annotation.RavenwoodThrow; import android.system.ErrnoException; import android.system.ErrnoException; import android.system.Os; import android.system.Os; Loading @@ -51,8 +50,6 @@ import android.util.CloseGuard; import android.util.Log; import android.util.Log; import android.util.Slog; import android.util.Slog; import com.android.internal.ravenwood.RavenwoodEnvironment; import dalvik.system.VMRuntime; import dalvik.system.VMRuntime; import libcore.io.IoUtils; import libcore.io.IoUtils; Loading Loading @@ -1254,15 +1251,10 @@ public class ParcelFileDescriptor implements Parcelable, Closeable { } } } } @RavenwoodReplace private static boolean isAtLeastQ() { private static boolean isAtLeastQ() { return (VMRuntime.getRuntime().getTargetSdkVersion() >= Build.VERSION_CODES.Q); return (VMRuntime.getRuntime().getTargetSdkVersion() >= Build.VERSION_CODES.Q); } } private static boolean isAtLeastQ$ravenwood() { return RavenwoodEnvironment.workaround().isTargetSdkAtLeastQ(); } private static int ifAtLeastQ(int value) { private static int ifAtLeastQ(int value) { return isAtLeastQ() ? value : 0; return isAtLeastQ() ? value : 0; } } Loading
core/java/android/os/Process.java +27 −97 Original line number Original line Diff line number Diff line Loading @@ -29,6 +29,11 @@ import android.annotation.TestApi; import android.annotation.UptimeMillisLong; import android.annotation.UptimeMillisLong; import android.compat.annotation.UnsupportedAppUsage; import android.compat.annotation.UnsupportedAppUsage; import android.os.Build.VERSION_CODES; import android.os.Build.VERSION_CODES; import android.ravenwood.annotation.RavenwoodKeep; import android.ravenwood.annotation.RavenwoodKeepPartialClass; import android.ravenwood.annotation.RavenwoodRedirect; import android.ravenwood.annotation.RavenwoodRedirectionClass; import android.ravenwood.annotation.RavenwoodReplace; import android.sysprop.MemoryProperties; import android.sysprop.MemoryProperties; import android.system.ErrnoException; import android.system.ErrnoException; import android.system.Os; import android.system.Os; Loading @@ -37,8 +42,6 @@ import android.system.StructPollfd; import android.util.Pair; import android.util.Pair; import android.webkit.WebViewZygote; import android.webkit.WebViewZygote; import com.android.internal.os.SomeArgs; import com.android.internal.util.Preconditions; import com.android.sdksandbox.flags.Flags; import com.android.sdksandbox.flags.Flags; import dalvik.system.VMDebug; import dalvik.system.VMDebug; Loading @@ -55,6 +58,8 @@ import java.util.concurrent.TimeoutException; /** /** * Tools for managing OS processes. * Tools for managing OS processes. */ */ @RavenwoodKeepPartialClass @RavenwoodRedirectionClass("Process_ravenwood") public class Process { public class Process { private static final String LOG_TAG = "Process"; private static final String LOG_TAG = "Process"; Loading Loading @@ -672,7 +677,6 @@ public class Process { */ */ public static final ZygoteProcess ZYGOTE_PROCESS = new ZygoteProcess(); public static final ZygoteProcess ZYGOTE_PROCESS = new ZygoteProcess(); /** /** * The process name set via {@link #setArgV0(String)}. * The process name set via {@link #setArgV0(String)}. */ */ Loading Loading @@ -846,47 +850,20 @@ public class Process { /** /** * Returns true if the current process is a 64-bit runtime. * Returns true if the current process is a 64-bit runtime. */ */ @android.ravenwood.annotation.RavenwoodKeep @RavenwoodKeep public static final boolean is64Bit() { public static final boolean is64Bit() { return VMRuntime.getRuntime().is64Bit(); return VMRuntime.getRuntime().is64Bit(); } } private static volatile ThreadLocal<SomeArgs> sIdentity$ravenwood; /** @hide */ @android.ravenwood.annotation.RavenwoodKeep public static void init$ravenwood(final int uid, final int pid) { sIdentity$ravenwood = ThreadLocal.withInitial(() -> { final SomeArgs args = SomeArgs.obtain(); args.argi1 = uid; args.argi2 = pid; args.argi3 = Long.hashCode(Thread.currentThread().getId()); args.argi4 = THREAD_PRIORITY_DEFAULT; args.arg1 = Boolean.TRUE; // backgroundOk return args; }); } /** @hide */ @android.ravenwood.annotation.RavenwoodKeep public static void reset$ravenwood() { sIdentity$ravenwood = null; } /** /** * Returns the identifier of this process, which can be used with * Returns the identifier of this process, which can be used with * {@link #killProcess} and {@link #sendSignal}. * {@link #killProcess} and {@link #sendSignal}. */ */ @android.ravenwood.annotation.RavenwoodReplace @RavenwoodKeep public static final int myPid() { public static final int myPid() { return Os.getpid(); return Os.getpid(); } } /** @hide */ public static final int myPid$ravenwood() { return Preconditions.requireNonNullViaRavenwoodRule(sIdentity$ravenwood).get().argi2; } /** /** * Returns the identifier of this process' parent. * Returns the identifier of this process' parent. * @hide * @hide Loading @@ -900,39 +877,29 @@ public class Process { * Returns the identifier of the calling thread, which be used with * Returns the identifier of the calling thread, which be used with * {@link #setThreadPriority(int, int)}. * {@link #setThreadPriority(int, int)}. */ */ @android.ravenwood.annotation.RavenwoodReplace @RavenwoodKeep public static final int myTid() { public static final int myTid() { return Os.gettid(); return Os.gettid(); } } /** @hide */ public static final int myTid$ravenwood() { return Preconditions.requireNonNullViaRavenwoodRule(sIdentity$ravenwood).get().argi3; } /** /** * Returns the identifier of this process's uid. This is the kernel uid * Returns the identifier of this process's uid. This is the kernel uid * that the process is running under, which is the identity of its * that the process is running under, which is the identity of its * app-specific sandbox. It is different from {@link #myUserHandle} in that * app-specific sandbox. It is different from {@link #myUserHandle} in that * a uid identifies a specific app sandbox in a specific user. * a uid identifies a specific app sandbox in a specific user. */ */ @android.ravenwood.annotation.RavenwoodReplace @RavenwoodKeep public static final int myUid() { public static final int myUid() { return Os.getuid(); return Os.getuid(); } } /** @hide */ public static final int myUid$ravenwood() { return Preconditions.requireNonNullViaRavenwoodRule(sIdentity$ravenwood).get().argi1; } /** /** * Returns this process's user handle. This is the * Returns this process's user handle. This is the * user the process is running under. It is distinct from * user the process is running under. It is distinct from * {@link #myUid()} in that a particular user will have multiple * {@link #myUid()} in that a particular user will have multiple * distinct apps running under it each with their own uid. * distinct apps running under it each with their own uid. */ */ @android.ravenwood.annotation.RavenwoodKeep @RavenwoodKeep public static UserHandle myUserHandle() { public static UserHandle myUserHandle() { return UserHandle.of(UserHandle.getUserId(myUid())); return UserHandle.of(UserHandle.getUserId(myUid())); } } Loading @@ -941,7 +908,7 @@ public class Process { * Returns whether the given uid belongs to a system core component or not. * Returns whether the given uid belongs to a system core component or not. * @hide * @hide */ */ @android.ravenwood.annotation.RavenwoodKeep @RavenwoodKeep public static boolean isCoreUid(int uid) { public static boolean isCoreUid(int uid) { return UserHandle.isCore(uid); return UserHandle.isCore(uid); } } Loading @@ -952,7 +919,7 @@ public class Process { * @return Whether the uid corresponds to an application sandbox running in * @return Whether the uid corresponds to an application sandbox running in * a specific user. * a specific user. */ */ @android.ravenwood.annotation.RavenwoodKeep @RavenwoodKeep public static boolean isApplicationUid(int uid) { public static boolean isApplicationUid(int uid) { return UserHandle.isApp(uid); return UserHandle.isApp(uid); } } Loading @@ -960,7 +927,7 @@ public class Process { /** /** * Returns whether the current process is in an isolated sandbox. * Returns whether the current process is in an isolated sandbox. */ */ @android.ravenwood.annotation.RavenwoodKeep @RavenwoodKeep public static final boolean isIsolated() { public static final boolean isIsolated() { return isIsolated(myUid()); return isIsolated(myUid()); } } Loading @@ -972,7 +939,7 @@ public class Process { @Deprecated @Deprecated @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.TIRAMISU, @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.TIRAMISU, publicAlternatives = "Use {@link #isIsolatedUid(int)} instead.") publicAlternatives = "Use {@link #isIsolatedUid(int)} instead.") @android.ravenwood.annotation.RavenwoodKeep @RavenwoodKeep public static final boolean isIsolated(int uid) { public static final boolean isIsolated(int uid) { return isIsolatedUid(uid); return isIsolatedUid(uid); } } Loading @@ -980,7 +947,7 @@ public class Process { /** /** * Returns whether the process with the given {@code uid} is an isolated sandbox. * Returns whether the process with the given {@code uid} is an isolated sandbox. */ */ @android.ravenwood.annotation.RavenwoodKeep @RavenwoodKeep public static final boolean isIsolatedUid(int uid) { public static final boolean isIsolatedUid(int uid) { uid = UserHandle.getAppId(uid); uid = UserHandle.getAppId(uid); return (uid >= FIRST_ISOLATED_UID && uid <= LAST_ISOLATED_UID) return (uid >= FIRST_ISOLATED_UID && uid <= LAST_ISOLATED_UID) Loading @@ -992,7 +959,7 @@ public class Process { * @see android.app.sdksandbox.SdkSandboxManager * @see android.app.sdksandbox.SdkSandboxManager */ */ @SuppressLint("UnflaggedApi") // promoting from @SystemApi. @SuppressLint("UnflaggedApi") // promoting from @SystemApi. @android.ravenwood.annotation.RavenwoodKeep @RavenwoodKeep public static final boolean isSdkSandboxUid(int uid) { public static final boolean isSdkSandboxUid(int uid) { uid = UserHandle.getAppId(uid); uid = UserHandle.getAppId(uid); return (uid >= FIRST_SDK_SANDBOX_UID && uid <= LAST_SDK_SANDBOX_UID); return (uid >= FIRST_SDK_SANDBOX_UID && uid <= LAST_SDK_SANDBOX_UID); Loading @@ -1008,7 +975,7 @@ public class Process { * @throws IllegalArgumentException if input is not an sdk sandbox uid * @throws IllegalArgumentException if input is not an sdk sandbox uid */ */ @SuppressLint("UnflaggedApi") // promoting from @SystemApi. @SuppressLint("UnflaggedApi") // promoting from @SystemApi. @android.ravenwood.annotation.RavenwoodKeep @RavenwoodKeep public static final int getAppUidForSdkSandboxUid(int uid) { public static final int getAppUidForSdkSandboxUid(int uid) { if (!isSdkSandboxUid(uid)) { if (!isSdkSandboxUid(uid)) { throw new IllegalArgumentException("Input UID is not an SDK sandbox UID"); throw new IllegalArgumentException("Input UID is not an SDK sandbox UID"); Loading @@ -1024,7 +991,7 @@ public class Process { */ */ @SystemApi(client = MODULE_LIBRARIES) @SystemApi(client = MODULE_LIBRARIES) @TestApi @TestApi @android.ravenwood.annotation.RavenwoodKeep @RavenwoodKeep // TODO(b/318651609): Deprecate once Process#getSdkSandboxUidForAppUid is rolled out to 100% // TODO(b/318651609): Deprecate once Process#getSdkSandboxUidForAppUid is rolled out to 100% public static final int toSdkSandboxUid(int uid) { public static final int toSdkSandboxUid(int uid) { return uid + (FIRST_SDK_SANDBOX_UID - FIRST_APPLICATION_UID); return uid + (FIRST_SDK_SANDBOX_UID - FIRST_APPLICATION_UID); Loading @@ -1040,7 +1007,7 @@ public class Process { * @throws IllegalArgumentException if input is not an app uid * @throws IllegalArgumentException if input is not an app uid */ */ @FlaggedApi(Flags.FLAG_SDK_SANDBOX_UID_TO_APP_UID_API) @FlaggedApi(Flags.FLAG_SDK_SANDBOX_UID_TO_APP_UID_API) @android.ravenwood.annotation.RavenwoodKeep @RavenwoodKeep public static final int getSdkSandboxUidForAppUid(int uid) { public static final int getSdkSandboxUidForAppUid(int uid) { if (!isApplicationUid(uid)) { if (!isApplicationUid(uid)) { throw new IllegalArgumentException("Input UID is not an app UID"); throw new IllegalArgumentException("Input UID is not an app UID"); Loading @@ -1051,7 +1018,7 @@ public class Process { /** /** * Returns whether the current process is a sdk sandbox process. * Returns whether the current process is a sdk sandbox process. */ */ @android.ravenwood.annotation.RavenwoodKeep @RavenwoodKeep public static final boolean isSdkSandbox() { public static final boolean isSdkSandbox() { return isSdkSandboxUid(myUid()); return isSdkSandboxUid(myUid()); } } Loading Loading @@ -1128,28 +1095,11 @@ public class Process { * not have permission to modify the given thread, or to use the given * not have permission to modify the given thread, or to use the given * priority. * priority. */ */ @android.ravenwood.annotation.RavenwoodReplace @RavenwoodRedirect public static final native void setThreadPriority(int tid, public static final native void setThreadPriority(int tid, @IntRange(from = -20, to = THREAD_PRIORITY_LOWEST) int priority) @IntRange(from = -20, to = THREAD_PRIORITY_LOWEST) int priority) throws IllegalArgumentException, SecurityException; throws IllegalArgumentException, SecurityException; /** @hide */ public static final void setThreadPriority$ravenwood(int tid, int priority) { final SomeArgs args = Preconditions.requireNonNullViaRavenwoodRule(sIdentity$ravenwood).get(); if (args.argi3 == tid) { boolean backgroundOk = (args.arg1 == Boolean.TRUE); if (priority >= THREAD_PRIORITY_BACKGROUND && !backgroundOk) { throw new IllegalArgumentException( "Priority " + priority + " blocked by setCanSelfBackground()"); } args.argi4 = priority; } else { throw new UnsupportedOperationException( "Cross-thread priority management not yet available in Ravenwood"); } } /** /** * Call with 'false' to cause future calls to {@link #setThreadPriority(int)} to * Call with 'false' to cause future calls to {@link #setThreadPriority(int)} to * throw an exception if passed a background-level thread priority. This is only * throw an exception if passed a background-level thread priority. This is only Loading @@ -1157,16 +1107,9 @@ public class Process { * * * @hide * @hide */ */ @android.ravenwood.annotation.RavenwoodReplace @RavenwoodRedirect public static final native void setCanSelfBackground(boolean backgroundOk); public static final native void setCanSelfBackground(boolean backgroundOk); /** @hide */ public static final void setCanSelfBackground$ravenwood(boolean backgroundOk) { final SomeArgs args = Preconditions.requireNonNullViaRavenwoodRule(sIdentity$ravenwood).get(); args.arg1 = Boolean.valueOf(backgroundOk); } /** /** * Sets the scheduling group for a thread. * Sets the scheduling group for a thread. * @hide * @hide Loading Loading @@ -1295,13 +1238,12 @@ public class Process { * * * @see #setThreadPriority(int, int) * @see #setThreadPriority(int, int) */ */ @android.ravenwood.annotation.RavenwoodReplace @RavenwoodReplace public static final native void setThreadPriority( public static final native void setThreadPriority( @IntRange(from = -20, to = THREAD_PRIORITY_LOWEST) int priority) @IntRange(from = -20, to = THREAD_PRIORITY_LOWEST) int priority) throws IllegalArgumentException, SecurityException; throws IllegalArgumentException, SecurityException; /** @hide */ private static void setThreadPriority$ravenwood(int priority) { public static final void setThreadPriority$ravenwood(int priority) { setThreadPriority(myTid(), priority); setThreadPriority(myTid(), priority); } } Loading @@ -1318,23 +1260,11 @@ public class Process { * @throws IllegalArgumentException Throws IllegalArgumentException if * @throws IllegalArgumentException Throws IllegalArgumentException if * <var>tid</var> does not exist. * <var>tid</var> does not exist. */ */ @android.ravenwood.annotation.RavenwoodReplace @RavenwoodRedirect @IntRange(from = -20, to = THREAD_PRIORITY_LOWEST) @IntRange(from = -20, to = THREAD_PRIORITY_LOWEST) public static final native int getThreadPriority(int tid) public static final native int getThreadPriority(int tid) throws IllegalArgumentException; throws IllegalArgumentException; /** @hide */ public static final int getThreadPriority$ravenwood(int tid) { final SomeArgs args = Preconditions.requireNonNullViaRavenwoodRule(sIdentity$ravenwood).get(); if (args.argi3 == tid) { return args.argi4; } else { throw new UnsupportedOperationException( "Cross-thread priority management not yet available in Ravenwood"); } } /** /** * Return the current scheduling policy of a thread, based on Linux. * Return the current scheduling policy of a thread, based on Linux. * * Loading
core/java/com/android/internal/ravenwood/RavenwoodEnvironment.java +2 −49 Original line number Original line Diff line number Diff line Loading @@ -28,19 +28,9 @@ import android.ravenwood.annotation.RavenwoodReplace; public final class RavenwoodEnvironment { public final class RavenwoodEnvironment { public static final String TAG = "RavenwoodEnvironment"; public static final String TAG = "RavenwoodEnvironment"; private static final RavenwoodEnvironment sInstance; private static RavenwoodEnvironment sInstance = new RavenwoodEnvironment(); private static final Workaround sWorkaround; private RavenwoodEnvironment() { private static RuntimeException notSupportedOnDevice() { } static { sInstance = new RavenwoodEnvironment(); sWorkaround = new Workaround(); ensureRavenwoodInitialized(); } public static RuntimeException notSupportedOnDevice() { return new UnsupportedOperationException("This method can only be used on Ravenwood"); return new UnsupportedOperationException("This method can only be used on Ravenwood"); } } Loading @@ -51,15 +41,6 @@ public final class RavenwoodEnvironment { return sInstance; return sInstance; } } /** * Initialize the ravenwood environment if it hasn't happened already, if running on Ravenwood. * * No-op if called on the device side. */ @RavenwoodRedirect public static void ensureRavenwoodInitialized() { } /** /** * USE IT SPARINGLY! Returns true if it's running on Ravenwood, hostside test environment. * USE IT SPARINGLY! Returns true if it's running on Ravenwood, hostside test environment. * * Loading Loading @@ -90,18 +71,6 @@ public final class RavenwoodEnvironment { throw notSupportedOnDevice(); throw notSupportedOnDevice(); } } /** * See {@link Workaround}. It's only usable on Ravenwood. */ @RavenwoodReplace public static Workaround workaround() { throw notSupportedOnDevice(); } private static Workaround workaround$ravenwood() { return sWorkaround; } /** /** * @return the "ravenwood-runtime" directory. * @return the "ravenwood-runtime" directory. */ */ Loading @@ -109,20 +78,4 @@ public final class RavenwoodEnvironment { public String getRavenwoodRuntimePath() { public String getRavenwoodRuntimePath() { throw notSupportedOnDevice(); throw notSupportedOnDevice(); } } /** * A set of APIs used to work around missing features on Ravenwood. Ideally, this class should * be empty, and all its APIs should be able to be implemented properly. */ public static class Workaround { Workaround() { } /** * @return whether the app's target SDK level is at least Q. */ public boolean isTargetSdkAtLeastQ() { return true; } } } }
ravenwood/junit-impl-src/android/platform/test/ravenwood/RavenwoodRuntimeEnvironmentController.java +7 −3 Original line number Original line Diff line number Diff line Loading @@ -40,6 +40,7 @@ import android.os.Build; import android.os.Bundle; import android.os.Bundle; import android.os.HandlerThread; import android.os.HandlerThread; import android.os.Looper; import android.os.Looper; import android.os.Process_ravenwood; import android.os.ServiceManager; import android.os.ServiceManager; import android.os.SystemProperties; import android.os.SystemProperties; import android.provider.DeviceConfig_host; import android.provider.DeviceConfig_host; Loading @@ -52,6 +53,7 @@ import androidx.test.platform.app.InstrumentationRegistry; import com.android.hoststubgen.hosthelper.HostTestUtils; import com.android.hoststubgen.hosthelper.HostTestUtils; import com.android.internal.os.RuntimeInit; import com.android.internal.os.RuntimeInit; import com.android.ravenwood.RavenwoodRuntimeNative; import com.android.ravenwood.RavenwoodRuntimeNative; import com.android.ravenwood.RavenwoodRuntimeState; import com.android.ravenwood.common.RavenwoodCommonUtils; import com.android.ravenwood.common.RavenwoodCommonUtils; import com.android.ravenwood.common.RavenwoodRuntimeException; import com.android.ravenwood.common.RavenwoodRuntimeException; import com.android.ravenwood.common.SneakyThrow; import com.android.ravenwood.common.SneakyThrow; Loading Loading @@ -223,7 +225,9 @@ public class RavenwoodRuntimeEnvironmentController { Thread.setDefaultUncaughtExceptionHandler(sUncaughtExceptionHandler); Thread.setDefaultUncaughtExceptionHandler(sUncaughtExceptionHandler); } } android.os.Process.init$ravenwood(config.mUid, config.mPid); RavenwoodRuntimeState.sUid = config.mUid; RavenwoodRuntimeState.sPid = config.mPid; RavenwoodRuntimeState.sTargetSdkLevel = config.mTargetSdkLevel; sOriginalIdentityToken = Binder.clearCallingIdentity(); sOriginalIdentityToken = Binder.clearCallingIdentity(); reinit(); reinit(); setSystemProperties(config.mSystemProperties); setSystemProperties(config.mSystemProperties); Loading Loading @@ -350,8 +354,8 @@ public class RavenwoodRuntimeEnvironmentController { if (sOriginalIdentityToken != -1) { if (sOriginalIdentityToken != -1) { Binder.restoreCallingIdentity(sOriginalIdentityToken); Binder.restoreCallingIdentity(sOriginalIdentityToken); } } android.os.Process.reset$ravenwood(); RavenwoodRuntimeState.reset(); Process_ravenwood.reset(); DeviceConfig_host.reset(); DeviceConfig_host.reset(); try { try { Loading