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

Commit 5f837486 authored by Dennis Shen's avatar Dennis Shen
Browse files

Update codegen to return defautl value if package is not in storage file

Bug: 301491148
Test: m and presubmits
Change-Id: Ic4ed15f31fce928e89a2b12259a69faa48e5f60e
parent f936d5b4
Loading
Loading
Loading
Loading
+16 −4
Original line number Diff line number Diff line
@@ -295,7 +295,10 @@ static CACHED_disabled_rw: LazyLock<bool> = LazyLock::new(|| {
                                get_boolean_flag_value(&flag_val_map, offset + 1)
                                    .map_err(|err| format!("failed to get flag: {err}"))
                            },
                            None => Err("no context found for package 'com.android.aconfig.test'".to_string())
                            None => {
                                log!(Level::Error, "no context found for package com.android.aconfig.test");
                                Ok(false)
                            }
                        }
                    })
                });
@@ -339,7 +342,10 @@ static CACHED_disabled_rw_exported: LazyLock<bool> = LazyLock::new(|| {
                                get_boolean_flag_value(&flag_val_map, offset + 2)
                                    .map_err(|err| format!("failed to get flag: {err}"))
                            },
                            None => Err("no context found for package 'com.android.aconfig.test'".to_string())
                            None => {
                                log!(Level::Error, "no context found for package com.android.aconfig.test");
                                Ok(false)
                            }
                        }
                    })
                });
@@ -383,7 +389,10 @@ static CACHED_disabled_rw_in_other_namespace: LazyLock<bool> = LazyLock::new(||
                                get_boolean_flag_value(&flag_val_map, offset + 3)
                                    .map_err(|err| format!("failed to get flag: {err}"))
                            },
                            None => Err("no context found for package 'com.android.aconfig.test'".to_string())
                            None => {
                                log!(Level::Error, "no context found for package com.android.aconfig.test");
                                Ok(false)
                            }
                        }
                    })
                });
@@ -428,7 +437,10 @@ static CACHED_enabled_rw: LazyLock<bool> = LazyLock::new(|| {
                                get_boolean_flag_value(&flag_val_map, offset + 8)
                                    .map_err(|err| format!("failed to get flag: {err}"))
                            },
                            None => Err("no context found for package 'com.android.aconfig.test'".to_string())
                            None => {
                                log!(Level::Error, "no context found for package com.android.aconfig.test");
                                Ok(true)
                            }
                        }
                    })
                });
+13 −1
Original line number Diff line number Diff line
@@ -76,7 +76,8 @@ namespace {cpp_namespace} \{
            : boolean_start_index_()
            {{ -endif }}
            , flag_value_file_(nullptr)
            , read_from_new_storage_(false) \{
            , read_from_new_storage_(false)
            , package_exists_in_storage_(true) \{

            if (access("/metadata/aconfig/boot/enable_only_new_storage", F_OK) == 0) \{
               read_from_new_storage_ = true;
@@ -99,6 +100,11 @@ namespace {cpp_namespace} \{
                ALOGE("error: failed to get package read context: %s", context.error().c_str());
            }

            if (!(context->package_exists)) \{
               package_exists_in_storage_ = false;
               return;
            }

            // cache package boolean flag start index
            boolean_start_index_ = context->boolean_start_index;

@@ -126,6 +132,10 @@ namespace {cpp_namespace} \{
            if (cache_[{item.readwrite_idx}] == -1) \{
            {{ if allow_instrumentation- }}
                if (read_from_new_storage_) \{
                    if (!package_exists_in_storage_) \{
                       return {item.default_value};
                    }

                    auto value = aconfig_storage::get_boolean_flag_value(
                        *flag_value_file_,
                        boolean_start_index_ + {item.flag_offset});
@@ -168,6 +178,8 @@ namespace {cpp_namespace} \{
        std::unique_ptr<aconfig_storage::MappedStorageFile> flag_value_file_;

        bool read_from_new_storage_;

        bool package_exists_in_storage_;
    {{ -endif }}
    {{ -endif }}

+4 −1
Original line number Diff line number Diff line
@@ -51,7 +51,10 @@ static CACHED_{flag.name}: LazyLock<bool> = LazyLock::new(|| \{
                                get_boolean_flag_value(&flag_val_map, offset + {flag.flag_offset})
                                    .map_err(|err| format!("failed to get flag: \{err}"))
                            },
                            None => Err("no context found for package '{package}'".to_string())
                            None => \{
                                 log!(Level::Error, "no context found for package {package}");
                                 Ok({flag.default_value})
                            }
                        }
                    })
                });
+2 −2
Original line number Diff line number Diff line
@@ -9,7 +9,7 @@ paste = "1.0.11"
protobuf = "3.2.0"
regex = "1.10.3"
aconfig_protos = { path = "../aconfig_protos" }
aconfigd_protos = { version = "0.1.0", path = "../../../../../system/server_configurable_flags/aconfigd"}
aconfigd_protos = { version = "0.1.0", path = "../../../../../packages/modules/ConfigInfrastructure/aconfigd/proto"}
nix = { version = "0.28.0", features = ["user"] }
aconfig_storage_file = { version = "0.1.0", path = "../aconfig_storage_file" }
aconfig_storage_read_api = { version = "0.1.0", path = "../aconfig_storage_read_api" }