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

Commit 6dc16b9b authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Add golden tests for systemfeatures codegen" into main am: 1385c581 am: 4dfd8d19

parents da2a06af 4dfd8d19
Loading
Loading
Loading
Loading
+33 −3
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@ package {
    // to get the below license kinds:
    //   SPDX-license-identifier-Apache-2.0
    default_applicable_licenses: ["frameworks_base_license"],
    default_team: "trendy_team_system_performance",
}

java_library_host {
@@ -25,8 +26,6 @@ java_binary_host {
    static_libs: ["systemfeatures-gen-lib"],
}

// TODO(b/203143243): Add golden diff test for generated sources.
// Functional runtime behavior is covered in systemfeatures-gen-tests.
genrule {
    name: "systemfeatures-gen-tests-srcs",
    cmd: "$(location systemfeatures-gen-tool) com.android.systemfeatures.RwNoFeatures --readonly=false > $(location RwNoFeatures.java) && " +
@@ -42,11 +41,12 @@ genrule {
    tools: ["systemfeatures-gen-tool"],
}

// Functional runtime behavior testing.
java_test_host {
    name: "systemfeatures-gen-tests",
    test_suites: ["general-tests"],
    srcs: [
        "tests/**/*.java",
        "tests/src/**/*.java",
        ":systemfeatures-gen-tests-srcs",
    ],
    test_options: {
@@ -61,3 +61,33 @@ java_test_host {
        "truth",
    ],
}

// Rename the goldens as they may be copied into the source tree, and we don't
// need or want the usual `.java` linting (e.g., copyright checks).
genrule {
    name: "systemfeatures-gen-tests-golden-srcs",
    cmd: "for f in $(in); do cp $$f $(genDir)/tests/gen/$$(basename $$f).gen; done",
    srcs: [":systemfeatures-gen-tests-srcs"],
    out: [
        "tests/gen/RwNoFeatures.java.gen",
        "tests/gen/RoNoFeatures.java.gen",
        "tests/gen/RwFeatures.java.gen",
        "tests/gen/RoFeatures.java.gen",
    ],
}

// Golden output testing. Golden sources can be updated via:
//   $ANDROID_BUILD_TOP/frameworks/base/tools/systemfeatures/tests/golden_test.sh --update
sh_test_host {
    name: "systemfeatures-gen-golden-tests",
    src: "tests/golden_test.sh",
    filename: "systemfeatures-gen-golden-tests.sh",
    test_config: "tests/systemfeatures-gen-golden-tests.xml",
    data: [
        "tests/golden/**/*.java*",
        ":systemfeatures-gen-tests-golden-srcs",
    ],
    test_options: {
        unit_test: true,
    },
}
+6 −0
Original line number Diff line number Diff line
@@ -142,6 +142,10 @@ object SystemFeaturesGenerator {

        // TODO(b/203143243): Add validation of build vs runtime values to ensure consistency.
        JavaFile.builder(outputClassName.packageName(), classBuilder.build())
            .indent("    ")
            .skipJavaLangImports(true)
            .addFileComment("This file is auto-generated. DO NOT MODIFY.\n")
            .addFileComment("Args: ${args.joinToString(" \\\n           ")}")
            .build()
            .writeTo(System.out)
    }
@@ -178,6 +182,7 @@ object SystemFeaturesGenerator {
            val methodBuilder =
                MethodSpec.methodBuilder(methodName)
                    .addModifiers(Modifier.PUBLIC, Modifier.STATIC)
                    .addJavadoc("Check for ${feature.name}.\n\n@hide")
                    .returns(Boolean::class.java)
                    .addParameter(CONTEXT_CLASS, "context")

@@ -228,6 +233,7 @@ object SystemFeaturesGenerator {
            MethodSpec.methodBuilder("maybeHasFeature")
                .addModifiers(Modifier.PUBLIC, Modifier.STATIC)
                .addAnnotation(ClassName.get("android.annotation", "Nullable"))
                .addJavadoc("@hide")
                .returns(Boolean::class.javaObjectType) // Use object type for nullability
                .addParameter(String::class.java, "featureName")
                .addParameter(Int::class.java, "version")
+88 −0
Original line number Diff line number Diff line
// This file is auto-generated. DO NOT MODIFY.
// Args: com.android.systemfeatures.RoFeatures \
//            --readonly=true \
//            --feature=WATCH:1 \
//            --feature=WIFI:0 \
//            --feature=VULKAN:-1 \
//            --feature=AUTO: \
//            --feature-apis=WATCH,PC
package com.android.systemfeatures;

import android.annotation.Nullable;
import android.content.Context;
import android.content.pm.PackageManager;
import com.android.aconfig.annotations.AssumeFalseForR8;
import com.android.aconfig.annotations.AssumeTrueForR8;

/**
 * @hide
 */
public final class RoFeatures {
    /**
     * Check for FEATURE_WATCH.
     *
     * @hide
     */
    @AssumeTrueForR8
    public static boolean hasFeatureWatch(Context context) {
        return true;
    }

    /**
     * Check for FEATURE_PC.
     *
     * @hide
     */
    public static boolean hasFeaturePc(Context context) {
        return hasFeatureFallback(context, PackageManager.FEATURE_PC);
    }

    /**
     * Check for FEATURE_WIFI.
     *
     * @hide
     */
    @AssumeTrueForR8
    public static boolean hasFeatureWifi(Context context) {
        return true;
    }

    /**
     * Check for FEATURE_VULKAN.
     *
     * @hide
     */
    @AssumeFalseForR8
    public static boolean hasFeatureVulkan(Context context) {
        return false;
    }

    /**
     * Check for FEATURE_AUTO.
     *
     * @hide
     */
    @AssumeFalseForR8
    public static boolean hasFeatureAuto(Context context) {
        return false;
    }

    private static boolean hasFeatureFallback(Context context, String featureName) {
        return context.getPackageManager().hasSystemFeature(featureName, 0);
    }

    /**
     * @hide
     */
    @Nullable
    public static Boolean maybeHasFeature(String featureName, int version) {
        switch (featureName) {
            case PackageManager.FEATURE_WATCH: return 1 >= version;
            case PackageManager.FEATURE_WIFI: return 0 >= version;
            case PackageManager.FEATURE_VULKAN: return -1 >= version;
            case PackageManager.FEATURE_AUTO: return false;
            default: break;
        }
        return null;
    }
}
+35 −0
Original line number Diff line number Diff line
// This file is auto-generated. DO NOT MODIFY.
// Args: com.android.systemfeatures.RoNoFeatures \
//            --readonly=true \
//            --feature-apis=WATCH
package com.android.systemfeatures;

import android.annotation.Nullable;
import android.content.Context;
import android.content.pm.PackageManager;

/**
 * @hide
 */
public final class RoNoFeatures {
    /**
     * Check for FEATURE_WATCH.
     *
     * @hide
     */
    public static boolean hasFeatureWatch(Context context) {
        return hasFeatureFallback(context, PackageManager.FEATURE_WATCH);
    }

    private static boolean hasFeatureFallback(Context context, String featureName) {
        return context.getPackageManager().hasSystemFeature(featureName, 0);
    }

    /**
     * @hide
     */
    @Nullable
    public static Boolean maybeHasFeature(String featureName, int version) {
        return null;
    }
}
+65 −0
Original line number Diff line number Diff line
// This file is auto-generated. DO NOT MODIFY.
// Args: com.android.systemfeatures.RwFeatures \
//            --readonly=false \
//            --feature=WATCH:1 \
//            --feature=WIFI:0 \
//            --feature=VULKAN:-1 \
//            --feature=AUTO:
package com.android.systemfeatures;

import android.annotation.Nullable;
import android.content.Context;
import android.content.pm.PackageManager;

/**
 * @hide
 */
public final class RwFeatures {
    /**
     * Check for FEATURE_WATCH.
     *
     * @hide
     */
    public static boolean hasFeatureWatch(Context context) {
        return hasFeatureFallback(context, PackageManager.FEATURE_WATCH);
    }

    /**
     * Check for FEATURE_WIFI.
     *
     * @hide
     */
    public static boolean hasFeatureWifi(Context context) {
        return hasFeatureFallback(context, PackageManager.FEATURE_WIFI);
    }

    /**
     * Check for FEATURE_VULKAN.
     *
     * @hide
     */
    public static boolean hasFeatureVulkan(Context context) {
        return hasFeatureFallback(context, PackageManager.FEATURE_VULKAN);
    }

    /**
     * Check for FEATURE_AUTO.
     *
     * @hide
     */
    public static boolean hasFeatureAuto(Context context) {
        return hasFeatureFallback(context, PackageManager.FEATURE_AUTO);
    }

    private static boolean hasFeatureFallback(Context context, String featureName) {
        return context.getPackageManager().hasSystemFeature(featureName, 0);
    }

    /**
     * @hide
     */
    @Nullable
    public static Boolean maybeHasFeature(String featureName, int version) {
        return null;
    }
}
Loading