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

Commit e1c97fa7 authored by John Wu's avatar John Wu
Browse files

[Ravenwood] Support context.getResources() without res APK

When a test uses framework resources without including resources of its
own, the existing implementation will crash the test. Make sure
resources are always available regardless whether the test includes its
own resources or not.

Bug: 339614874
Flag: EXEMPT host side change only
Test: $ANDROID_BUILD_TOP/frameworks/base/ravenwood/scripts/run-ravenwood-tests.sh
Test: atest RavenwoodServicesTest
Change-Id: Ic9000d892d6b899ffbbbecb7d713fee19a601b07
parent 3bc44be9
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -331,6 +331,7 @@ android_ravenwood_libgroup {
    name: "ravenwood-runtime",
    data: [
        "framework-res",
        "ravenwood-empty-res",
    ],
    libs: [
        "100-framework-minus-apex.ravenwood",
+4 −0
Original line number Diff line number Diff line
android_app {
    name: "ravenwood-empty-res",
    sdk_version: "current",
}
+19 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2024 The Android Open Source Project

     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at

          http://www.apache.org/licenses/LICENSE-2.0

     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.
-->

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.android.ravenwood.emptyres">
</manifest>
+6 −8
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package android.platform.test.ravenwood;

import static com.android.ravenwood.common.RavenwoodCommonUtils.RAVENWOOD_EMPTY_RESOURCES_APK;
import static com.android.ravenwood.common.RavenwoodCommonUtils.RAVENWOOD_RESOURCE_APK;

import static org.junit.Assert.assertFalse;
@@ -109,10 +110,6 @@ public class RavenwoodRuleImpl {

        android.os.Process.init$ravenwood(rule.mUid, rule.mPid);
        android.os.Binder.init$ravenwood();
//        android.os.SystemProperties.init$ravenwood(
//                rule.mSystemProperties.getValues(),
//                rule.mSystemProperties.getKeyReadablePredicate(),
//                rule.mSystemProperties.getKeyWritablePredicate());
        setSystemProperties(rule.mSystemProperties);

        ServiceManager.init$ravenwood();
@@ -131,11 +128,12 @@ public class RavenwoodRuleImpl {

        // TODO This should be integrated into LoadedApk
        final Supplier<Resources> resourcesSupplier = () -> {
            final var resApkFile = new File(RAVENWOOD_RESOURCE_APK).getAbsoluteFile();
            var resApkFile = new File(RAVENWOOD_RESOURCE_APK);
            if (!resApkFile.isFile()) {
                resApkFile = new File(RAVENWOOD_EMPTY_RESOURCES_APK);
            }
            assertTrue(resApkFile.isFile());

            final var res = resApkFile.getAbsolutePath();

            final String res = resApkFile.getAbsolutePath();
            final var emptyPaths = new String[0];

            ResourcesManager.getInstance().initializeApplicationPaths(res, emptyPaths);
+5 −2
Original line number Diff line number Diff line
@@ -42,12 +42,15 @@ public class RavenwoodCommonUtils {

    private static final boolean IS_ON_RAVENWOOD = RavenwoodDivergence.isOnRavenwood();

    private static final String RAVEWOOD_RUNTIME_PATH = getRavenwoodRuntimePathInternal();
    private static final String RAVENWOOD_RUNTIME_PATH = getRavenwoodRuntimePathInternal();

    public static final String RAVENWOOD_SYSPROP = "ro.is_on_ravenwood";

    public static final String RAVENWOOD_RESOURCE_APK = "ravenwood-res-apks/ravenwood-res.apk";

    public static final String RAVENWOOD_EMPTY_RESOURCES_APK =
            RAVENWOOD_RUNTIME_PATH + "ravenwood-data/ravenwood-empty-res.apk";

    // @GuardedBy("sLock")
    private static boolean sIntegrityChecked = false;

@@ -178,7 +181,7 @@ public class RavenwoodCommonUtils {
     */
    public static String getRavenwoodRuntimePath() {
        ensureOnRavenwood();
        return RAVEWOOD_RUNTIME_PATH;
        return RAVENWOOD_RUNTIME_PATH;
    }

    private static String getRavenwoodRuntimePathInternal() {
Loading