only use new storage for read write

Test: atest aconfig.test.java
Bug: 349874828
Change-Id: I5af9fa6243b8b8a157f03242e6e5a411ced7be44
This commit is contained in:
Zhi Dou
2024-07-19 20:37:53 +00:00
parent ca4c83efa3
commit 1edd4485c6
2 changed files with 18 additions and 6 deletions

View File

@@ -677,7 +677,7 @@ mod tests {
modified_parsed_flags.into_iter(), modified_parsed_flags.into_iter(),
mode, mode,
flag_ids, flag_ids,
false, true,
) )
.unwrap(); .unwrap();
@@ -870,7 +870,7 @@ mod tests {
modified_parsed_flags.into_iter(), modified_parsed_flags.into_iter(),
mode, mode,
flag_ids, flag_ids,
false, true,
) )
.unwrap(); .unwrap();
@@ -991,7 +991,7 @@ mod tests {
modified_parsed_flags.into_iter(), modified_parsed_flags.into_iter(),
mode, mode,
flag_ids, flag_ids,
false, true,
) )
.unwrap(); .unwrap();
let expect_featureflags_content = r#" let expect_featureflags_content = r#"

View File

@@ -10,12 +10,14 @@ import android.provider.DeviceConfig;
import android.provider.DeviceConfig.Properties; import android.provider.DeviceConfig.Properties;
{{ -if not library_exported }}
{{ -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; import java.io.File;
{{ -endif }} {{ -endif }}
{{ -endif }}
{{ -endif }} {{ -endif }}
/** @hide */ /** @hide */
@@ -30,6 +32,7 @@ public final class FeatureFlagsImpl implements FeatureFlags \{
private static boolean {flag.method_name} = {flag.default_value}; private static boolean {flag.method_name} = {flag.default_value};
{{ -endif }} {{ -endif }}
{{ -endfor }} {{ -endfor }}
{{ -if not library_exported }}
{{ -if allow_instrumentation }} {{ -if allow_instrumentation }}
StorageInternalReader reader; StorageInternalReader reader;
boolean readFromNewStorage; boolean readFromNewStorage;
@@ -40,23 +43,31 @@ public final class FeatureFlagsImpl implements FeatureFlags \{
File file = new File("/metadata/aconfig_test_missions/mission_1"); File file = new File("/metadata/aconfig_test_missions/mission_1");
if (file.exists()) \{ if (file.exists()) \{
readFromNewStorage = true; readFromNewStorage = true;
try \{
reader = new StorageInternalReader("{container}", "{package_name}"); reader = new StorageInternalReader("{container}", "{package_name}");
} catch(Exception e) \{
reader = null;
} }
} }
}
{{ -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 }} {{ -if allow_instrumentation }}
boolean val; boolean val;
{{ -endif }}
{{ -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 allow_instrumentation }}
if (readFromNewStorage) \{ if (readFromNewStorage && reader != null) \{
try \{ try \{
val = reader.getBooleanFlagValue({flag.flag_offset}); val = reader.getBooleanFlagValue({flag.flag_offset});
if (val == {flag.method_name}) \{ if (val == {flag.method_name}) \{
@@ -67,11 +78,12 @@ public final class FeatureFlagsImpl implements FeatureFlags \{
val, {flag.method_name})); val, {flag.method_name}));
} }
} catch (Exception e) \{ } catch (Exception e) \{
Log.e(TAG,"error: failed to read flag value of {flag.method_name}"); Log.e(TAG,"error: failed to read flag value of {flag.method_name}", e);
} }
} }
{{ -endif }} {{ -endif }}
{{ -endif }} {{ -endif }}
{{ -endif }}
{{ -endfor }} {{ -endfor }}
} catch (NullPointerException e) \{ } catch (NullPointerException e) \{
throw new RuntimeException( throw new RuntimeException(