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

Commit b52465da authored by Zhi Dou's avatar Zhi Dou
Browse files

aconfig: add new testing flag enabled_fixed_ro_exported

This commit adds a new testing flag enabled_fixed_ro_exported to test
the case of a exported and fixed_read_only flag.

Test: atest aconfig.test aconfig.test.java AconfigJavaHostTest
aconfig.test.cpp aconfig.test.cpp.test_mode aconfig.prod_mode.test.rust
Bug: 316357680

Change-Id: Iaedb8a6875166c6a6d24c7c3deee701a496b4964
parent c1d0a14b
Loading
Loading
Loading
Loading
+80 −3
Original line number Diff line number Diff line
@@ -153,6 +153,10 @@ mod tests {
#define COM_ANDROID_ACONFIG_TEST_ENABLED_FIXED_RO true
#endif

#ifndef COM_ANDROID_ACONFIG_TEST_ENABLED_FIXED_RO_EXPORTED
#define COM_ANDROID_ACONFIG_TEST_ENABLED_FIXED_RO_EXPORTED true
#endif

#ifdef __cplusplus

#include <memory>
@@ -173,6 +177,8 @@ public:

    virtual bool enabled_fixed_ro() = 0;

    virtual bool enabled_fixed_ro_exported() = 0;

    virtual bool enabled_ro() = 0;

    virtual bool enabled_ro_exported() = 0;
@@ -202,6 +208,10 @@ inline bool enabled_fixed_ro() {
    return COM_ANDROID_ACONFIG_TEST_ENABLED_FIXED_RO;
}

inline bool enabled_fixed_ro_exported() {
    return COM_ANDROID_ACONFIG_TEST_ENABLED_FIXED_RO_EXPORTED;
}

inline bool enabled_ro() {
    return true;
}
@@ -229,6 +239,8 @@ bool com_android_aconfig_test_disabled_rw_in_other_namespace();

bool com_android_aconfig_test_enabled_fixed_ro();

bool com_android_aconfig_test_enabled_fixed_ro_exported();

bool com_android_aconfig_test_enabled_ro();

bool com_android_aconfig_test_enabled_ro_exported();
@@ -274,6 +286,10 @@ public:

    virtual void enabled_fixed_ro(bool val) = 0;

    virtual bool enabled_fixed_ro_exported() = 0;

    virtual void enabled_fixed_ro_exported(bool val) = 0;

    virtual bool enabled_ro() = 0;

    virtual void enabled_ro(bool val) = 0;
@@ -331,6 +347,14 @@ inline void enabled_fixed_ro(bool val) {
    provider_->enabled_fixed_ro(val);
}

inline bool enabled_fixed_ro_exported() {
    return provider_->enabled_fixed_ro_exported();
}

inline void enabled_fixed_ro_exported(bool val) {
    provider_->enabled_fixed_ro_exported(val);
}

inline bool enabled_ro() {
    return provider_->enabled_ro();
}
@@ -384,6 +408,10 @@ bool com_android_aconfig_test_enabled_fixed_ro();

void set_com_android_aconfig_test_enabled_fixed_ro(bool val);

bool com_android_aconfig_test_enabled_fixed_ro_exported();

void set_com_android_aconfig_test_enabled_fixed_ro_exported(bool val);

bool com_android_aconfig_test_enabled_ro();

void set_com_android_aconfig_test_enabled_ro(bool val);
@@ -421,6 +449,8 @@ public:

    virtual bool disabled_rw_exported() = 0;

    virtual bool enabled_fixed_ro_exported() = 0;

    virtual bool enabled_ro_exported() = 0;
};

@@ -430,6 +460,10 @@ inline bool disabled_rw_exported() {
    return provider_->disabled_rw_exported();
}

inline bool enabled_fixed_ro_exported() {
    return provider_->enabled_fixed_ro_exported();
}

