Game Driver: Fix EnableForAllApps switch and test
Bug: 123707483 Bug: 119221883 Test: Build, flash, boot and make RunSettingsRoboTests Change-Id: Iffbe3355b37763d4fa71b96271c1ba448fb6cdc5
This commit is contained in:
@@ -74,6 +74,7 @@ public class GameDriverEnableForAllAppsPreferenceController extends BasePreferen
|
||||
public void displayPreference(PreferenceScreen screen) {
|
||||
super.displayPreference(screen);
|
||||
mPreference = screen.findPreference(getPreferenceKey());
|
||||
mPreference.setOnPreferenceChangeListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -98,8 +99,20 @@ public class GameDriverEnableForAllAppsPreferenceController extends BasePreferen
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
final boolean isChecked = (boolean) newValue;
|
||||
final int gameDriver = Settings.Global.getInt(
|
||||
mContentResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_DEFAULT);
|
||||
|
||||
if (isChecked && gameDriver == GAME_DRIVER_ALL_APPS) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!isChecked && (gameDriver == GAME_DRIVER_DEFAULT || gameDriver == GAME_DRIVER_OFF)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Settings.Global.putInt(mContentResolver, Settings.Global.GAME_DRIVER_ALL_APPS,
|
||||
(boolean) newValue ? GAME_DRIVER_ALL_APPS : GAME_DRIVER_DEFAULT);
|
||||
isChecked ? GAME_DRIVER_ALL_APPS : GAME_DRIVER_DEFAULT);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@@ -79,19 +79,21 @@ public class GameDriverGlobalSwitchBarController
|
||||
|
||||
@Override
|
||||
public boolean onSwitchToggled(boolean isChecked) {
|
||||
if (!isChecked) {
|
||||
Settings.Global.putInt(
|
||||
mContentResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_OFF);
|
||||
final int gameDriver = Settings.Global.getInt(
|
||||
mContentResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_DEFAULT);
|
||||
|
||||
if (isChecked
|
||||
&& (gameDriver == GAME_DRIVER_DEFAULT || gameDriver == GAME_DRIVER_ALL_APPS)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (Settings.Global.getInt(
|
||||
mContentResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_DEFAULT)
|
||||
!= GAME_DRIVER_ALL_APPS) {
|
||||
Settings.Global.putInt(
|
||||
mContentResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_DEFAULT);
|
||||
if (!isChecked && gameDriver == GAME_DRIVER_OFF) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Settings.Global.putInt(mContentResolver, Settings.Global.GAME_DRIVER_ALL_APPS,
|
||||
isChecked ? GAME_DRIVER_DEFAULT : GAME_DRIVER_OFF);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@@ -36,7 +36,6 @@ import androidx.preference.PreferenceScreen;
|
||||
import androidx.preference.SwitchPreference;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
@@ -63,11 +62,14 @@ public class GameDriverEnableForAllAppsPreferenceControllerTest {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mResolver = mContext.getContentResolver();
|
||||
|
||||
Settings.Global.putInt(mResolver, Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 1);
|
||||
Settings.Global.putInt(
|
||||
mResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_DEFAULT);
|
||||
|
||||
mController = new GameDriverEnableForAllAppsPreferenceController(mContext, "testKey");
|
||||
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
|
||||
mController.displayPreference(mScreen);
|
||||
|
||||
Settings.Global.putInt(mResolver, Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -138,7 +140,6 @@ public class GameDriverEnableForAllAppsPreferenceControllerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore("b/123707483")
|
||||
public void updateState_gameDriverOff_notVisibleAndUncheck() {
|
||||
Settings.Global.putInt(mResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_OFF);
|
||||
mController.updateState(mPreference);
|
||||
|
Reference in New Issue
Block a user