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

Commit 41b52321 authored by Zhi Dou's avatar Zhi Dou Committed by Gerrit Code Review
Browse files

Merge "add allow_instrumentation back" into main

parents 5badb85e be41b100
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -501,7 +501,7 @@ mod tests {
            modified_parsed_flags.into_iter(),
            mode,
            flag_ids,
            false,
            true,
        )
        .unwrap();
        let expect_flags_content = EXPECTED_FLAG_COMMON_CONTENT.to_string()
+67 −0
Original line number Diff line number Diff line
package {package_name};
{{ -if not is_test_mode }}
{{ -if allow_instrumentation }}
{{ if not library_exported- }}
// TODO(b/303773055): Remove the annotation after access issue is resolved.
import android.compat.annotation.UnsupportedAppUsage;
@@ -112,6 +113,72 @@ public final class FeatureFlagsImpl implements FeatureFlags \{
    }
{{ endfor }}
}

{{ else }} {#- else for allow_instrumentation is not enabled #}
{{ if not library_exported- }}
// TODO(b/303773055): Remove the annotation after access issue is resolved.
import android.compat.annotation.UnsupportedAppUsage;
{{ -endif }}

{{ -if runtime_lookup_required }}
import android.provider.DeviceConfig;
import android.provider.DeviceConfig.Properties;
{{ -endif }}
/** @hide */
public final class FeatureFlagsImpl implements FeatureFlags \{
{{ -if runtime_lookup_required }}
{{ -for namespace_with_flags in namespace_flags }}
    private static volatile boolean {namespace_with_flags.namespace}_is_cached = false;
{{ -endfor- }}

{{ for flag in flag_elements }}
{{- if flag.is_read_write }}
    private static boolean {flag.method_name} = {flag.default_value};
{{ -endif }}
{{ -endfor }}
{{ for namespace_with_flags in namespace_flags }}
    private void load_overrides_{namespace_with_flags.namespace}() \{
        try \{
            Properties properties = DeviceConfig.getProperties("{namespace_with_flags.namespace}");
{{ -for flag in namespace_with_flags.flags }}
{{ -if flag.is_read_write }}
            {flag.method_name} =
                properties.getBoolean(Flags.FLAG_{flag.flag_name_constant_suffix}, {flag.default_value});
{{ -endif }}
{{ -endfor }}
        } catch (NullPointerException e) \{
            throw new RuntimeException(
                "Cannot read value from namespace {namespace_with_flags.namespace} "
                + "from DeviceConfig. It could be that the code using flag "
                + "executed before SettingsProvider initialization. Please use "
                + "fixed read-only flag by adding is_fixed_read_only: true in "
                + "flag declaration.",
                e
            );
        }
        {namespace_with_flags.namespace}_is_cached = true;
}
{{ endfor- }}
{{ -endif }}{#- end of runtime_lookup_required #}
{{ -for flag in flag_elements }}
    @Override
{{ -if not library_exported }}
    @com.android.aconfig.annotations.AconfigFlagAccessor
    @UnsupportedAppUsage
{{ -endif }}
    public boolean {flag.method_name}() \{
{{ -if flag.is_read_write }}
        if (!{flag.device_config_namespace}_is_cached) \{
            load_overrides_{flag.device_config_namespace}();
        }
        return {flag.method_name};
{{ -else }}
        return {flag.default_value};
{{ -endif }}
    }
{{ endfor }}
}
{{ endif}} {#- endif for allow_instrumentation #}
{{ else }} {#- Generate only stub if in test mode #}
/** @hide */
public final class FeatureFlagsImpl implements FeatureFlags \{