Merge "Don't cache simple BooleanFlags." into tm-dev
This commit is contained in:
@@ -31,6 +31,7 @@ import com.android.systemui.dump.DumpManager;
|
|||||||
|
|
||||||
import java.io.FileDescriptor;
|
import java.io.FileDescriptor;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
@@ -65,7 +66,7 @@ public class FeatureFlagsRelease implements FeatureFlags, Dumpable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isEnabled(BooleanFlag flag) {
|
public boolean isEnabled(BooleanFlag flag) {
|
||||||
return isEnabled(flag.getId(), flag.getDefault());
|
return flag.getDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -120,10 +121,24 @@ public class FeatureFlagsRelease implements FeatureFlags, Dumpable {
|
|||||||
@Override
|
@Override
|
||||||
public void dump(@NonNull FileDescriptor fd, @NonNull PrintWriter pw, @NonNull String[] args) {
|
public void dump(@NonNull FileDescriptor fd, @NonNull PrintWriter pw, @NonNull String[] args) {
|
||||||
pw.println("can override: false");
|
pw.println("can override: false");
|
||||||
int numBooleans = mBooleanCache.size();
|
Map<Integer, Flag<?>> knownFlags = Flags.collectFlags();
|
||||||
pw.println("booleans: " + numBooleans);
|
for (Map.Entry<Integer, Flag<?>> idToFlag : knownFlags.entrySet()) {
|
||||||
for (int i = 0; i < numBooleans; i++) {
|
int id = idToFlag.getKey();
|
||||||
pw.println(" sysui_flag_" + mBooleanCache.keyAt(i) + ": " + mBooleanCache.valueAt(i));
|
Flag<?> flag = idToFlag.getValue();
|
||||||
|
boolean def = false;
|
||||||
|
if (mBooleanCache.indexOfKey(flag.getId()) < 0) {
|
||||||
|
if (flag instanceof SysPropBooleanFlag) {
|
||||||
|
SysPropBooleanFlag f = (SysPropBooleanFlag) flag;
|
||||||
|
def = mSystemProperties.getBoolean(f.getName(), f.getDefault());
|
||||||
|
} else if (flag instanceof ResourceBooleanFlag) {
|
||||||
|
ResourceBooleanFlag f = (ResourceBooleanFlag) flag;
|
||||||
|
def = mResources.getBoolean(f.getResourceId());
|
||||||
|
} else if (flag instanceof BooleanFlag) {
|
||||||
|
BooleanFlag f = (BooleanFlag) flag;
|
||||||
|
def = f.getDefault();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pw.println(" sysui_flag_" + id + ": " + (mBooleanCache.get(id, def)));
|
||||||
}
|
}
|
||||||
int numStrings = mStringCache.size();
|
int numStrings = mStringCache.size();
|
||||||
pw.println("Strings: " + numStrings);
|
pw.println("Strings: " + numStrings);
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ import android.test.suitebuilder.annotation.SmallTest
|
|||||||
import com.android.systemui.SysuiTestCase
|
import com.android.systemui.SysuiTestCase
|
||||||
import com.android.systemui.dump.DumpManager
|
import com.android.systemui.dump.DumpManager
|
||||||
import com.android.systemui.util.mockito.any
|
import com.android.systemui.util.mockito.any
|
||||||
import com.android.systemui.util.mockito.mock
|
|
||||||
import com.google.common.truth.Truth.assertThat
|
import com.google.common.truth.Truth.assertThat
|
||||||
import org.junit.After
|
import org.junit.After
|
||||||
import org.junit.Assert.assertThrows
|
import org.junit.Assert.assertThrows
|
||||||
@@ -31,8 +30,6 @@ import org.mockito.Mock
|
|||||||
import org.mockito.Mockito.verify
|
import org.mockito.Mockito.verify
|
||||||
import org.mockito.Mockito.verifyNoMoreInteractions
|
import org.mockito.Mockito.verifyNoMoreInteractions
|
||||||
import org.mockito.MockitoAnnotations
|
import org.mockito.MockitoAnnotations
|
||||||
import java.io.PrintWriter
|
|
||||||
import java.io.StringWriter
|
|
||||||
import org.mockito.Mockito.`when` as whenever
|
import org.mockito.Mockito.`when` as whenever
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -97,43 +94,4 @@ class FeatureFlagsReleaseTest : SysuiTestCase() {
|
|||||||
whenever(mSystemProperties.getBoolean(flagName, flagDefault)).thenReturn(flagDefault)
|
whenever(mSystemProperties.getBoolean(flagName, flagDefault)).thenReturn(flagDefault)
|
||||||
assertThat(mFeatureFlagsRelease.isEnabled(flag)).isEqualTo(flagDefault)
|
assertThat(mFeatureFlagsRelease.isEnabled(flag)).isEqualTo(flagDefault)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
fun testDump() {
|
|
||||||
val flag1 = BooleanFlag(1, true)
|
|
||||||
val flag2 = ResourceBooleanFlag(2, 1002)
|
|
||||||
val flag3 = BooleanFlag(3, false)
|
|
||||||
val flag4 = StringFlag(4, "")
|
|
||||||
val flag5 = StringFlag(5, "flag5default")
|
|
||||||
val flag6 = ResourceStringFlag(6, 1006)
|
|
||||||
|
|
||||||
whenever(mResources.getBoolean(1002)).thenReturn(true)
|
|
||||||
whenever(mResources.getString(1006)).thenReturn("resource1006")
|
|
||||||
whenever(mResources.getString(1007)).thenReturn("resource1007")
|
|
||||||
|
|
||||||
// WHEN the flags have been accessed
|
|
||||||
assertThat(mFeatureFlagsRelease.isEnabled(flag1)).isTrue()
|
|
||||||
assertThat(mFeatureFlagsRelease.isEnabled(flag2)).isTrue()
|
|
||||||
assertThat(mFeatureFlagsRelease.isEnabled(flag3)).isFalse()
|
|
||||||
assertThat(mFeatureFlagsRelease.getString(flag4)).isEmpty()
|
|
||||||
assertThat(mFeatureFlagsRelease.getString(flag5)).isEqualTo("flag5default")
|
|
||||||
assertThat(mFeatureFlagsRelease.getString(flag6)).isEqualTo("resource1006")
|
|
||||||
|
|
||||||
// THEN the dump contains the flags and the default values
|
|
||||||
val dump = dumpToString()
|
|
||||||
assertThat(dump).contains(" sysui_flag_1: true\n")
|
|
||||||
assertThat(dump).contains(" sysui_flag_2: true\n")
|
|
||||||
assertThat(dump).contains(" sysui_flag_3: false\n")
|
|
||||||
assertThat(dump).contains(" sysui_flag_4: [length=0] \"\"\n")
|
|
||||||
assertThat(dump).contains(" sysui_flag_5: [length=12] \"flag5default\"\n")
|
|
||||||
assertThat(dump).contains(" sysui_flag_6: [length=12] \"resource1006\"\n")
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun dumpToString(): String {
|
|
||||||
val sw = StringWriter()
|
|
||||||
val pw = PrintWriter(sw)
|
|
||||||
mFeatureFlagsRelease.dump(mock(), pw, emptyArray())
|
|
||||||
pw.flush()
|
|
||||||
return sw.toString()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user