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

Commit 01473c6c authored by Zhi Dou's avatar Zhi Dou Committed by Automerger Merge Worker
Browse files

Merge "Revert "remove file check"" into main am: e7784d13

parents 3af87ab4 e7784d13
Loading
Loading
Loading
Loading
+89 −8
Original line number Diff line number Diff line
@@ -513,11 +513,19 @@ 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.Binder;
        import android.provider.DeviceConfig;
        import android.provider.DeviceConfig.Properties;
        import android.aconfig.storage.StorageInternalReader;
        import java.nio.file.Files;
        import java.nio.file.Paths;

        /** @hide */
        public final class FeatureFlagsImpl implements FeatureFlags {
            private static final boolean isReadFromNew = Files.exists(Paths.get("/metadata/aconfig/boot/enable_only_new_storage"));
            private static volatile boolean isCached = false;
            private static volatile boolean aconfig_test_is_cached = false;
            private static volatile boolean other_namespace_is_cached = false;
            private static boolean disabledRw = false;
            private static boolean disabledRwExported = false;
            private static boolean disabledRwInOtherNamespace = false;
@@ -536,6 +544,55 @@ mod tests {
                disabledRwInOtherNamespace = foundPackage ? reader.getBooleanFlagValue(3) : false;
                isCached = true;
            }
            private void load_overrides_aconfig_test() {
                final long ident = Binder.clearCallingIdentity();
                try {
                    Properties properties = DeviceConfig.getProperties("aconfig_test");
                    disabledRw =
                        properties.getBoolean(Flags.FLAG_DISABLED_RW, false);
                    disabledRwExported =
                        properties.getBoolean(Flags.FLAG_DISABLED_RW_EXPORTED, false);
                    enabledRw =
                        properties.getBoolean(Flags.FLAG_ENABLED_RW, true);
                } catch (NullPointerException e) {
                    throw new RuntimeException(
                        "Cannot read value from namespace aconfig_test "
                        + "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
                    );
                } catch (SecurityException e) {
                    // for isolated process case, skip loading flag value from the storage, use the default
                } finally {
                    Binder.restoreCallingIdentity(ident);
                }
                aconfig_test_is_cached = true;
            }

            private void load_overrides_other_namespace() {
                final long ident = Binder.clearCallingIdentity();
                try {
                    Properties properties = DeviceConfig.getProperties("other_namespace");
                    disabledRwInOtherNamespace =
                        properties.getBoolean(Flags.FLAG_DISABLED_RW_IN_OTHER_NAMESPACE, false);
                } catch (NullPointerException e) {
                    throw new RuntimeException(
                        "Cannot read value from namespace other_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
                    );
                } catch (SecurityException e) {
                    // for isolated process case, skip loading flag value from the storage, use the default
                } finally {
                    Binder.restoreCallingIdentity(ident);
                }
                other_namespace_is_cached = true;
            }

            @Override
            @com.android.aconfig.annotations.AconfigFlagAccessor
@@ -547,27 +604,45 @@ mod tests {
            @com.android.aconfig.annotations.AconfigFlagAccessor
            @UnsupportedAppUsage
            public boolean disabledRw() {
                if (isReadFromNew) {
                    if (!isCached) {
                        init();
                    }
                } else {
                    if (!aconfig_test_is_cached) {
                        load_overrides_aconfig_test();
                    }
                }
                return disabledRw;
            }
            @Override
            @com.android.aconfig.annotations.AconfigFlagAccessor
            @UnsupportedAppUsage
            public boolean disabledRwExported() {
                if (isReadFromNew) {
                    if (!isCached) {
                        init();
                    }
                } else {
                    if (!aconfig_test_is_cached) {
                        load_overrides_aconfig_test();
                    }
                }
                return disabledRwExported;
            }
            @Override
            @com.android.aconfig.annotations.AconfigFlagAccessor
            @UnsupportedAppUsage
            public boolean disabledRwInOtherNamespace() {
                if (isReadFromNew) {
                    if (!isCached) {
                        init();
                    }
                } else {
                    if (!other_namespace_is_cached) {
                        load_overrides_other_namespace();
                    }
                }
                return disabledRwInOtherNamespace;
            }
            @Override
@@ -598,9 +673,15 @@ mod tests {
            @com.android.aconfig.annotations.AconfigFlagAccessor
            @UnsupportedAppUsage
            public boolean enabledRw() {
                if (isReadFromNew) {
                    if (!isCached) {
                        init();
                    }
                } else {
                    if (!aconfig_test_is_cached) {
                        load_overrides_aconfig_test();
                    }
                }
                return enabledRw;
            }
        }
+47 −33
Original line number Diff line number Diff line
package {package_name};
{{ -if not is_test_mode }}
{{ -if allow_instrumentation }}
{{ if not library_exported- }}{#- only new storage for prod mode #}
{{ 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.os.Binder;
import android.provider.DeviceConfig;
import android.provider.DeviceConfig.Properties;

{{ -if not library_exported }}
import android.aconfig.storage.StorageInternalReader;
import java.nio.file.Files;
import java.nio.file.Paths;
{{ -endif }}

{{ -endif }}
/** @hide */
public final class FeatureFlagsImpl implements FeatureFlags \{
{{ -if runtime_lookup_required }}
{{ -if not library_exported }}
    private static final boolean isReadFromNew = Files.exists(Paths.get("/metadata/aconfig/boot/enable_only_new_storage"));
    private static volatile boolean isCached = false;
{{ -endif }}
{{ -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 }}

{{ if not library_exported }}
    private void init() \{
        StorageInternalReader reader = null;
        boolean foundPackage = true;
@@ -34,37 +53,9 @@ public final class FeatureFlagsImpl implements FeatureFlags \{
        {{ -endfor }}
        isCached = true;
    }
{{ -endif }}{#- end of runtime_lookup_required #}
{{ -for flag in flag_elements }}
    @Override
    @com.android.aconfig.annotations.AconfigFlagAccessor
    @UnsupportedAppUsage
    public boolean {flag.method_name}() \{
{{ -if flag.is_read_write }}
        if (!isCached) \{
            init();
        }
        return {flag.method_name};
{{ -else }}
        return {flag.default_value};
{{ -endif }}
    }
{{ endfor }}
}
{{ -else- }}{#- device config for exproted mode #}
import android.os.Binder;
import android.provider.DeviceConfig;
import android.provider.DeviceConfig.Properties;
/** @hide */
public final class FeatureFlagsImpl implements FeatureFlags \{
{{ -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 }}
{{ endif }}


{{ for namespace_with_flags in namespace_flags }}
    private void load_overrides_{namespace_with_flags.namespace}() \{
        final long ident = Binder.clearCallingIdentity();
@@ -93,17 +84,40 @@ public final class FeatureFlagsImpl implements FeatureFlags \{
        {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 not library_exported }}
{{ -if flag.is_read_write }}
        if (isReadFromNew) \{
            if (!isCached) \{
                init();
            }
        } else \{
            if (!{flag.device_config_namespace}_is_cached) \{
                load_overrides_{flag.device_config_namespace}();
            }
        }
        return {flag.method_name};
{{ -else }}
        return {flag.default_value};
{{ -endif }}
{{ else }}
        if (!{flag.device_config_namespace}_is_cached) \{
            load_overrides_{flag.device_config_namespace}();
        }
        return {flag.method_name};
{{ -endif }}
    }
{{ endfor }}
}
{{ -endif- }} {#- end exported mode #}

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