diff --git a/res/values/strings.xml b/res/values/strings.xml index 83e730af664..f04aef289e6 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -10951,8 +10951,8 @@ Default Game Driver - - Prerelease Driver + + Developer Driver System Graphics Driver @@ -10963,6 +10963,7 @@ @string/graphics_driver_app_preference_default + @string/graphics_driver_app_preference_prerelease_driver @string/graphics_driver_app_preference_game_driver @string/graphics_driver_app_preference_system diff --git a/src/com/android/settings/development/graphicsdriver/GraphicsDriverAppPreferenceController.java b/src/com/android/settings/development/graphicsdriver/GraphicsDriverAppPreferenceController.java index c1376a81c59..2013b459f92 100644 --- a/src/com/android/settings/development/graphicsdriver/GraphicsDriverAppPreferenceController.java +++ b/src/com/android/settings/development/graphicsdriver/GraphicsDriverAppPreferenceController.java @@ -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; @@ -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 mAppInfos; @@ -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 = @@ -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. @@ -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 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) { diff --git a/tests/robotests/src/com/android/settings/development/graphicsdriver/GraphicsDriverAppPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/development/graphicsdriver/GraphicsDriverAppPreferenceControllerTest.java index 522dc8aab3b..372daf0cc95 100644 --- a/tests/robotests/src/com/android/settings/development/graphicsdriver/GraphicsDriverAppPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/development/graphicsdriver/GraphicsDriverAppPreferenceControllerTest.java @@ -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"; @@ -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); @@ -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(); @@ -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); } @@ -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(); @@ -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);