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

Commit 07e82a0d authored by Zhi Dou's avatar Zhi Dou Committed by Automerger Merge Worker
Browse files

Merge "aconfig: fix build issue" into main am: a1038d74

parents f5fabb6f a1038d74
Loading
Loading
Loading
Loading
+50 −1
Original line number Diff line number Diff line
@@ -641,7 +641,6 @@ mod tests {
        package com.android.aconfig.test;
        // TODO(b/303773055): Remove the annotation after access issue is resolved.
        import android.compat.annotation.UnsupportedAppUsage;
        import android.os.Build;
        import android.os.flagging.PlatformAconfigPackageInternal;
        import android.util.Log;
        /** @hide */
@@ -1379,6 +1378,56 @@ mod tests {
        assert!(file_set.is_empty());
    }

    // Test that the SDK check isn't added unless the library is exported (even
    // if the flag is present in finalized_flags).
    #[test]
    fn test_generate_java_code_flags_with_sdk_check() {
        let parsed_flags = crate::test::parse_test_flags();
        let mode = CodegenMode::Production;
        let modified_parsed_flags =
            crate::commands::modify_parsed_flags_based_on_mode(parsed_flags, mode).unwrap();
        let flag_ids =
            assign_flag_ids(crate::test::TEST_PACKAGE, modified_parsed_flags.iter()).unwrap();
        let mut finalized_flags = FinalizedFlagMap::new();
        finalized_flags.insert_if_new(
            ApiLevel(36),
            FinalizedFlag {
                flag_name: "disabled_rw".to_string(),
                package_name: "com.android.aconfig.test".to_string(),
            },
        );
        let config = JavaCodegenConfig {
            codegen_mode: mode,
            flag_ids,
            allow_instrumentation: true,
            package_fingerprint: 5801144784618221668,
            new_exported: true,
            single_exported_file: false,
            finalized_flags,
        };
        let generated_files = generate_java_code(
            crate::test::TEST_PACKAGE,
            modified_parsed_flags.into_iter(),
            config,
        )
        .unwrap();

        let expect_flags_content = EXPECTED_FLAG_COMMON_CONTENT.to_string()
            + r#"
        private static FeatureFlags FEATURE_FLAGS = new FeatureFlagsImpl();
        }"#;

        let file = generated_files.iter().find(|f| f.path.ends_with("Flags.java")).unwrap();
        assert_eq!(
            None,
            crate::test::first_significant_code_diff(
                &expect_flags_content,
                &String::from_utf8(file.contents.clone()).unwrap()
            ),
            "Flags content is not correct"
        );
    }

    #[test]
    fn test_generate_java_code_test() {
        let parsed_flags = crate::test::parse_test_flags();
+0 −1
Original line number Diff line number Diff line
@@ -2,7 +2,6 @@ package {package_name}; {#- CODEGEN FOR INTERNAL MODE FOR NEW STORAGE #}
// TODO(b/303773055): Remove the annotation after access issue is resolved.
import android.compat.annotation.UnsupportedAppUsage;
{{ -if runtime_lookup_required }}
import android.os.Build;
{{ if is_platform_container }}
import android.os.flagging.PlatformAconfigPackageInternal;
{{ -else }} {#- else is_platform_container #}
+3 −1
Original line number Diff line number Diff line
@@ -4,7 +4,7 @@ package {package_name};
import android.compat.annotation.UnsupportedAppUsage;
{{ else }}
import android.os.Build;
{{ -endif }}
{{ -endif }} {#- end not library_exported#}
{{ -if single_exported_file }}
{{ -if library_exported }}
/**
@@ -33,11 +33,13 @@ public final class Flags \{
    @UnsupportedAppUsage
{{ -endif }}
    public static boolean {item.method_name}() \{
        {{ if library_exported- }}
        {{ -if item.finalized_sdk_present }}
        if (Build.VERSION.SDK_INT >= {item.finalized_sdk_value}) \{
          return true;
        }
        {{ -endif}}  {#- end finalized_sdk_present#}
        {{ -endif}}  {#- end library_exported#}
        return FEATURE_FLAGS.{item.method_name}();
    }
{{ -endfor }}