aconfig: add isOptimizationEnabled in FakeFeatureFlagsImpl
This change adds isOptimizationEnabled method in FakeFeatureFlagsImpl. This method can help test to decide whether the code using flag is optimized. Bug: 309406391 Test: atest aconfig.test aconfig.test.java Change-Id: I7e7109ac06ab44f9b8dee56c76be9479f60a9148
This commit is contained in:
@@ -278,8 +278,11 @@ mod tests {
|
||||
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;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
/** @hide */
|
||||
public class FakeFeatureFlagsImpl implements FeatureFlags {
|
||||
public FakeFeatureFlagsImpl() {
|
||||
@@ -341,6 +344,13 @@ 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) {
|
||||
@@ -348,6 +358,10 @@ 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),
|
||||
@@ -361,6 +375,16 @@ mod tests {
|
||||
Map.entry(Flags.FLAG_ENABLED_RW, false)
|
||||
)
|
||||
);
|
||||
private Set<String> mReadOnlyFlagsSet = new HashSet<>(
|
||||
Arrays.asList(
|
||||
Flags.FLAG_DISABLED_RO,
|
||||
Flags.FLAG_ENABLED_FIXED_RO,
|
||||
Flags.FLAG_ENABLED_FIXED_RO_EXPORTED,
|
||||
Flags.FLAG_ENABLED_RO,
|
||||
Flags.FLAG_ENABLED_RO_EXPORTED,
|
||||
""
|
||||
)
|
||||
);
|
||||
}
|
||||
"#;
|
||||
|
||||
@@ -644,8 +668,11 @@ mod tests {
|
||||
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;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
/** @hide */
|
||||
public class FakeFeatureFlagsImpl implements FeatureFlags {
|
||||
public FakeFeatureFlagsImpl() {
|
||||
@@ -677,6 +704,13 @@ 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) {
|
||||
@@ -684,6 +718,10 @@ 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),
|
||||
@@ -691,6 +729,11 @@ mod tests {
|
||||
Map.entry(Flags.FLAG_ENABLED_RO_EXPORTED, false)
|
||||
)
|
||||
);
|
||||
private Set<String> mReadOnlyFlagsSet = new HashSet<>(
|
||||
Arrays.asList(
|
||||
""
|
||||
)
|
||||
);
|
||||
}
|
||||
"#;
|
||||
|
||||
@@ -964,8 +1007,11 @@ mod tests {
|
||||
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;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
/** @hide */
|
||||
public class FakeFeatureFlagsImpl implements FeatureFlags {
|
||||
public FakeFeatureFlagsImpl() {
|
||||
@@ -1012,6 +1058,13 @@ 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) {
|
||||
@@ -1019,6 +1072,10 @@ 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),
|
||||
@@ -1029,6 +1086,17 @@ mod tests {
|
||||
Map.entry(Flags.FLAG_ENABLED_RW, false)
|
||||
)
|
||||
);
|
||||
private Set<String> mReadOnlyFlagsSet = new HashSet<>(
|
||||
Arrays.asList(
|
||||
Flags.FLAG_DISABLED_RO,
|
||||
Flags.FLAG_DISABLED_RW,
|
||||
Flags.FLAG_DISABLED_RW_IN_OTHER_NAMESPACE,
|
||||
Flags.FLAG_ENABLED_FIXED_RO,
|
||||
Flags.FLAG_ENABLED_RO,
|
||||
Flags.FLAG_ENABLED_RW,
|
||||
""
|
||||
)
|
||||
);
|
||||
}
|
||||
"#;
|
||||
let mut file_set = HashMap::from([
|
||||
|
@@ -2,8 +2,11 @@ package {package_name};
|
||||
// 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;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/** @hide */
|
||||
public class FakeFeatureFlagsImpl implements FeatureFlags \{
|
||||
@@ -31,6 +34,14 @@ public class FakeFeatureFlagsImpl implements FeatureFlags \{
|
||||
}
|
||||
}
|
||||
|
||||
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) \{
|
||||
@@ -39,12 +50,28 @@ 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(
|
||||
{{-for item in flag_elements}}
|
||||
{{ -for item in flag_elements }}
|
||||
Map.entry(Flags.FLAG_{item.flag_name_constant_suffix}, false)
|
||||
{{ -if not @last }},{{ endif }}
|
||||
{{ -endfor }}
|
||||
)
|
||||
);
|
||||
|
||||
private Set<String> mReadOnlyFlagsSet = new HashSet<>(
|
||||
Arrays.asList(
|
||||
{{ -for item in flag_elements }}
|
||||
{{ -if not item.is_read_write }}
|
||||
Flags.FLAG_{item.flag_name_constant_suffix},
|
||||
{{ -endif }}
|
||||
{{ -endfor }}
|
||||
""{# The empty string here is to resolve the ending comma #}
|
||||
)
|
||||
);
|
||||
}
|
||||
|
Reference in New Issue
Block a user