diff options
author | 2024-10-29 11:18:38 -0700 | |
---|---|---|
committer | 2024-11-13 09:03:26 -0800 | |
commit | 7261855ac79a5ff177face7c02a161440a4f620b (patch) | |
tree | 5c60662b6092917f7ea06c81db5dcbad474e6782 /ravenwood/junit-impl-src/android | |
parent | 6e5eb8a738a29bc9f62b6f3dd60fcd3b626e2081 (diff) |
Compat-framework on ravenwood
Flag: EXEMPT host test change only
Bug: 367706429
Test: $ANDROID_BUILD_TOP/frameworks/base/ravenwood/scripts/run-ravenwood-tests.sh
Change-Id: Ibef0180fe3e5acb919cb6cbab09574c508e6d894
Merged-In: Ibef0180fe3e5acb919cb6cbab09574c508e6d894
Diffstat (limited to 'ravenwood/junit-impl-src/android')
2 files changed, 44 insertions, 0 deletions
diff --git a/ravenwood/junit-impl-src/android/platform/test/ravenwood/RavenwoodRuntimeEnvironmentController.java b/ravenwood/junit-impl-src/android/platform/test/ravenwood/RavenwoodRuntimeEnvironmentController.java index c5a9c7b28ad3..678a97be60a2 100644 --- a/ravenwood/junit-impl-src/android/platform/test/ravenwood/RavenwoodRuntimeEnvironmentController.java +++ b/ravenwood/junit-impl-src/android/platform/test/ravenwood/RavenwoodRuntimeEnvironmentController.java @@ -30,9 +30,12 @@ import static org.mockito.Mockito.mock; import android.annotation.Nullable; import android.app.ActivityManager; +import android.app.AppCompatCallbacks; import android.app.Instrumentation; import android.app.ResourcesManager; import android.app.UiAutomation; +import android.content.Context; +import android.content.pm.ApplicationInfo; import android.content.res.Resources; import android.os.Binder; import android.os.Build; @@ -41,6 +44,7 @@ import android.os.HandlerThread; import android.os.Looper; import android.os.Process_ravenwood; import android.os.ServiceManager; +import android.os.ServiceManager.ServiceNotFoundException; import android.os.SystemProperties; import android.provider.DeviceConfig_host; import android.system.ErrnoException; @@ -58,6 +62,7 @@ import com.android.ravenwood.common.RavenwoodCommonUtils; import com.android.ravenwood.common.RavenwoodRuntimeException; import com.android.ravenwood.common.SneakyThrow; import com.android.server.LocalServices; +import com.android.server.compat.PlatformCompat; import org.junit.runner.Description; @@ -331,6 +336,8 @@ public class RavenwoodRuntimeEnvironmentController { RavenwoodSystemServer.init(config); + initializeCompatIds(config); + if (ENABLE_TIMEOUT_STACKS) { sPendingTimeout = sTimeoutExecutor.schedule( RavenwoodRuntimeEnvironmentController::dumpStacks, @@ -346,6 +353,31 @@ public class RavenwoodRuntimeEnvironmentController { Binder.restoreCallingIdentity(packBinderIdentityToken(false, config.mUid, config.mPid)); } + private static void initializeCompatIds(RavenwoodConfig config) { + // Set up compat-IDs for the app side. + // TODO: Inside the system server, all the compat-IDs should be enabled, + // Due to the `AppCompatCallbacks.install(new long[0], new long[0])` call in + // SystemServer. + + // Compat framework only uses the package name and the target SDK level. + ApplicationInfo appInfo = new ApplicationInfo(); + appInfo.packageName = config.mTargetPackageName; + appInfo.targetSdkVersion = config.mTargetSdkLevel; + + PlatformCompat platformCompat = null; + try { + platformCompat = (PlatformCompat) ServiceManager.getServiceOrThrow( + Context.PLATFORM_COMPAT_SERVICE); + } catch (ServiceNotFoundException e) { + throw new RuntimeException(e); + } + + var disabledChanges = platformCompat.getDisabledChanges(appInfo); + var loggableChanges = platformCompat.getLoggableChanges(appInfo); + + AppCompatCallbacks.install(disabledChanges, loggableChanges); + } + /** * De-initialize. */ diff --git a/ravenwood/junit-impl-src/android/platform/test/ravenwood/RavenwoodSystemServer.java b/ravenwood/junit-impl-src/android/platform/test/ravenwood/RavenwoodSystemServer.java index f198a08a50e3..438a2bfa7a14 100644 --- a/ravenwood/junit-impl-src/android/platform/test/ravenwood/RavenwoodSystemServer.java +++ b/ravenwood/junit-impl-src/android/platform/test/ravenwood/RavenwoodSystemServer.java @@ -17,7 +17,9 @@ package android.platform.test.ravenwood; import android.content.ClipboardManager; +import android.content.Context; import android.hardware.SerialManager; +import android.os.ServiceManager; import android.os.SystemClock; import android.ravenwood.example.BlueManager; import android.ravenwood.example.RedManager; @@ -27,6 +29,8 @@ import android.util.ArraySet; import com.android.server.LocalServices; import com.android.server.SystemService; import com.android.server.SystemServiceManager; +import com.android.server.compat.PlatformCompat; +import com.android.server.compat.PlatformCompatNative; import com.android.server.utils.TimingsTraceAndSlog; import java.util.List; @@ -65,6 +69,14 @@ public class RavenwoodSystemServer { private static SystemServiceManager sServiceManager; public static void init(RavenwoodConfig config) { + // Always start PlatformCompat, regardless of the requested services. + // PlatformCompat is not really a SystemService, so it won't receive boot phases / etc. + // This initialization code is copied from SystemServer.java. + PlatformCompat platformCompat = new PlatformCompat(config.mState.mSystemServerContext); + ServiceManager.addService(Context.PLATFORM_COMPAT_SERVICE, platformCompat); + ServiceManager.addService(Context.PLATFORM_COMPAT_NATIVE_SERVICE, + new PlatformCompatNative(platformCompat)); + // Avoid overhead if no services required if (config.mServicesRequired.isEmpty()) return; |