Loading res/values/strings.xml +3 −2 Original line number Diff line number Diff line Loading @@ -10990,8 +10990,8 @@ <string name="graphics_driver_app_preference_default">Default</string> <!-- The game driver value for Game Driver app preference [CHAR LIMIT=50] --> <string name="graphics_driver_app_preference_game_driver">Game Driver</string> <!-- The prerelase driver value for Prerelease Driver app preference [CHAR LIMIT=50] --> <string name="graphics_driver_app_preference_prerelease_driver">Prerelease Driver</string> <!-- The prerelase driver value for Developer Driver app preference [CHAR LIMIT=50] --> <string name="graphics_driver_app_preference_prerelease_driver">Developer Driver</string> <!-- The system driver value for system graphics driver app preference [CHAR LIMIT=50] --> <string name="graphics_driver_app_preference_system">System Graphics Driver</string> <!-- All the graphics driver preference values for all apps globally [CHAR LIMIT=50] --> Loading @@ -11002,6 +11002,7 @@ <!-- All the values of graphics driver for app preference [CHAR LIMIT=50] --> <string-array name="graphics_driver_app_preference_values"> <item>@string/graphics_driver_app_preference_default</item> <item>@string/graphics_driver_app_preference_prerelease_driver</item> <item>@string/graphics_driver_app_preference_game_driver</item> <item>@string/graphics_driver_app_preference_system</item> </string-array> src/com/android/settings/development/graphicsdriver/GraphicsDriverAppPreferenceController.java +30 −2 Original line number Diff line number Diff line Loading @@ -26,7 +26,9 @@ import android.content.pm.PackageManager; import android.content.res.Resources; import android.os.Handler; import android.os.Looper; import android.os.SystemProperties; import android.provider.Settings; import android.text.TextUtils; import androidx.annotation.VisibleForTesting; import androidx.preference.ListPreference; Loading Loading @@ -58,15 +60,19 @@ public class GraphicsDriverAppPreferenceController extends BasePreferenceControl GraphicsDriverContentObserver.OnGraphicsDriverContentChangedListener, LifecycleObserver, OnStart, OnStop { private static final String PROPERTY_GFX_DRIVER_GAME = "ro.gfx.driver.0"; private static final String PROPERTY_GFX_DRIVER_PRERELEASE = "ro.gfx.driver.1"; private final Context mContext; private final ContentResolver mContentResolver; private final CharSequence[] mEntryList; private final String mPreferenceTitle; private final String mPreferenceDefault; private final String mPreferenceGameDriver; private final String mPreferencePrereleaseDriver; private final String mPreferenceSystem; @VisibleForTesting CharSequence[] mEntryList; @VisibleForTesting GraphicsDriverContentObserver mGraphicsDriverContentObserver; private final List<AppInfo> mAppInfos; Loading @@ -85,7 +91,6 @@ public class GraphicsDriverAppPreferenceController extends BasePreferenceControl new GraphicsDriverContentObserver(new Handler(Looper.getMainLooper()), this); final Resources resources = context.getResources(); mEntryList = resources.getStringArray(R.array.graphics_driver_app_preference_values); mPreferenceTitle = resources.getString(R.string.graphics_driver_app_preference_title); mPreferenceDefault = resources.getString(R.string.graphics_driver_app_preference_default); mPreferenceGameDriver = Loading @@ -93,6 +98,7 @@ public class GraphicsDriverAppPreferenceController extends BasePreferenceControl mPreferencePrereleaseDriver = resources.getString(R.string.graphics_driver_app_preference_prerelease_driver); mPreferenceSystem = resources.getString(R.string.graphics_driver_app_preference_system); mEntryList = constructEntryList(); // TODO: Move this task to background if there's potential ANR/Jank. // Update the UI when all the app infos are ready. Loading Loading @@ -189,6 +195,28 @@ public class GraphicsDriverAppPreferenceController extends BasePreferenceControl updateState(mPreferenceGroup); } /** * Constructs and returns a list of graphics driver choices. */ public CharSequence[] constructEntryList() { final String prereleaseDriverPackageName = SystemProperties.get(PROPERTY_GFX_DRIVER_PRERELEASE); final String gameDriverPackageName = SystemProperties.get(PROPERTY_GFX_DRIVER_GAME); List<CharSequence> entryList = new ArrayList<>(); entryList.add(mPreferenceDefault); if (!TextUtils.isEmpty(prereleaseDriverPackageName)) { entryList.add(mPreferencePrereleaseDriver); } if (!TextUtils.isEmpty(gameDriverPackageName)) { entryList.add(mPreferenceGameDriver); } entryList.add(mPreferenceSystem); CharSequence[] filteredEntryList = new CharSequence[entryList.size()]; filteredEntryList = entryList.toArray(filteredEntryList); return filteredEntryList; } // AppInfo class to achieve loading the application label only once class AppInfo { AppInfo(PackageManager packageManager, ApplicationInfo applicationInfo) { Loading tests/robotests/src/com/android/settings/development/graphicsdriver/GraphicsDriverAppPreferenceControllerTest.java +26 −4 Original line number Diff line number Diff line Loading @@ -56,8 +56,9 @@ import java.util.Arrays; public class GraphicsDriverAppPreferenceControllerTest { private static final int DEFAULT = 0; private static final int GAME_DRIVER = 1; private static final int SYSTEM = 2; private static final int PRERELEASE_DRIVER = 1; private static final int GAME_DRIVER = 2; private static final int SYSTEM = 3; private static final String TEST_APP_NAME = "testApp"; private static final String TEST_PKG_NAME = "testPkg"; Loading Loading @@ -116,7 +117,7 @@ public class GraphicsDriverAppPreferenceControllerTest { } @Test public void getAvailability_gameDriverOff_conditionallyUnavailable() { public void getAvailability_graphicsDriverOff_conditionallyUnavailable() { loadDefaultConfig(); Settings.Global.putInt(mResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_OFF); Loading Loading @@ -163,7 +164,7 @@ public class GraphicsDriverAppPreferenceControllerTest { } @Test public void updateState_gameDriverOff_notVisible() { public void updateState_graphicsDriverOff_notVisible() { Settings.Global.putInt(mResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_OFF); loadDefaultConfig(); Loading Loading @@ -213,6 +214,8 @@ public class GraphicsDriverAppPreferenceControllerTest { assertThat(preference.getDialogTitle()).isEqualTo(mDialogTitle); assertThat(preference.getEntries()).isEqualTo(mValueList); assertThat(preference.getEntryValues()).isEqualTo(mValueList); assertThat(preference.getEntry()).isEqualTo(mValueList[PRERELEASE_DRIVER]); assertThat(preference.getValue()).isEqualTo(mValueList[PRERELEASE_DRIVER]); assertThat(preference.getSummary()).isEqualTo(mPreferencePrereleaseDriver); } Loading Loading @@ -248,6 +251,23 @@ public class GraphicsDriverAppPreferenceControllerTest { .isEqualTo(""); } @Test public void onPreferenceChange_selectPRERELEASE_DRIVER_shouldUpdateAttrAndSettingsGlobal() { loadDefaultConfig(); final ListPreference preference = mController.createListPreference(mContext, TEST_PKG_NAME, TEST_APP_NAME); mController.onPreferenceChange(preference, mValueList[PRERELEASE_DRIVER]); assertThat(preference.getEntry()).isEqualTo(mValueList[PRERELEASE_DRIVER]); assertThat(preference.getValue()).isEqualTo(mValueList[PRERELEASE_DRIVER]); assertThat(preference.getSummary()).isEqualTo(mValueList[PRERELEASE_DRIVER]); assertThat(Settings.Global.getString(mResolver, Settings.Global.GAME_DRIVER_PRERELEASE_OPT_IN_APPS)) .isEqualTo(TEST_PKG_NAME); assertThat(Settings.Global.getString(mResolver, Settings.Global.GAME_DRIVER_OPT_OUT_APPS)) .isEqualTo(""); } @Test public void onPreferenceChange_selectGAME_DRIVER_shouldUpdateAttributesAndSettingsGlobal() { loadDefaultConfig(); Loading Loading @@ -306,6 +326,8 @@ public class GraphicsDriverAppPreferenceControllerTest { Settings.Global.putString(mResolver, Settings.Global.GAME_DRIVER_OPT_OUT_APPS, optOut); mController = new GraphicsDriverAppPreferenceController(mContext, "testKey"); mController.mEntryList = mContext.getResources().getStringArray( R.array.graphics_driver_app_preference_values); mGroup = spy(new PreferenceCategory(mContext)); final PreferenceManager preferenceManager = new PreferenceManager(mContext); when(mGroup.getContext()).thenReturn(mContext); Loading Loading
res/values/strings.xml +3 −2 Original line number Diff line number Diff line Loading @@ -10990,8 +10990,8 @@ <string name="graphics_driver_app_preference_default">Default</string> <!-- The game driver value for Game Driver app preference [CHAR LIMIT=50] --> <string name="graphics_driver_app_preference_game_driver">Game Driver</string> <!-- The prerelase driver value for Prerelease Driver app preference [CHAR LIMIT=50] --> <string name="graphics_driver_app_preference_prerelease_driver">Prerelease Driver</string> <!-- The prerelase driver value for Developer Driver app preference [CHAR LIMIT=50] --> <string name="graphics_driver_app_preference_prerelease_driver">Developer Driver</string> <!-- The system driver value for system graphics driver app preference [CHAR LIMIT=50] --> <string name="graphics_driver_app_preference_system">System Graphics Driver</string> <!-- All the graphics driver preference values for all apps globally [CHAR LIMIT=50] --> Loading @@ -11002,6 +11002,7 @@ <!-- All the values of graphics driver for app preference [CHAR LIMIT=50] --> <string-array name="graphics_driver_app_preference_values"> <item>@string/graphics_driver_app_preference_default</item> <item>@string/graphics_driver_app_preference_prerelease_driver</item> <item>@string/graphics_driver_app_preference_game_driver</item> <item>@string/graphics_driver_app_preference_system</item> </string-array>
src/com/android/settings/development/graphicsdriver/GraphicsDriverAppPreferenceController.java +30 −2 Original line number Diff line number Diff line Loading @@ -26,7 +26,9 @@ import android.content.pm.PackageManager; import android.content.res.Resources; import android.os.Handler; import android.os.Looper; import android.os.SystemProperties; import android.provider.Settings; import android.text.TextUtils; import androidx.annotation.VisibleForTesting; import androidx.preference.ListPreference; Loading Loading @@ -58,15 +60,19 @@ public class GraphicsDriverAppPreferenceController extends BasePreferenceControl GraphicsDriverContentObserver.OnGraphicsDriverContentChangedListener, LifecycleObserver, OnStart, OnStop { private static final String PROPERTY_GFX_DRIVER_GAME = "ro.gfx.driver.0"; private static final String PROPERTY_GFX_DRIVER_PRERELEASE = "ro.gfx.driver.1"; private final Context mContext; private final ContentResolver mContentResolver; private final CharSequence[] mEntryList; private final String mPreferenceTitle; private final String mPreferenceDefault; private final String mPreferenceGameDriver; private final String mPreferencePrereleaseDriver; private final String mPreferenceSystem; @VisibleForTesting CharSequence[] mEntryList; @VisibleForTesting GraphicsDriverContentObserver mGraphicsDriverContentObserver; private final List<AppInfo> mAppInfos; Loading @@ -85,7 +91,6 @@ public class GraphicsDriverAppPreferenceController extends BasePreferenceControl new GraphicsDriverContentObserver(new Handler(Looper.getMainLooper()), this); final Resources resources = context.getResources(); mEntryList = resources.getStringArray(R.array.graphics_driver_app_preference_values); mPreferenceTitle = resources.getString(R.string.graphics_driver_app_preference_title); mPreferenceDefault = resources.getString(R.string.graphics_driver_app_preference_default); mPreferenceGameDriver = Loading @@ -93,6 +98,7 @@ public class GraphicsDriverAppPreferenceController extends BasePreferenceControl mPreferencePrereleaseDriver = resources.getString(R.string.graphics_driver_app_preference_prerelease_driver); mPreferenceSystem = resources.getString(R.string.graphics_driver_app_preference_system); mEntryList = constructEntryList(); // TODO: Move this task to background if there's potential ANR/Jank. // Update the UI when all the app infos are ready. Loading Loading @@ -189,6 +195,28 @@ public class GraphicsDriverAppPreferenceController extends BasePreferenceControl updateState(mPreferenceGroup); } /** * Constructs and returns a list of graphics driver choices. */ public CharSequence[] constructEntryList() { final String prereleaseDriverPackageName = SystemProperties.get(PROPERTY_GFX_DRIVER_PRERELEASE); final String gameDriverPackageName = SystemProperties.get(PROPERTY_GFX_DRIVER_GAME); List<CharSequence> entryList = new ArrayList<>(); entryList.add(mPreferenceDefault); if (!TextUtils.isEmpty(prereleaseDriverPackageName)) { entryList.add(mPreferencePrereleaseDriver); } if (!TextUtils.isEmpty(gameDriverPackageName)) { entryList.add(mPreferenceGameDriver); } entryList.add(mPreferenceSystem); CharSequence[] filteredEntryList = new CharSequence[entryList.size()]; filteredEntryList = entryList.toArray(filteredEntryList); return filteredEntryList; } // AppInfo class to achieve loading the application label only once class AppInfo { AppInfo(PackageManager packageManager, ApplicationInfo applicationInfo) { Loading
tests/robotests/src/com/android/settings/development/graphicsdriver/GraphicsDriverAppPreferenceControllerTest.java +26 −4 Original line number Diff line number Diff line Loading @@ -56,8 +56,9 @@ import java.util.Arrays; public class GraphicsDriverAppPreferenceControllerTest { private static final int DEFAULT = 0; private static final int GAME_DRIVER = 1; private static final int SYSTEM = 2; private static final int PRERELEASE_DRIVER = 1; private static final int GAME_DRIVER = 2; private static final int SYSTEM = 3; private static final String TEST_APP_NAME = "testApp"; private static final String TEST_PKG_NAME = "testPkg"; Loading Loading @@ -116,7 +117,7 @@ public class GraphicsDriverAppPreferenceControllerTest { } @Test public void getAvailability_gameDriverOff_conditionallyUnavailable() { public void getAvailability_graphicsDriverOff_conditionallyUnavailable() { loadDefaultConfig(); Settings.Global.putInt(mResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_OFF); Loading Loading @@ -163,7 +164,7 @@ public class GraphicsDriverAppPreferenceControllerTest { } @Test public void updateState_gameDriverOff_notVisible() { public void updateState_graphicsDriverOff_notVisible() { Settings.Global.putInt(mResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_OFF); loadDefaultConfig(); Loading Loading @@ -213,6 +214,8 @@ public class GraphicsDriverAppPreferenceControllerTest { assertThat(preference.getDialogTitle()).isEqualTo(mDialogTitle); assertThat(preference.getEntries()).isEqualTo(mValueList); assertThat(preference.getEntryValues()).isEqualTo(mValueList); assertThat(preference.getEntry()).isEqualTo(mValueList[PRERELEASE_DRIVER]); assertThat(preference.getValue()).isEqualTo(mValueList[PRERELEASE_DRIVER]); assertThat(preference.getSummary()).isEqualTo(mPreferencePrereleaseDriver); } Loading Loading @@ -248,6 +251,23 @@ public class GraphicsDriverAppPreferenceControllerTest { .isEqualTo(""); } @Test public void onPreferenceChange_selectPRERELEASE_DRIVER_shouldUpdateAttrAndSettingsGlobal() { loadDefaultConfig(); final ListPreference preference = mController.createListPreference(mContext, TEST_PKG_NAME, TEST_APP_NAME); mController.onPreferenceChange(preference, mValueList[PRERELEASE_DRIVER]); assertThat(preference.getEntry()).isEqualTo(mValueList[PRERELEASE_DRIVER]); assertThat(preference.getValue()).isEqualTo(mValueList[PRERELEASE_DRIVER]); assertThat(preference.getSummary()).isEqualTo(mValueList[PRERELEASE_DRIVER]); assertThat(Settings.Global.getString(mResolver, Settings.Global.GAME_DRIVER_PRERELEASE_OPT_IN_APPS)) .isEqualTo(TEST_PKG_NAME); assertThat(Settings.Global.getString(mResolver, Settings.Global.GAME_DRIVER_OPT_OUT_APPS)) .isEqualTo(""); } @Test public void onPreferenceChange_selectGAME_DRIVER_shouldUpdateAttributesAndSettingsGlobal() { loadDefaultConfig(); Loading Loading @@ -306,6 +326,8 @@ public class GraphicsDriverAppPreferenceControllerTest { Settings.Global.putString(mResolver, Settings.Global.GAME_DRIVER_OPT_OUT_APPS, optOut); mController = new GraphicsDriverAppPreferenceController(mContext, "testKey"); mController.mEntryList = mContext.getResources().getStringArray( R.array.graphics_driver_app_preference_values); mGroup = spy(new PreferenceCategory(mContext)); final PreferenceManager preferenceManager = new PreferenceManager(mContext); when(mGroup.getContext()).thenReturn(mContext); Loading