inline bool enabled_ro_exported() {
    return provider_->enabled_ro_exported();
}
@@ -441,6 +475,8 @@ extern "C" {

bool com_android_aconfig_test_disabled_rw_exported();

bool com_android_aconfig_test_enabled_fixed_ro_exported();

bool com_android_aconfig_test_enabled_ro_exported();

#ifdef __cplusplus
@@ -496,6 +532,10 @@ namespace com::android::aconfig::test {
                return COM_ANDROID_ACONFIG_TEST_ENABLED_FIXED_RO;
            }

            virtual bool enabled_fixed_ro_exported() override {
                return COM_ANDROID_ACONFIG_TEST_ENABLED_FIXED_RO_EXPORTED;
            }

            virtual bool enabled_ro() override {
                return true;
            }
@@ -542,6 +582,10 @@ bool com_android_aconfig_test_enabled_fixed_ro() {
    return COM_ANDROID_ACONFIG_TEST_ENABLED_FIXED_RO;
}

bool com_android_aconfig_test_enabled_fixed_ro_exported() {
    return COM_ANDROID_ACONFIG_TEST_ENABLED_FIXED_RO_EXPORTED;
}

bool com_android_aconfig_test_enabled_ro() {
    return true;
}
@@ -647,6 +691,19 @@ namespace com::android::aconfig::test {
                overrides_["enabled_fixed_ro"] = val;
            }

            virtual bool enabled_fixed_ro_exported() override {
                auto it = overrides_.find("enabled_fixed_ro_exported");
                  if (it != overrides_.end()) {
                      return it->second;
                } else {
                  return true;
                }
            }

            virtual void enabled_fixed_ro_exported(bool val) override {
                overrides_["enabled_fixed_ro_exported"] = val;
            }

            virtual bool enabled_ro() override {
                auto it = overrides_.find("enabled_ro");
                  if (it != overrides_.end()) {
@@ -743,6 +800,13 @@ void set_com_android_aconfig_test_enabled_fixed_ro(bool val) {
    com::android::aconfig::test::enabled_fixed_ro(val);
}

bool com_android_aconfig_test_enabled_fixed_ro_exported() {
    return com::android::aconfig::test::enabled_fixed_ro_exported();
}

void set_com_android_aconfig_test_enabled_fixed_ro_exported(bool val) {
    com::android::aconfig::test::enabled_fixed_ro_exported(val);
}

bool com_android_aconfig_test_enabled_ro() {
    return com::android::aconfig::test::enabled_ro();
@@ -798,19 +862,28 @@ namespace com::android::aconfig::test {
                return cache_[0];
            }

            virtual bool enabled_ro_exported() override {
            virtual bool enabled_fixed_ro_exported() override {
                if (cache_[1] == -1) {
                    cache_[1] = server_configurable_flags::GetServerConfigurableFlag(
                        "aconfig_flags.aconfig_test",
                        "com.android.aconfig.test.enabled_ro_exported",
                        "com.android.aconfig.test.enabled_fixed_ro_exported",
                        "false") == "true";
                }
                return cache_[1];
            }

            virtual bool enabled_ro_exported() override {
                if (cache_[2] == -1) {
                    cache_[2] = server_configurable_flags::GetServerConfigurableFlag(
                        "aconfig_flags.aconfig_test",
                        "com.android.aconfig.test.enabled_ro_exported",
                        "false") == "true";
                }
                return cache_[2];
            }

    private:
        std::vector<int8_t> cache_ = std::vector<int8_t>(2, -1);
        std::vector<int8_t> cache_ = std::vector<int8_t>(3, -1);
    };

    std::unique_ptr<flag_provider_interface> provider_ =
@@ -821,6 +894,10 @@ bool com_android_aconfig_test_disabled_rw_exported() {
    return com::android::aconfig::test::disabled_rw_exported();
}

bool com_android_aconfig_test_enabled_fixed_ro_exported() {
    return com::android::aconfig::test::enabled_fixed_ro_exported();
}

bool com_android_aconfig_test_enabled_ro_exported() {
    return com::android::aconfig::test::enabled_ro_exported();
}
+53 −0
Original line number Diff line number Diff line
@@ -202,6 +202,9 @@ mod tests {
        boolean enabledFixedRo();
        @com.android.aconfig.annotations.AssumeTrueForR8
        @UnsupportedAppUsage
        boolean enabledFixedRoExported();
        @com.android.aconfig.annotations.AssumeTrueForR8
        @UnsupportedAppUsage
        boolean enabledRo();
        @com.android.aconfig.annotations.AssumeTrueForR8
        @UnsupportedAppUsage
@@ -228,6 +231,8 @@ mod tests {
        /** @hide */
        public static final String FLAG_ENABLED_FIXED_RO = "com.android.aconfig.test.enabled_fixed_ro";
        /** @hide */
        public static final String FLAG_ENABLED_FIXED_RO_EXPORTED = "com.android.aconfig.test.enabled_fixed_ro_exported";
        /** @hide */
        public static final String FLAG_ENABLED_RO = "com.android.aconfig.test.enabled_ro";
        /** @hide */
        public static final String FLAG_ENABLED_RO_EXPORTED = "com.android.aconfig.test.enabled_ro_exported";
@@ -258,6 +263,11 @@ mod tests {
        }
        @com.android.aconfig.annotations.AssumeTrueForR8
        @UnsupportedAppUsage
        public static boolean enabledFixedRoExported() {
            return FEATURE_FLAGS.enabledFixedRoExported();
        }
        @com.android.aconfig.annotations.AssumeTrueForR8
        @UnsupportedAppUsage
        public static boolean enabledRo() {
            return FEATURE_FLAGS.enabledRo();
        }
@@ -310,6 +320,11 @@ mod tests {
        }
        @Override
        @UnsupportedAppUsage
        public boolean enabledFixedRoExported() {
            return getValue(Flags.FLAG_ENABLED_FIXED_RO_EXPORTED);
        }
        @Override
        @UnsupportedAppUsage
        public boolean enabledRo() {
            return getValue(Flags.FLAG_ENABLED_RO);
        }
@@ -348,6 +363,7 @@ mod tests {
                Map.entry(Flags.FLAG_DISABLED_RW_EXPORTED, false),
                Map.entry(Flags.FLAG_DISABLED_RW_IN_OTHER_NAMESPACE, false),
                Map.entry(Flags.FLAG_ENABLED_FIXED_RO, false),
                Map.entry(Flags.FLAG_ENABLED_FIXED_RO_EXPORTED, false),
                Map.entry(Flags.FLAG_ENABLED_RO, false),
                Map.entry(Flags.FLAG_ENABLED_RO_EXPORTED, false),
                Map.entry(Flags.FLAG_ENABLED_RW, false)
@@ -463,6 +479,11 @@ mod tests {
            }
            @Override
            @UnsupportedAppUsage
            public boolean enabledFixedRoExported() {
                return true;
            }
            @Override
            @UnsupportedAppUsage
            public boolean enabledRo() {
                return true;
            }
@@ -528,6 +549,8 @@ mod tests {
            /** @hide */
            public static final String FLAG_DISABLED_RW_EXPORTED = "com.android.aconfig.test.disabled_rw_exported";
            /** @hide */
            public static final String FLAG_ENABLED_FIXED_RO_EXPORTED = "com.android.aconfig.test.enabled_fixed_ro_exported";
            /** @hide */
            public static final String FLAG_ENABLED_RO_EXPORTED = "com.android.aconfig.test.enabled_ro_exported";

            @UnsupportedAppUsage
@@ -535,6 +558,10 @@ mod tests {
                return FEATURE_FLAGS.disabledRwExported();
            }
            @UnsupportedAppUsage
            public static boolean enabledFixedRoExported() {
                return FEATURE_FLAGS.enabledFixedRoExported();
            }
            @UnsupportedAppUsage
            public static boolean enabledRoExported() {
                return FEATURE_FLAGS.enabledRoExported();
            }
@@ -551,6 +578,8 @@ mod tests {
            @UnsupportedAppUsage
            boolean disabledRwExported();
            @UnsupportedAppUsage
            boolean enabledFixedRoExported();
            @UnsupportedAppUsage
            boolean enabledRoExported();
        }
        "#;
@@ -566,6 +595,7 @@ mod tests {
            private static boolean aconfig_test_is_cached = false;
            private static boolean other_namespace_is_cached = false;
            private static boolean disabledRwExported = false;
            private static boolean enabledFixedRoExported = false;
            private static boolean enabledRoExported = false;


@@ -574,6 +604,8 @@ mod tests {
                    Properties properties = DeviceConfig.getProperties("aconfig_test");
                    disabledRwExported =
                        properties.getBoolean("com.android.aconfig.test.disabled_rw_exported", false);
                    enabledFixedRoExported =
                        properties.getBoolean("com.android.aconfig.test.enabled_fixed_ro_exported", false);
                    enabledRoExported =
                        properties.getBoolean("com.android.aconfig.test.enabled_ro_exported", false);
                } catch (NullPointerException e) {
@@ -614,6 +646,15 @@ mod tests {
                return disabledRwExported;
            }

            @Override
            @UnsupportedAppUsage
            public boolean enabledFixedRoExported() {
                if (!aconfig_test_is_cached) {
                    load_overrides_aconfig_test();
                }
                return enabledFixedRoExported;
            }

            @Override
            @UnsupportedAppUsage
            public boolean enabledRoExported() {
@@ -642,6 +683,11 @@ mod tests {
            }
            @Override
            @UnsupportedAppUsage
            public boolean enabledFixedRoExported() {
                return getValue(Flags.FLAG_ENABLED_FIXED_RO_EXPORTED);
            }
            @Override
            @UnsupportedAppUsage
            public boolean enabledRoExported() {
                return getValue(Flags.FLAG_ENABLED_RO_EXPORTED);
            }
@@ -666,6 +712,7 @@ mod tests {
            private Map<String, Boolean> mFlagMap = new HashMap<>(
                Map.ofEntries(
                    Map.entry(Flags.FLAG_DISABLED_RW_EXPORTED, false),
                    Map.entry(Flags.FLAG_ENABLED_FIXED_RO_EXPORTED, false),
                    Map.entry(Flags.FLAG_ENABLED_RO_EXPORTED, false)
                )
            );
@@ -759,6 +806,12 @@ mod tests {
            }
            @Override
            @UnsupportedAppUsage
            public boolean enabledFixedRoExported() {
                throw new UnsupportedOperationException(
                    "Method is not implemented.");
            }
            @Override
            @UnsupportedAppUsage
            public boolean enabledRo() {
                throw new UnsupportedOperationException(
                    "Method is not implemented.");
+35 −0
Original line number Diff line number Diff line
@@ -153,6 +153,11 @@ impl FlagProvider {
        true
    }

    /// query flag enabled_fixed_ro_exported
    pub fn enabled_fixed_ro_exported(&self) -> bool {
        true
    }

    /// query flag enabled_ro
    pub fn enabled_ro(&self) -> bool {
        true
@@ -202,6 +207,12 @@ pub fn enabled_fixed_ro() -> bool {
    true
}

/// query flag enabled_fixed_ro_exported
#[inline(always)]
pub fn enabled_fixed_ro_exported() -> bool {
    true
}

/// query flag enabled_ro
#[inline(always)]
pub fn enabled_ro() -> bool {
@@ -302,6 +313,18 @@ impl FlagProvider {
        self.overrides.insert("enabled_fixed_ro", val);
    }

    /// query flag enabled_fixed_ro_exported
    pub fn enabled_fixed_ro_exported(&self) -> bool {
        self.overrides.get("enabled_fixed_ro_exported").copied().unwrap_or(
            true
        )
    }

    /// set flag enabled_fixed_ro_exported
    pub fn set_enabled_fixed_ro_exported(&mut self, val: bool) {
        self.overrides.insert("enabled_fixed_ro_exported", val);
    }

    /// query flag enabled_ro
    pub fn enabled_ro(&self) -> bool {
        self.overrides.get("enabled_ro").copied().unwrap_or(
@@ -412,6 +435,18 @@ pub fn set_enabled_fixed_ro(val: bool) {
    PROVIDER.lock().unwrap().set_enabled_fixed_ro(val);
}

/// query flag enabled_fixed_ro_exported
#[inline(always)]
pub fn enabled_fixed_ro_exported() -> bool {
    PROVIDER.lock().unwrap().enabled_fixed_ro_exported()
}

/// set flag enabled_fixed_ro_exported
#[inline(always)]
pub fn set_enabled_fixed_ro_exported(val: bool) {
    PROVIDER.lock().unwrap().set_enabled_fixed_ro_exported(val);
}

/// query flag enabled_ro
#[inline(always)]
pub fn enabled_ro() -> bool {
+13 −7
Original line number Diff line number Diff line
@@ -390,9 +390,9 @@ mod tests {
        assert_eq!(ProtoFlagState::ENABLED, enabled_ro.trace[2].state());
        assert_eq!(ProtoFlagPermission::READ_ONLY, enabled_ro.trace[2].permission());

        assert_eq!(8, parsed_flags.parsed_flag.len());
        assert_eq!(9, parsed_flags.parsed_flag.len());
        for pf in parsed_flags.parsed_flag.iter() {
            if pf.name() == "enabled_fixed_ro" {
            if pf.name().starts_with("enabled_fixed_ro") {
                continue;
            }
            let first = pf.trace.first().unwrap();
@@ -621,7 +621,13 @@ mod tests {
        let bytes =
            dump_parsed_flags(vec![input, input2], DumpFormat::Textproto, &[], true).unwrap();
        let text = std::str::from_utf8(&bytes).unwrap();
        assert_eq!(crate::test::TEST_FLAGS_TEXTPROTO.trim(), text.trim());
        assert_eq!(
            None,
            crate::test::first_significant_code_diff(
                crate::test::TEST_FLAGS_TEXTPROTO.trim(),
                text.trim()
            )
        );
    }

    #[test]
@@ -631,14 +637,14 @@ mod tests {

        let filtered_parsed_flags =
            filter_parsed_flags(parsed_flags.clone(), CodegenMode::Exported);
        assert_eq!(2, filtered_parsed_flags.len());
        assert_eq!(3, filtered_parsed_flags.len());

        let filtered_parsed_flags =
            filter_parsed_flags(parsed_flags.clone(), CodegenMode::Production);
        assert_eq!(8, filtered_parsed_flags.len());
        assert_eq!(9, filtered_parsed_flags.len());

        let filtered_parsed_flags = filter_parsed_flags(parsed_flags.clone(), CodegenMode::Test);
        assert_eq!(8, filtered_parsed_flags.len());
        assert_eq!(9, filtered_parsed_flags.len());
    }

    fn parse_test_flags_as_input() -> Input {
@@ -664,7 +670,7 @@ mod tests {
    fn test_modify_parsed_flags_based_on_mode_exported() {
        let parsed_flags = crate::test::parse_test_flags();
        let p_parsed_flags = modify_parsed_flags_based_on_mode(parsed_flags, CodegenMode::Exported);
        assert_eq!(2, p_parsed_flags.len());
        assert_eq!(3, p_parsed_flags.len());
        for flag in p_parsed_flags.iter() {
            assert_eq!(ProtoFlagState::DISABLED, flag.state());
            assert_eq!(ProtoFlagPermission::READ_WRITE, flag.permission());
+10 −1
Original line number Diff line number Diff line
@@ -341,6 +341,7 @@ mod tests {
                "com.android.aconfig.test.disabled_rw_exported",
                "com.android.aconfig.test.disabled_rw_in_other_namespace",
                "com.android.aconfig.test.enabled_fixed_ro",
                "com.android.aconfig.test.enabled_fixed_ro_exported",
                "com.android.aconfig.test.enabled_ro",
                "com.android.aconfig.test.enabled_ro_exported",
                "com.android.aconfig.test.enabled_rw",
@@ -360,6 +361,7 @@ mod tests {
            "state:ENABLED",
            &[
                "com.android.aconfig.test.enabled_fixed_ro",
                "com.android.aconfig.test.enabled_fixed_ro_exported",
                "com.android.aconfig.test.enabled_ro",
                "com.android.aconfig.test.enabled_ro_exported",
                "com.android.aconfig.test.enabled_rw",
@@ -370,6 +372,7 @@ mod tests {
            &[
                "com.android.aconfig.test.disabled_ro",
                "com.android.aconfig.test.enabled_fixed_ro",
                "com.android.aconfig.test.enabled_fixed_ro_exported",
                "com.android.aconfig.test.enabled_ro",
                "com.android.aconfig.test.enabled_ro_exported",
            ]
@@ -377,12 +380,16 @@ mod tests {
        // trace: not supported yet
        assert_create_filter_predicate!(
            "is_fixed_read_only:true",
            &["com.android.aconfig.test.enabled_fixed_ro"]
            &[
                "com.android.aconfig.test.enabled_fixed_ro",
                "com.android.aconfig.test.enabled_fixed_ro_exported",
            ]
        );
        assert_create_filter_predicate!(
            "is_exported:true",
            &[
                "com.android.aconfig.test.disabled_rw_exported",
                "com.android.aconfig.test.enabled_fixed_ro_exported",
                "com.android.aconfig.test.enabled_ro_exported",
            ]
        );
@@ -394,6 +401,7 @@ mod tests {
                "com.android.aconfig.test.disabled_rw_exported",
                "com.android.aconfig.test.disabled_rw_in_other_namespace",
                "com.android.aconfig.test.enabled_fixed_ro",
                "com.android.aconfig.test.enabled_fixed_ro_exported",
                "com.android.aconfig.test.enabled_ro",
                "com.android.aconfig.test.enabled_ro_exported",
                "com.android.aconfig.test.enabled_rw",
@@ -406,6 +414,7 @@ mod tests {
            "permission:READ_ONLY+state:ENABLED",
            &[
                "com.android.aconfig.test.enabled_fixed_ro",
                "com.android.aconfig.test.enabled_fixed_ro_exported",
                "com.android.aconfig.test.enabled_ro",
                "com.android.aconfig.test.enabled_ro_exported",
            ]
Loading