Change control semantics in transcode settings

Change global transcode enable toggle preference to global disable
toggle preference. Change app slection for skipping transcode to
app selection for enabling transcode, by default transcoding would be
disabled for all apps.

Test: Manual, Roboelectric unit tests
Change-Id: I44f4d1b24fac70a4560e8b3a12d505bd2da26f20
This commit is contained in:
Biswarup Pal
2020-11-15 13:49:29 +00:00
parent 5816d414db
commit ab51e8ff38
5 changed files with 41 additions and 41 deletions

View File

@@ -51,24 +51,24 @@ import org.robolectric.shadows.ShadowPackageManager;
import java.util.Collections;
@RunWith(RobolectricTestRunner.class)
public class TranscodeSkipAppsPreferenceControllerTest {
public class TranscodeAppsPreferenceControllerTest {
private static final int APPLICATION_UID = 1234;
private static final String SKIP_SELECTED_APPS_PROP_KEY =
"persist.sys.fuse.transcode_skip_uids";
private static final String TRANSCODE_SELECTED_APPS_PROP_KEY =
"persist.sys.fuse.transcode_uids";
@Mock
private PreferenceScreen mScreen;
private Context mContext;
private ShadowPackageManager mShadowPackageManager;
private TranscodeSkipAppsPreferenceController mController;
private TranscodeAppsPreferenceController mController;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = ApplicationProvider.getApplicationContext();
mShadowPackageManager = Shadows.shadowOf(mContext.getPackageManager());
mController = new TranscodeSkipAppsPreferenceController(mContext, "test_key");
mController = new TranscodeAppsPreferenceController(mContext, "test_key");
Preference preference = new Preference(mContext);
when(mScreen.getContext()).thenReturn(mContext);
@@ -99,28 +99,28 @@ public class TranscodeSkipAppsPreferenceControllerTest {
}
@Test
public void preferenceChecked_shouldSkipApp() {
// First ensure that the app is not in skip list.
SystemProperties.set(SKIP_SELECTED_APPS_PROP_KEY, String.valueOf(-1));
public void preferenceChecked_shouldSelectApp() {
// First ensure that the app is not selected.
SystemProperties.set(TRANSCODE_SELECTED_APPS_PROP_KEY, String.valueOf(-1));
SwitchPreference switchPreference = createPreference(/* defaultCheckedState = */ false);
switchPreference.performClick();
// Verify that the app is added to skip list.
assertThat(SystemProperties.get(SKIP_SELECTED_APPS_PROP_KEY)).contains(
// Verify that the app is selected.
assertThat(SystemProperties.get(TRANSCODE_SELECTED_APPS_PROP_KEY)).contains(
String.valueOf(APPLICATION_UID));
}
@Test
public void preferenceUnchecked_shouldNotSkipApp() {
// First ensure that the app is in skip list.
SystemProperties.set(SKIP_SELECTED_APPS_PROP_KEY, String.valueOf(APPLICATION_UID));
public void preferenceUnchecked_shouldUnSelectApp() {
// First ensure that the app is selected.
SystemProperties.set(TRANSCODE_SELECTED_APPS_PROP_KEY, String.valueOf(APPLICATION_UID));
SwitchPreference switchPreference = createPreference(/* defaultCheckedState = */ true);
switchPreference.performClick();
// Verify that the app is removed from skip list.
assertThat(SystemProperties.get(SKIP_SELECTED_APPS_PROP_KEY)).doesNotContain(
// Verify that the app is not selected.
assertThat(SystemProperties.get(TRANSCODE_SELECTED_APPS_PROP_KEY)).doesNotContain(
String.valueOf(APPLICATION_UID));
}

View File

@@ -47,14 +47,14 @@ public class TranscodeGlobalTogglePreferenceControllerTest {
}
@Test
public void isChecked_whenEnabled_shouldReturnTrue() {
SystemProperties.set(TRANSCODE_ENABLED_PROP_KEY, "true");
public void isChecked_whenDisabled_shouldReturnTrue() {
SystemProperties.set(TRANSCODE_ENABLED_PROP_KEY, "false");
assertThat(mController.isChecked()).isTrue();
}
@Test
public void isChecked_whenDisabled_shouldReturnTrue() {
SystemProperties.set(TRANSCODE_ENABLED_PROP_KEY, "false");
public void isChecked_whenEnabled_shouldReturnFalse() {
SystemProperties.set(TRANSCODE_ENABLED_PROP_KEY, "true");
assertThat(mController.isChecked()).isFalse();
}
@@ -63,8 +63,8 @@ public class TranscodeGlobalTogglePreferenceControllerTest {
// Simulate the UI being clicked.
mController.setChecked(true);
// Verify the system property was updated with the UI value.
assertThat(SystemProperties.getBoolean(TRANSCODE_ENABLED_PROP_KEY, false)).isTrue();
// Verify the system property was updated.
assertThat(SystemProperties.getBoolean(TRANSCODE_ENABLED_PROP_KEY, true)).isFalse();
}
@Test
@@ -72,7 +72,7 @@ public class TranscodeGlobalTogglePreferenceControllerTest {
// Simulate the UI being clicked.
mController.setChecked(false);
// Verify the system property was updated with the UI value.
assertThat(SystemProperties.getBoolean(TRANSCODE_ENABLED_PROP_KEY, true)).isFalse();
// Verify the system property was updated.
assertThat(SystemProperties.getBoolean(TRANSCODE_ENABLED_PROP_KEY, false)).isTrue();
}
}