aconfig: remove UnsupportedAppUsage from java exported mode

UnsupportedAppUsage was added to support cts test access issue. For new
exported mode, if the cts tests code with exported flag, there won't be access issue. So this annotation is not needed. Removing this annotation also removes the dependency on this annotation in google3 code.

Test: atest aconfig.test
Bug: 311152507
Bug: 303773055
Change-Id: I8c190e69cdb514af7992ccca7fea152c917047dc
This commit is contained in:
Zhi Dou 2024-03-11 03:57:24 +00:00
parent 39cfb1e9d2
commit 8837769f46
5 changed files with 33 additions and 79 deletions

View file

@ -351,6 +351,10 @@ mod tests {
}
return false;
}
@com.android.aconfig.annotations.AssumeTrueForR8
private boolean isOptimizationEnabled() {
return false;
}
private boolean getValue(String flagName) {
Boolean value = this.mFlagMap.get(flagName);
if (value == null) {
@ -358,10 +362,6 @@ mod tests {
}
return value;
}
@com.android.aconfig.annotations.AssumeTrueForR8
private boolean isOptimizationEnabled() {
return false;
}
private Map<String, Boolean> mFlagMap = new HashMap<>(
Map.ofEntries(
Map.entry(Flags.FLAG_DISABLED_RO, false),
@ -558,8 +558,6 @@ mod tests {
let expect_flags_content = r#"
package com.android.aconfig.test;
// TODO(b/303773055): Remove the annotation after access issue is resolved.
import android.compat.annotation.UnsupportedAppUsage;
/** @hide */
public final class Flags {
/** @hide */
@ -569,15 +567,12 @@ mod tests {
/** @hide */
public static final String FLAG_ENABLED_RO_EXPORTED = "com.android.aconfig.test.enabled_ro_exported";
@UnsupportedAppUsage
public static boolean disabledRwExported() {
return FEATURE_FLAGS.disabledRwExported();
}
@UnsupportedAppUsage
public static boolean enabledFixedRoExported() {
return FEATURE_FLAGS.enabledFixedRoExported();
}
@UnsupportedAppUsage
public static boolean enabledRoExported() {
return FEATURE_FLAGS.enabledRoExported();
}
@ -587,23 +582,16 @@ mod tests {
let expect_feature_flags_content = r#"
package com.android.aconfig.test;
// TODO(b/303773055): Remove the annotation after access issue is resolved.
import android.compat.annotation.UnsupportedAppUsage;
/** @hide */
public interface FeatureFlags {
@UnsupportedAppUsage
boolean disabledRwExported();
@UnsupportedAppUsage
boolean enabledFixedRoExported();
@UnsupportedAppUsage
boolean enabledRoExported();
}
"#;
let expect_feature_flags_impl_content = r#"
package com.android.aconfig.test;
// TODO(b/303773055): Remove the annotation after access issue is resolved.
import android.compat.annotation.UnsupportedAppUsage;
import android.provider.DeviceConfig;
import android.provider.DeviceConfig.Properties;
/** @hide */
@ -637,7 +625,6 @@ mod tests {
}
@Override
@UnsupportedAppUsage
public boolean disabledRwExported() {
if (!aconfig_test_is_cached) {
load_overrides_aconfig_test();
@ -646,7 +633,6 @@ mod tests {
}
@Override
@UnsupportedAppUsage
public boolean enabledFixedRoExported() {
if (!aconfig_test_is_cached) {
load_overrides_aconfig_test();
@ -655,7 +641,6 @@ mod tests {
}
@Override
@UnsupportedAppUsage
public boolean enabledRoExported() {
if (!aconfig_test_is_cached) {
load_overrides_aconfig_test();
@ -666,8 +651,6 @@ mod tests {
let expect_fake_feature_flags_impl_content = r#"
package com.android.aconfig.test;
// TODO(b/303773055): Remove the annotation after access issue is resolved.
import android.compat.annotation.UnsupportedAppUsage;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
@ -679,17 +662,14 @@ mod tests {
resetAll();
}
@Override
@UnsupportedAppUsage
public boolean disabledRwExported() {
return getValue(Flags.FLAG_DISABLED_RW_EXPORTED);
}
@Override
@UnsupportedAppUsage
public boolean enabledFixedRoExported() {
return getValue(Flags.FLAG_ENABLED_FIXED_RO_EXPORTED);
}
@Override
@UnsupportedAppUsage
public boolean enabledRoExported() {
return getValue(Flags.FLAG_ENABLED_RO_EXPORTED);
}
@ -704,13 +684,6 @@ mod tests {
entry.setValue(null);
}
}
public boolean isFlagReadOnlyOptimized(String flagName) {
if (mReadOnlyFlagsSet.contains(flagName) &&
isOptimizationEnabled()) {
return true;
}
return false;
}
private boolean getValue(String flagName) {
Boolean value = this.mFlagMap.get(flagName);
if (value == null) {
@ -718,10 +691,6 @@ mod tests {
}
return value;
}
@com.android.aconfig.annotations.AssumeTrueForR8
private boolean isOptimizationEnabled() {
return false;
}
private Map<String, Boolean> mFlagMap = new HashMap<>(
Map.ofEntries(
Map.entry(Flags.FLAG_DISABLED_RW_EXPORTED, false),
@ -1065,6 +1034,10 @@ mod tests {
}
return false;
}
@com.android.aconfig.annotations.AssumeTrueForR8
private boolean isOptimizationEnabled() {
return false;
}
private boolean getValue(String flagName) {
Boolean value = this.mFlagMap.get(flagName);
if (value == null) {
@ -1072,10 +1045,6 @@ mod tests {
}
return value;
}
@com.android.aconfig.annotations.AssumeTrueForR8
private boolean isOptimizationEnabled() {
return false;
}
private Map<String, Boolean> mFlagMap = new HashMap<>(
Map.ofEntries(
Map.entry(Flags.FLAG_DISABLED_RO, false),

View file

@ -1,7 +1,8 @@
package {package_name};
{{ if not library_exported- }}
// TODO(b/303773055): Remove the annotation after access issue is resolved.
import android.compat.annotation.UnsupportedAppUsage;
{{ -endif }}
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
@ -16,7 +17,7 @@ public class FakeFeatureFlagsImpl implements FeatureFlags \{
{{ for item in flag_elements}}
@Override
@UnsupportedAppUsage
{{ if not library_exported }} @UnsupportedAppUsage{{ -endif }}
public boolean {item.method_name}() \{
return getValue(Flags.FLAG_{item.flag_name_constant_suffix});
}
@ -33,7 +34,7 @@ public class FakeFeatureFlagsImpl implements FeatureFlags \{
entry.setValue(null);
}
}
{{ if not library_exported }}
public boolean isFlagReadOnlyOptimized(String flagName) \{
if (mReadOnlyFlagsSet.contains(flagName) &&
isOptimizationEnabled()) \{
@ -42,6 +43,11 @@ public class FakeFeatureFlagsImpl implements FeatureFlags \{
return false;
}
@com.android.aconfig.annotations.AssumeTrueForR8
private boolean isOptimizationEnabled() \{
return false;
}
{{ -endif }}
private boolean getValue(String flagName) \{
Boolean value = this.mFlagMap.get(flagName);
if (value == null) \{
@ -50,10 +56,6 @@ public class FakeFeatureFlagsImpl implements FeatureFlags \{
return value;
}
@com.android.aconfig.annotations.AssumeTrueForR8
private boolean isOptimizationEnabled() \{
return false;
}
private Map<String, Boolean> mFlagMap = new HashMap<>(
Map.ofEntries(

View file

@ -1,23 +1,21 @@
package {package_name};
{{ if not library_exported- }}
// TODO(b/303773055): Remove the annotation after access issue is resolved.
import android.compat.annotation.UnsupportedAppUsage;
{{ -endif }}
/** @hide */
public interface FeatureFlags \{
{{ for item in flag_elements }}
{{ -if library_exported }}
@UnsupportedAppUsage
boolean {item.method_name}();
{{ -else }}
{{ -if not item.is_read_write }}
{{ -if item.default_value }}
@com.android.aconfig.annotations.AssumeTrueForR8
{{ -else }}
@com.android.aconfig.annotations.AssumeFalseForR8
{{ -endif- }}
{{ endif }}
{{ -endif }}
{{ -if not library_exported }}
@UnsupportedAppUsage
{{ -endif }}
boolean {item.method_name}();
{{ endif }}
{{ -endfor }}
}
}

View file

@ -1,6 +1,8 @@
package {package_name};
{{ if not library_exported- }}
// TODO(b/303773055): Remove the annotation after access issue is resolved.
import android.compat.annotation.UnsupportedAppUsage;
{{ -endif }}
{{ -if not is_test_mode }}
{{ -if runtime_lookup_required }}
import android.provider.DeviceConfig;
@ -14,12 +16,8 @@ public final class FeatureFlagsImpl implements FeatureFlags \{
{{ -endfor- }}
{{ for flag in flag_elements }}
{{ -if library_exported }}
private static boolean {flag.method_name} = false;
{{ -else }}
{{- if flag.is_read_write }}
private static boolean {flag.method_name} = {flag.default_value};
{{- endif- }}
{{ -endif }}
{{ -endfor }}
{{ for namespace_with_flags in namespace_flags }}
@ -27,15 +25,10 @@ public final class FeatureFlagsImpl implements FeatureFlags \{
try \{
Properties properties = DeviceConfig.getProperties("{namespace_with_flags.namespace}");
{{ -for flag in namespace_with_flags.flags }}
{{ -if library_exported }}
{flag.method_name} =
properties.getBoolean("{flag.device_config_flag}", false);
{{ -else }}
{{ -if flag.is_read_write }}
{flag.method_name} =
properties.getBoolean("{flag.device_config_flag}", {flag.default_value});
{{ -endif }}
{{ -endif }}
{{ -endfor }}
} catch (NullPointerException e) \{
throw new RuntimeException(
@ -53,14 +46,10 @@ public final class FeatureFlagsImpl implements FeatureFlags \{
{{ -endif }}{#- end of runtime_lookup_required #}
{{ -for flag in flag_elements }}
@Override
{{ -if not library_exported }}
@UnsupportedAppUsage
{{ -endif }}
public boolean {flag.method_name}() \{
{{ -if library_exported }}
if (!{flag.device_config_namespace}_is_cached) \{
load_overrides_{flag.device_config_namespace}();
}
return {flag.method_name};
{{ -else }}
{{ -if flag.is_read_write }}
if (!{flag.device_config_namespace}_is_cached) \{
load_overrides_{flag.device_config_namespace}();
@ -68,7 +57,6 @@ public final class FeatureFlagsImpl implements FeatureFlags \{
return {flag.method_name};
{{ -else }}
return {flag.default_value};
{{ -endif- }}
{{ -endif }}
}
{{ endfor }}
@ -79,7 +67,9 @@ public final class FeatureFlagsImpl implements FeatureFlags \{
public final class FeatureFlagsImpl implements FeatureFlags \{
{{ for flag in flag_elements }}
@Override
{{ -if not library_exported }}
@UnsupportedAppUsage
{{ -endif }}
public boolean {flag.method_name}() \{
throw new UnsupportedOperationException(
"Method is not implemented.");

View file

@ -1,8 +1,8 @@
package {package_name};
{{ if not library_exported- }}
// TODO(b/303773055): Remove the annotation after access issue is resolved.
import android.compat.annotation.UnsupportedAppUsage;
{{ -endif }}
/** @hide */
public final class Flags \{
{{ -for item in flag_elements}}
@ -10,12 +10,6 @@ public final class Flags \{
public static final String FLAG_{item.flag_name_constant_suffix} = "{item.device_config_flag}";
{{- endfor }}
{{ -for item in flag_elements}}
{{ if library_exported }}
@UnsupportedAppUsage
public static boolean {item.method_name}() \{
return FEATURE_FLAGS.{item.method_name}();
}
{{ -else }}
{{ -if not item.is_read_write }}
{{ -if item.default_value }}
@com.android.aconfig.annotations.AssumeTrueForR8
@ -23,11 +17,12 @@ public final class Flags \{
@com.android.aconfig.annotations.AssumeFalseForR8
{{ -endif }}
{{ -endif }}
{{ -if not library_exported }}
@UnsupportedAppUsage
{{ -endif }}
public static boolean {item.method_name}() \{
return FEATURE_FLAGS.{item.method_name}();
}
{{ -endif }}
{{ -endfor }}
{{ -if is_test_mode }}
public static void setFeatureFlags(FeatureFlags featureFlags) \{