Loading core/java/android/app/ActivityThread.java +26 −0 Original line number Diff line number Diff line Loading @@ -259,6 +259,7 @@ import com.android.org.conscrypt.TrustedCertificateStore; import com.android.server.am.BitmapDumpProto; import com.android.server.am.MemInfoDumpProto; import dalvik.annotation.optimization.NeverInline; import dalvik.annotation.optimization.NeverCompile; import dalvik.system.AppSpecializationHooks; import dalvik.system.CloseGuard; Loading Loading @@ -3354,6 +3355,31 @@ public final class ActivityThread extends ClientTransactionHandler return mInstrumentation; } @NeverCompile // Only called by tests. @NeverInline // Only called by tests. @RavenwoodReplace public static void throwIfNotInstrumenting() { final ActivityThread activityThread = ActivityThread.currentActivityThread(); if (activityThread == null) { // Only tests can reach here. return; } final Instrumentation instrumentation = activityThread.getInstrumentation(); if (instrumentation == null) { // Only tests can reach here. return; } if (instrumentation.isInstrumenting()) { return; } throw new IllegalStateException(); } public static void throwIfNotInstrumenting$ravenwood() { // Treat Ravenwood tests as instrumenting, so that they can call code that is // used in instrumentation tests. } public boolean isProfiling() { return mProfiler != null && mProfiler.profileFile != null && mProfiler.profileFd == null; Loading core/java/android/app/PropertyInvalidatedCache.java +7 −22 Original line number Diff line number Diff line Loading @@ -1441,30 +1441,15 @@ public class PropertyInvalidatedCache<Query, Result> { /** * Throw if the current process is not allowed to use test APIs. */ @android.ravenwood.annotation.RavenwoodReplace private static void throwIfNotTest() { final ActivityThread activityThread = ActivityThread.currentActivityThread(); if (activityThread == null) { // Only tests can reach here. return; } final Instrumentation instrumentation = activityThread.getInstrumentation(); if (instrumentation == null) { // Only tests can reach here. return; } if (instrumentation.isInstrumenting()) { return; } try { ActivityThread.throwIfNotInstrumenting(); } catch (IllegalStateException e) { if (Flags.enforcePicTestmodeProtocol()) { throw new IllegalStateException("Test-only API called not from a test."); throw e; } // else swallow the exception } /** * Do not throw if running under ravenwood. */ private static void throwIfNotTest$ravenwood() { } /** Loading core/java/android/os/CombinedMessageQueue/MessageQueue.java +3 −26 Original line number Diff line number Diff line Loading @@ -22,7 +22,6 @@ import android.annotation.Nullable; import android.annotation.SuppressLint; import android.annotation.TestApi; import android.app.ActivityThread; import android.app.Instrumentation; import android.compat.annotation.UnsupportedAppUsage; import android.ravenwood.annotation.RavenwoodKeepWholeClass; import android.ravenwood.annotation.RavenwoodRedirect; Loading Loading @@ -211,28 +210,6 @@ public final class MessageQueue { return false; } @RavenwoodReplace private static void throwIfNotTest() { final ActivityThread activityThread = ActivityThread.currentActivityThread(); if (activityThread == null) { // Only tests can reach here. return; } final Instrumentation instrumentation = activityThread.getInstrumentation(); if (instrumentation == null) { // Only tests can reach here. return; } if (instrumentation.isInstrumenting()) { return; } throw new IllegalStateException("Test-only API called not from a test!"); } private static void throwIfNotTest$ravenwood() { return; } @Override protected void finalize() throws Throwable { try { Loading Loading @@ -1517,7 +1494,7 @@ public final class MessageQueue { */ @SuppressLint("VisiblySynchronized") // Legacy MessageQueue synchronizes on this Long peekWhenForTest() { throwIfNotTest(); ActivityThread.throwIfNotInstrumenting(); Message ret; if (sUseConcurrent) { ret = nextMessage(true, true); Loading @@ -1536,7 +1513,7 @@ public final class MessageQueue { @SuppressLint("VisiblySynchronized") // Legacy MessageQueue synchronizes on this @Nullable Message pollForTest() { throwIfNotTest(); ActivityThread.throwIfNotInstrumenting(); if (sUseConcurrent) { return nextMessage(false, true); } else { Loading @@ -1552,7 +1529,7 @@ public final class MessageQueue { * and may not be resumed until after returning from this method. */ boolean isBlockedOnSyncBarrier() { throwIfNotTest(); ActivityThread.throwIfNotInstrumenting(); if (sUseConcurrent) { // Call nextMessage to get the stack drained into our priority queues nextMessage(true, false); Loading core/java/android/os/LegacyMessageQueue/MessageQueue.java +3 −26 Original line number Diff line number Diff line Loading @@ -22,7 +22,6 @@ import android.annotation.Nullable; import android.annotation.SuppressLint; import android.annotation.TestApi; import android.app.ActivityThread; import android.app.Instrumentation; import android.compat.annotation.UnsupportedAppUsage; import android.ravenwood.annotation.RavenwoodKeepWholeClass; import android.ravenwood.annotation.RavenwoodRedirect; Loading Loading @@ -103,28 +102,6 @@ public final class MessageQueue { mPtr = nativeInit(); } @android.ravenwood.annotation.RavenwoodReplace private static void throwIfNotTest() { final ActivityThread activityThread = ActivityThread.currentActivityThread(); if (activityThread == null) { // Only tests can reach here. return; } final Instrumentation instrumentation = activityThread.getInstrumentation(); if (instrumentation == null) { // Only tests can reach here. return; } if (instrumentation.isInstrumenting()) { return; } throw new IllegalStateException("Test-only API called not from a test!"); } private static void throwIfNotTest$ravenwood() { return; } @Override protected void finalize() throws Throwable { try { Loading Loading @@ -758,7 +735,7 @@ public final class MessageQueue { */ @SuppressLint("VisiblySynchronized") // Legacy MessageQueue synchronizes on this Long peekWhenForTest() { throwIfNotTest(); ActivityThread.throwIfNotInstrumenting(); Message ret = legacyPeekOrPoll(true); return ret != null ? ret.when : null; } Loading @@ -772,7 +749,7 @@ public final class MessageQueue { @SuppressLint("VisiblySynchronized") // Legacy MessageQueue synchronizes on this @Nullable Message pollForTest() { throwIfNotTest(); ActivityThread.throwIfNotInstrumenting(); return legacyPeekOrPoll(false); } Loading @@ -784,7 +761,7 @@ public final class MessageQueue { * and may not be resumed until after returning from this method. */ boolean isBlockedOnSyncBarrier() { throwIfNotTest(); ActivityThread.throwIfNotInstrumenting(); synchronized (this) { Message msg = mMessages; return msg != null && msg.target == null; Loading Loading
core/java/android/app/ActivityThread.java +26 −0 Original line number Diff line number Diff line Loading @@ -259,6 +259,7 @@ import com.android.org.conscrypt.TrustedCertificateStore; import com.android.server.am.BitmapDumpProto; import com.android.server.am.MemInfoDumpProto; import dalvik.annotation.optimization.NeverInline; import dalvik.annotation.optimization.NeverCompile; import dalvik.system.AppSpecializationHooks; import dalvik.system.CloseGuard; Loading Loading @@ -3354,6 +3355,31 @@ public final class ActivityThread extends ClientTransactionHandler return mInstrumentation; } @NeverCompile // Only called by tests. @NeverInline // Only called by tests. @RavenwoodReplace public static void throwIfNotInstrumenting() { final ActivityThread activityThread = ActivityThread.currentActivityThread(); if (activityThread == null) { // Only tests can reach here. return; } final Instrumentation instrumentation = activityThread.getInstrumentation(); if (instrumentation == null) { // Only tests can reach here. return; } if (instrumentation.isInstrumenting()) { return; } throw new IllegalStateException(); } public static void throwIfNotInstrumenting$ravenwood() { // Treat Ravenwood tests as instrumenting, so that they can call code that is // used in instrumentation tests. } public boolean isProfiling() { return mProfiler != null && mProfiler.profileFile != null && mProfiler.profileFd == null; Loading
core/java/android/app/PropertyInvalidatedCache.java +7 −22 Original line number Diff line number Diff line Loading @@ -1441,30 +1441,15 @@ public class PropertyInvalidatedCache<Query, Result> { /** * Throw if the current process is not allowed to use test APIs. */ @android.ravenwood.annotation.RavenwoodReplace private static void throwIfNotTest() { final ActivityThread activityThread = ActivityThread.currentActivityThread(); if (activityThread == null) { // Only tests can reach here. return; } final Instrumentation instrumentation = activityThread.getInstrumentation(); if (instrumentation == null) { // Only tests can reach here. return; } if (instrumentation.isInstrumenting()) { return; } try { ActivityThread.throwIfNotInstrumenting(); } catch (IllegalStateException e) { if (Flags.enforcePicTestmodeProtocol()) { throw new IllegalStateException("Test-only API called not from a test."); throw e; } // else swallow the exception } /** * Do not throw if running under ravenwood. */ private static void throwIfNotTest$ravenwood() { } /** Loading
core/java/android/os/CombinedMessageQueue/MessageQueue.java +3 −26 Original line number Diff line number Diff line Loading @@ -22,7 +22,6 @@ import android.annotation.Nullable; import android.annotation.SuppressLint; import android.annotation.TestApi; import android.app.ActivityThread; import android.app.Instrumentation; import android.compat.annotation.UnsupportedAppUsage; import android.ravenwood.annotation.RavenwoodKeepWholeClass; import android.ravenwood.annotation.RavenwoodRedirect; Loading Loading @@ -211,28 +210,6 @@ public final class MessageQueue { return false; } @RavenwoodReplace private static void throwIfNotTest() { final ActivityThread activityThread = ActivityThread.currentActivityThread(); if (activityThread == null) { // Only tests can reach here. return; } final Instrumentation instrumentation = activityThread.getInstrumentation(); if (instrumentation == null) { // Only tests can reach here. return; } if (instrumentation.isInstrumenting()) { return; } throw new IllegalStateException("Test-only API called not from a test!"); } private static void throwIfNotTest$ravenwood() { return; } @Override protected void finalize() throws Throwable { try { Loading Loading @@ -1517,7 +1494,7 @@ public final class MessageQueue { */ @SuppressLint("VisiblySynchronized") // Legacy MessageQueue synchronizes on this Long peekWhenForTest() { throwIfNotTest(); ActivityThread.throwIfNotInstrumenting(); Message ret; if (sUseConcurrent) { ret = nextMessage(true, true); Loading @@ -1536,7 +1513,7 @@ public final class MessageQueue { @SuppressLint("VisiblySynchronized") // Legacy MessageQueue synchronizes on this @Nullable Message pollForTest() { throwIfNotTest(); ActivityThread.throwIfNotInstrumenting(); if (sUseConcurrent) { return nextMessage(false, true); } else { Loading @@ -1552,7 +1529,7 @@ public final class MessageQueue { * and may not be resumed until after returning from this method. */ boolean isBlockedOnSyncBarrier() { throwIfNotTest(); ActivityThread.throwIfNotInstrumenting(); if (sUseConcurrent) { // Call nextMessage to get the stack drained into our priority queues nextMessage(true, false); Loading
core/java/android/os/LegacyMessageQueue/MessageQueue.java +3 −26 Original line number Diff line number Diff line Loading @@ -22,7 +22,6 @@ import android.annotation.Nullable; import android.annotation.SuppressLint; import android.annotation.TestApi; import android.app.ActivityThread; import android.app.Instrumentation; import android.compat.annotation.UnsupportedAppUsage; import android.ravenwood.annotation.RavenwoodKeepWholeClass; import android.ravenwood.annotation.RavenwoodRedirect; Loading Loading @@ -103,28 +102,6 @@ public final class MessageQueue { mPtr = nativeInit(); } @android.ravenwood.annotation.RavenwoodReplace private static void throwIfNotTest() { final ActivityThread activityThread = ActivityThread.currentActivityThread(); if (activityThread == null) { // Only tests can reach here. return; } final Instrumentation instrumentation = activityThread.getInstrumentation(); if (instrumentation == null) { // Only tests can reach here. return; } if (instrumentation.isInstrumenting()) { return; } throw new IllegalStateException("Test-only API called not from a test!"); } private static void throwIfNotTest$ravenwood() { return; } @Override protected void finalize() throws Throwable { try { Loading Loading @@ -758,7 +735,7 @@ public final class MessageQueue { */ @SuppressLint("VisiblySynchronized") // Legacy MessageQueue synchronizes on this Long peekWhenForTest() { throwIfNotTest(); ActivityThread.throwIfNotInstrumenting(); Message ret = legacyPeekOrPoll(true); return ret != null ? ret.when : null; } Loading @@ -772,7 +749,7 @@ public final class MessageQueue { @SuppressLint("VisiblySynchronized") // Legacy MessageQueue synchronizes on this @Nullable Message pollForTest() { throwIfNotTest(); ActivityThread.throwIfNotInstrumenting(); return legacyPeekOrPoll(false); } Loading @@ -784,7 +761,7 @@ public final class MessageQueue { * and may not be resumed until after returning from this method. */ boolean isBlockedOnSyncBarrier() { throwIfNotTest(); ActivityThread.throwIfNotInstrumenting(); synchronized (this) { Message msg = mMessages; return msg != null && msg.target == null; Loading