Loading tools/aconfig/aconfig/src/codegen/java.rs +46 −63 Original line number Original line Diff line number Diff line Loading @@ -46,7 +46,6 @@ where let runtime_lookup_required = let runtime_lookup_required = flag_elements.iter().any(|elem| elem.is_read_write) || library_exported; flag_elements.iter().any(|elem| elem.is_read_write) || library_exported; let container = (flag_elements.first().expect("zero template flags").container).to_string(); let container = (flag_elements.first().expect("zero template flags").container).to_string(); let context = Context { let context = Context { flag_elements, flag_elements, namespace_flags, namespace_flags, Loading Loading @@ -693,7 +692,6 @@ mod tests { + r#" + r#" import android.aconfig.storage.StorageInternalReader; import android.aconfig.storage.StorageInternalReader; import android.util.Log; import android.util.Log; import java.io.File; "# "# + expected_featureflagsmpl_content_1 + expected_featureflagsmpl_content_1 + r#" + r#" Loading @@ -701,10 +699,13 @@ mod tests { boolean readFromNewStorage; boolean readFromNewStorage; private final static String TAG = "AconfigJavaCodegen"; private final static String TAG = "AconfigJavaCodegen"; private final static String SUCCESS_LOG = "success: %s value matches"; private final static String MISMATCH_LOG = "error: %s value mismatch, new storage value is %s, old storage value is %s"; private final static String ERROR_LOG = "error: failed to read flag value"; public FeatureFlagsImpl() { private void init() { File file = new File("/metadata/aconfig_test_missions/mission_1"); if (reader != null) return; if (file.exists()) { if (DeviceConfig.getBoolean("core_experiments_team_internal", "com.android.providers.settings.storage_test_mission_1", false)) { readFromNewStorage = true; readFromNewStorage = true; try { try { reader = new StorageInternalReader("system", "com.android.aconfig.test"); reader = new StorageInternalReader("system", "com.android.aconfig.test"); Loading @@ -716,89 +717,57 @@ mod tests { private void load_overrides_aconfig_test() { private void load_overrides_aconfig_test() { try { try { boolean val; Properties properties = DeviceConfig.getProperties("aconfig_test"); Properties properties = DeviceConfig.getProperties("aconfig_test"); disabledRw = disabledRw = properties.getBoolean(Flags.FLAG_DISABLED_RW, false); 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 ); } aconfig_test_is_cached = true; init(); if (readFromNewStorage && reader != null) { if (readFromNewStorage && reader != null) { boolean val; try { try { val = reader.getBooleanFlagValue(1); val = reader.getBooleanFlagValue(1); if (val == disabledRw) { if (val == disabledRw) { Log.i(TAG, "success: disabledRw value matches"); Log.i(TAG, String.format(SUCCESS_LOG, "disabledRw")); } else { } else { Log.i(TAG, String.format( Log.i(TAG, String.format(MISMATCH_LOG, "disabledRw", val, disabledRw)); "error: disabledRw value mismatch, new storage value is %s, old storage value is %s", val, disabledRw)); } } catch (Exception e) { Log.e(TAG, "error: failed to read flag value of disabledRw", e); } } } disabledRwExported = properties.getBoolean(Flags.FLAG_DISABLED_RW_EXPORTED, false); if (readFromNewStorage && reader != null) { try { val = reader.getBooleanFlagValue(2); val = reader.getBooleanFlagValue(2); if (val == disabledRwExported) { if (val == disabledRwExported) { Log.i(TAG, "success: disabledRwExported value matches"); Log.i(TAG, String.format(SUCCESS_LOG, "disabledRwExported")); } else { } else { Log.i(TAG, String.format( Log.i(TAG, String.format(MISMATCH_LOG, "disabledRwExported", val, disabledRwExported)); "error: disabledRwExported value mismatch, new storage value is %s, old storage value is %s", val, disabledRwExported)); } } catch (Exception e) { Log.e(TAG, "error: failed to read flag value of disabledRwExported", e); } } } enabledRw = properties.getBoolean(Flags.FLAG_ENABLED_RW, true); if (readFromNewStorage && reader != null) { try { val = reader.getBooleanFlagValue(8); val = reader.getBooleanFlagValue(8); if (val == enabledRw) { if (val == enabledRw) { Log.i(TAG, "success: enabledRw value matches"); Log.i(TAG, String.format(SUCCESS_LOG, "enabledRw")); } else { } else { Log.i(TAG, String.format( Log.i(TAG, String.format(MISMATCH_LOG, "enabledRw", val, enabledRw)); "error: enabledRw value mismatch, new storage value is %s, old storage value is %s", val, enabledRw)); } } } catch (Exception e) { } catch (Exception e) { Log.e(TAG, "error: failed to read flag value of enabledRw", e); Log.e(TAG, ERROR_LOG, e); } } } } } 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 ); } aconfig_test_is_cached = true; } } private void load_overrides_other_namespace() { private void load_overrides_other_namespace() { try { try { boolean val; Properties properties = DeviceConfig.getProperties("other_namespace"); Properties properties = DeviceConfig.getProperties("other_namespace"); disabledRwInOtherNamespace = disabledRwInOtherNamespace = properties.getBoolean(Flags.FLAG_DISABLED_RW_IN_OTHER_NAMESPACE, false); properties.getBoolean(Flags.FLAG_DISABLED_RW_IN_OTHER_NAMESPACE, false); if (readFromNewStorage && reader != null) { try { val = reader.getBooleanFlagValue(3); if (val == disabledRwInOtherNamespace) { Log.i(TAG, "success: disabledRwInOtherNamespace value matches"); } else { Log.i(TAG, String.format( "error: disabledRwInOtherNamespace value mismatch, new storage value is %s, old storage value is %s", val, disabledRwInOtherNamespace)); } } catch (Exception e) { Log.e(TAG, "error: failed to read flag value of disabledRwInOtherNamespace", e); } } } catch (NullPointerException e) { } catch (NullPointerException e) { throw new RuntimeException( throw new RuntimeException( "Cannot read value from namespace other_namespace " "Cannot read value from namespace other_namespace " Loading @@ -810,6 +779,20 @@ mod tests { ); ); } } other_namespace_is_cached = true; other_namespace_is_cached = true; init(); if (readFromNewStorage && reader != null) { boolean val; try { val = reader.getBooleanFlagValue(3); if (val == disabledRwInOtherNamespace) { Log.i(TAG, String.format(SUCCESS_LOG, "disabledRwInOtherNamespace")); } else { Log.i(TAG, String.format(MISMATCH_LOG, "disabledRwInOtherNamespace", val, disabledRwInOtherNamespace)); } } catch (Exception e) { Log.e(TAG, ERROR_LOG, e); } } }"# + expected_featureflagsmpl_content_2; }"# + expected_featureflagsmpl_content_2; let mut file_set = HashMap::from([ let mut file_set = HashMap::from([ Loading tools/aconfig/aconfig/templates/FeatureFlagsImpl.java.template +30 −28 Original line number Original line Diff line number Diff line Loading @@ -14,8 +14,6 @@ import android.provider.DeviceConfig.Properties; {{ -if allow_instrumentation }} {{ -if allow_instrumentation }} import android.aconfig.storage.StorageInternalReader; import android.aconfig.storage.StorageInternalReader; import android.util.Log; import android.util.Log; import java.io.File; {{ -endif }} {{ -endif }} {{ -endif }} {{ -endif }} Loading @@ -38,10 +36,13 @@ public final class FeatureFlagsImpl implements FeatureFlags \{ boolean readFromNewStorage; boolean readFromNewStorage; private final static String TAG = "AconfigJavaCodegen"; private final static String TAG = "AconfigJavaCodegen"; private final static String SUCCESS_LOG = "success: %s value matches"; private final static String MISMATCH_LOG = "error: %s value mismatch, new storage value is %s, old storage value is %s"; private final static String ERROR_LOG = "error: failed to read flag value"; public FeatureFlagsImpl() \{ private void init() \{ File file = new File("/metadata/aconfig_test_missions/mission_1"); if (reader != null) return; if (file.exists()) \{ if (DeviceConfig.getBoolean("core_experiments_team_internal", "com.android.providers.settings.storage_test_mission_1", false)) \{ readFromNewStorage = true; readFromNewStorage = true; try \{ try \{ reader = new StorageInternalReader("{container}", "{package_name}"); reader = new StorageInternalReader("{container}", "{package_name}"); Loading @@ -50,39 +51,17 @@ public final class FeatureFlagsImpl implements FeatureFlags \{ } } } } } } {{ -endif }} {{ -endif }} {{ -endif }} {{ -endif }} {{ for namespace_with_flags in namespace_flags }} {{ for namespace_with_flags in namespace_flags }} private void load_overrides_{namespace_with_flags.namespace}() \{ private void load_overrides_{namespace_with_flags.namespace}() \{ try \{ try \{ {{ -if not library_exported }} {{ -if allow_instrumentation }} boolean val; {{ -endif }} {{ -endif }} Properties properties = DeviceConfig.getProperties("{namespace_with_flags.namespace}"); Properties properties = DeviceConfig.getProperties("{namespace_with_flags.namespace}"); {{ -for flag in namespace_with_flags.flags }} {{ -for flag in namespace_with_flags.flags }} {{ -if flag.is_read_write }} {{ -if flag.is_read_write }} {flag.method_name} = {flag.method_name} = properties.getBoolean(Flags.FLAG_{flag.flag_name_constant_suffix}, {flag.default_value}); properties.getBoolean(Flags.FLAG_{flag.flag_name_constant_suffix}, {flag.default_value}); {{ -if not library_exported }} {{ -if allow_instrumentation }} if (readFromNewStorage && reader != null) \{ try \{ val = reader.getBooleanFlagValue({flag.flag_offset}); if (val == {flag.method_name}) \{ Log.i(TAG, "success: {flag.method_name} value matches"); } else \{ Log.i(TAG, String.format( "error: {flag.method_name} value mismatch, new storage value is %s, old storage value is %s", val, {flag.method_name})); } } catch (Exception e) \{ Log.e(TAG, "error: failed to read flag value of {flag.method_name}", e); } } {{ -endif }} {{ -endif }} {{ -endif }} {{ -endif }} {{ -endfor }} {{ -endfor }} } catch (NullPointerException e) \{ } catch (NullPointerException e) \{ Loading @@ -96,6 +75,29 @@ public final class FeatureFlagsImpl implements FeatureFlags \{ ); ); } } {namespace_with_flags.namespace}_is_cached = true; {namespace_with_flags.namespace}_is_cached = true; {{ -if not library_exported }} {{ -if allow_instrumentation }} init(); if (readFromNewStorage && reader != null) \{ boolean val; try \{ {{ -for flag in namespace_with_flags.flags }} {{ -if flag.is_read_write }} val = reader.getBooleanFlagValue({flag.flag_offset}); if (val == {flag.method_name}) \{ Log.i(TAG, String.format(SUCCESS_LOG, "{flag.method_name}")); } else \{ Log.i(TAG, String.format(MISMATCH_LOG, "{flag.method_name}", val, {flag.method_name})); } {{ -endif }} {{ -endfor }} } catch (Exception e) \{ Log.e(TAG, ERROR_LOG, e); } } {{ -endif }} {{ -endif }} } } {{ endfor- }} {{ endfor- }} {{ -endif }}{#- end of runtime_lookup_required #} {{ -endif }}{#- end of runtime_lookup_required #} Loading Loading
tools/aconfig/aconfig/src/codegen/java.rs +46 −63 Original line number Original line Diff line number Diff line Loading @@ -46,7 +46,6 @@ where let runtime_lookup_required = let runtime_lookup_required = flag_elements.iter().any(|elem| elem.is_read_write) || library_exported; flag_elements.iter().any(|elem| elem.is_read_write) || library_exported; let container = (flag_elements.first().expect("zero template flags").container).to_string(); let container = (flag_elements.first().expect("zero template flags").container).to_string(); let context = Context { let context = Context { flag_elements, flag_elements, namespace_flags, namespace_flags, Loading Loading @@ -693,7 +692,6 @@ mod tests { + r#" + r#" import android.aconfig.storage.StorageInternalReader; import android.aconfig.storage.StorageInternalReader; import android.util.Log; import android.util.Log; import java.io.File; "# "# + expected_featureflagsmpl_content_1 + expected_featureflagsmpl_content_1 + r#" + r#" Loading @@ -701,10 +699,13 @@ mod tests { boolean readFromNewStorage; boolean readFromNewStorage; private final static String TAG = "AconfigJavaCodegen"; private final static String TAG = "AconfigJavaCodegen"; private final static String SUCCESS_LOG = "success: %s value matches"; private final static String MISMATCH_LOG = "error: %s value mismatch, new storage value is %s, old storage value is %s"; private final static String ERROR_LOG = "error: failed to read flag value"; public FeatureFlagsImpl() { private void init() { File file = new File("/metadata/aconfig_test_missions/mission_1"); if (reader != null) return; if (file.exists()) { if (DeviceConfig.getBoolean("core_experiments_team_internal", "com.android.providers.settings.storage_test_mission_1", false)) { readFromNewStorage = true; readFromNewStorage = true; try { try { reader = new StorageInternalReader("system", "com.android.aconfig.test"); reader = new StorageInternalReader("system", "com.android.aconfig.test"); Loading @@ -716,89 +717,57 @@ mod tests { private void load_overrides_aconfig_test() { private void load_overrides_aconfig_test() { try { try { boolean val; Properties properties = DeviceConfig.getProperties("aconfig_test"); Properties properties = DeviceConfig.getProperties("aconfig_test"); disabledRw = disabledRw = properties.getBoolean(Flags.FLAG_DISABLED_RW, false); 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 ); } aconfig_test_is_cached = true; init(); if (readFromNewStorage && reader != null) { if (readFromNewStorage && reader != null) { boolean val; try { try { val = reader.getBooleanFlagValue(1); val = reader.getBooleanFlagValue(1); if (val == disabledRw) { if (val == disabledRw) { Log.i(TAG, "success: disabledRw value matches"); Log.i(TAG, String.format(SUCCESS_LOG, "disabledRw")); } else { } else { Log.i(TAG, String.format( Log.i(TAG, String.format(MISMATCH_LOG, "disabledRw", val, disabledRw)); "error: disabledRw value mismatch, new storage value is %s, old storage value is %s", val, disabledRw)); } } catch (Exception e) { Log.e(TAG, "error: failed to read flag value of disabledRw", e); } } } disabledRwExported = properties.getBoolean(Flags.FLAG_DISABLED_RW_EXPORTED, false); if (readFromNewStorage && reader != null) { try { val = reader.getBooleanFlagValue(2); val = reader.getBooleanFlagValue(2); if (val == disabledRwExported) { if (val == disabledRwExported) { Log.i(TAG, "success: disabledRwExported value matches"); Log.i(TAG, String.format(SUCCESS_LOG, "disabledRwExported")); } else { } else { Log.i(TAG, String.format( Log.i(TAG, String.format(MISMATCH_LOG, "disabledRwExported", val, disabledRwExported)); "error: disabledRwExported value mismatch, new storage value is %s, old storage value is %s", val, disabledRwExported)); } } catch (Exception e) { Log.e(TAG, "error: failed to read flag value of disabledRwExported", e); } } } enabledRw = properties.getBoolean(Flags.FLAG_ENABLED_RW, true); if (readFromNewStorage && reader != null) { try { val = reader.getBooleanFlagValue(8); val = reader.getBooleanFlagValue(8); if (val == enabledRw) { if (val == enabledRw) { Log.i(TAG, "success: enabledRw value matches"); Log.i(TAG, String.format(SUCCESS_LOG, "enabledRw")); } else { } else { Log.i(TAG, String.format( Log.i(TAG, String.format(MISMATCH_LOG, "enabledRw", val, enabledRw)); "error: enabledRw value mismatch, new storage value is %s, old storage value is %s", val, enabledRw)); } } } catch (Exception e) { } catch (Exception e) { Log.e(TAG, "error: failed to read flag value of enabledRw", e); Log.e(TAG, ERROR_LOG, e); } } } } } 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 ); } aconfig_test_is_cached = true; } } private void load_overrides_other_namespace() { private void load_overrides_other_namespace() { try { try { boolean val; Properties properties = DeviceConfig.getProperties("other_namespace"); Properties properties = DeviceConfig.getProperties("other_namespace"); disabledRwInOtherNamespace = disabledRwInOtherNamespace = properties.getBoolean(Flags.FLAG_DISABLED_RW_IN_OTHER_NAMESPACE, false); properties.getBoolean(Flags.FLAG_DISABLED_RW_IN_OTHER_NAMESPACE, false); if (readFromNewStorage && reader != null) { try { val = reader.getBooleanFlagValue(3); if (val == disabledRwInOtherNamespace) { Log.i(TAG, "success: disabledRwInOtherNamespace value matches"); } else { Log.i(TAG, String.format( "error: disabledRwInOtherNamespace value mismatch, new storage value is %s, old storage value is %s", val, disabledRwInOtherNamespace)); } } catch (Exception e) { Log.e(TAG, "error: failed to read flag value of disabledRwInOtherNamespace", e); } } } catch (NullPointerException e) { } catch (NullPointerException e) { throw new RuntimeException( throw new RuntimeException( "Cannot read value from namespace other_namespace " "Cannot read value from namespace other_namespace " Loading @@ -810,6 +779,20 @@ mod tests { ); ); } } other_namespace_is_cached = true; other_namespace_is_cached = true; init(); if (readFromNewStorage && reader != null) { boolean val; try { val = reader.getBooleanFlagValue(3); if (val == disabledRwInOtherNamespace) { Log.i(TAG, String.format(SUCCESS_LOG, "disabledRwInOtherNamespace")); } else { Log.i(TAG, String.format(MISMATCH_LOG, "disabledRwInOtherNamespace", val, disabledRwInOtherNamespace)); } } catch (Exception e) { Log.e(TAG, ERROR_LOG, e); } } }"# + expected_featureflagsmpl_content_2; }"# + expected_featureflagsmpl_content_2; let mut file_set = HashMap::from([ let mut file_set = HashMap::from([ Loading
tools/aconfig/aconfig/templates/FeatureFlagsImpl.java.template +30 −28 Original line number Original line Diff line number Diff line Loading @@ -14,8 +14,6 @@ import android.provider.DeviceConfig.Properties; {{ -if allow_instrumentation }} {{ -if allow_instrumentation }} import android.aconfig.storage.StorageInternalReader; import android.aconfig.storage.StorageInternalReader; import android.util.Log; import android.util.Log; import java.io.File; {{ -endif }} {{ -endif }} {{ -endif }} {{ -endif }} Loading @@ -38,10 +36,13 @@ public final class FeatureFlagsImpl implements FeatureFlags \{ boolean readFromNewStorage; boolean readFromNewStorage; private final static String TAG = "AconfigJavaCodegen"; private final static String TAG = "AconfigJavaCodegen"; private final static String SUCCESS_LOG = "success: %s value matches"; private final static String MISMATCH_LOG = "error: %s value mismatch, new storage value is %s, old storage value is %s"; private final static String ERROR_LOG = "error: failed to read flag value"; public FeatureFlagsImpl() \{ private void init() \{ File file = new File("/metadata/aconfig_test_missions/mission_1"); if (reader != null) return; if (file.exists()) \{ if (DeviceConfig.getBoolean("core_experiments_team_internal", "com.android.providers.settings.storage_test_mission_1", false)) \{ readFromNewStorage = true; readFromNewStorage = true; try \{ try \{ reader = new StorageInternalReader("{container}", "{package_name}"); reader = new StorageInternalReader("{container}", "{package_name}"); Loading @@ -50,39 +51,17 @@ public final class FeatureFlagsImpl implements FeatureFlags \{ } } } } } } {{ -endif }} {{ -endif }} {{ -endif }} {{ -endif }} {{ for namespace_with_flags in namespace_flags }} {{ for namespace_with_flags in namespace_flags }} private void load_overrides_{namespace_with_flags.namespace}() \{ private void load_overrides_{namespace_with_flags.namespace}() \{ try \{ try \{ {{ -if not library_exported }} {{ -if allow_instrumentation }} boolean val; {{ -endif }} {{ -endif }} Properties properties = DeviceConfig.getProperties("{namespace_with_flags.namespace}"); Properties properties = DeviceConfig.getProperties("{namespace_with_flags.namespace}"); {{ -for flag in namespace_with_flags.flags }} {{ -for flag in namespace_with_flags.flags }} {{ -if flag.is_read_write }} {{ -if flag.is_read_write }} {flag.method_name} = {flag.method_name} = properties.getBoolean(Flags.FLAG_{flag.flag_name_constant_suffix}, {flag.default_value}); properties.getBoolean(Flags.FLAG_{flag.flag_name_constant_suffix}, {flag.default_value}); {{ -if not library_exported }} {{ -if allow_instrumentation }} if (readFromNewStorage && reader != null) \{ try \{ val = reader.getBooleanFlagValue({flag.flag_offset}); if (val == {flag.method_name}) \{ Log.i(TAG, "success: {flag.method_name} value matches"); } else \{ Log.i(TAG, String.format( "error: {flag.method_name} value mismatch, new storage value is %s, old storage value is %s", val, {flag.method_name})); } } catch (Exception e) \{ Log.e(TAG, "error: failed to read flag value of {flag.method_name}", e); } } {{ -endif }} {{ -endif }} {{ -endif }} {{ -endif }} {{ -endfor }} {{ -endfor }} } catch (NullPointerException e) \{ } catch (NullPointerException e) \{ Loading @@ -96,6 +75,29 @@ public final class FeatureFlagsImpl implements FeatureFlags \{ ); ); } } {namespace_with_flags.namespace}_is_cached = true; {namespace_with_flags.namespace}_is_cached = true; {{ -if not library_exported }} {{ -if allow_instrumentation }} init(); if (readFromNewStorage && reader != null) \{ boolean val; try \{ {{ -for flag in namespace_with_flags.flags }} {{ -if flag.is_read_write }} val = reader.getBooleanFlagValue({flag.flag_offset}); if (val == {flag.method_name}) \{ Log.i(TAG, String.format(SUCCESS_LOG, "{flag.method_name}")); } else \{ Log.i(TAG, String.format(MISMATCH_LOG, "{flag.method_name}", val, {flag.method_name})); } {{ -endif }} {{ -endfor }} } catch (Exception e) \{ Log.e(TAG, ERROR_LOG, e); } } {{ -endif }} {{ -endif }} } } {{ endfor- }} {{ endfor- }} {{ -endif }}{#- end of runtime_lookup_required #} {{ -endif }}{#- end of runtime_lookup_required #} Loading