Merge "Add prerelease driver to graphics driver preference dashboard."

This commit is contained in:
TreeHugger Robot
2020-02-20 19:02:57 +00:00
committed by Android (Google) Code Review
3 changed files with 59 additions and 8 deletions

View File

@@ -10990,8 +10990,8 @@
<string name="graphics_driver_app_preference_default">Default</string> <string name="graphics_driver_app_preference_default">Default</string>
<!-- The game driver value for Game Driver app preference [CHAR LIMIT=50] --> <!-- The game driver value for Game Driver app preference [CHAR LIMIT=50] -->
<string name="graphics_driver_app_preference_game_driver">Game Driver</string> <string name="graphics_driver_app_preference_game_driver">Game Driver</string>
<!-- The prerelase driver value for Prerelease Driver app preference [CHAR LIMIT=50] --> <!-- The prerelase driver value for Developer Driver app preference [CHAR LIMIT=50] -->
<string name="graphics_driver_app_preference_prerelease_driver">Prerelease Driver</string> <string name="graphics_driver_app_preference_prerelease_driver">Developer Driver</string>
<!-- The system driver value for system graphics driver app preference [CHAR LIMIT=50] --> <!-- The system driver value for system graphics driver app preference [CHAR LIMIT=50] -->
<string name="graphics_driver_app_preference_system">System Graphics Driver</string> <string name="graphics_driver_app_preference_system">System Graphics Driver</string>
<!-- All the graphics driver preference values for all apps globally [CHAR LIMIT=50] --> <!-- All the graphics driver preference values for all apps globally [CHAR LIMIT=50] -->
@@ -11002,6 +11002,7 @@
<!-- All the values of graphics driver for app preference [CHAR LIMIT=50] --> <!-- All the values of graphics driver for app preference [CHAR LIMIT=50] -->
<string-array name="graphics_driver_app_preference_values"> <string-array name="graphics_driver_app_preference_values">
<item>@string/graphics_driver_app_preference_default</item> <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_game_driver</item>
<item>@string/graphics_driver_app_preference_system</item> <item>@string/graphics_driver_app_preference_system</item>
</string-array> </string-array>

View File

@@ -26,7 +26,9 @@ import android.content.pm.PackageManager;
import android.content.res.Resources; import android.content.res.Resources;
import android.os.Handler; import android.os.Handler;
import android.os.Looper; import android.os.Looper;
import android.os.SystemProperties;
import android.provider.Settings; import android.provider.Settings;
import android.text.TextUtils;
import androidx.annotation.VisibleForTesting; import androidx.annotation.VisibleForTesting;
import androidx.preference.ListPreference; import androidx.preference.ListPreference;
@@ -58,15 +60,19 @@ public class GraphicsDriverAppPreferenceController extends BasePreferenceControl
GraphicsDriverContentObserver.OnGraphicsDriverContentChangedListener, LifecycleObserver, GraphicsDriverContentObserver.OnGraphicsDriverContentChangedListener, LifecycleObserver,
OnStart, OnStop { 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 Context mContext;
private final ContentResolver mContentResolver; private final ContentResolver mContentResolver;
private final CharSequence[] mEntryList;
private final String mPreferenceTitle; private final String mPreferenceTitle;
private final String mPreferenceDefault; private final String mPreferenceDefault;
private final String mPreferenceGameDriver; private final String mPreferenceGameDriver;
private final String mPreferencePrereleaseDriver; private final String mPreferencePrereleaseDriver;
private final String mPreferenceSystem; private final String mPreferenceSystem;
@VisibleForTesting @VisibleForTesting
CharSequence[] mEntryList;
@VisibleForTesting
GraphicsDriverContentObserver mGraphicsDriverContentObserver; GraphicsDriverContentObserver mGraphicsDriverContentObserver;
private final List<AppInfo> mAppInfos; private final List<AppInfo> mAppInfos;
@@ -85,7 +91,6 @@ public class GraphicsDriverAppPreferenceController extends BasePreferenceControl
new GraphicsDriverContentObserver(new Handler(Looper.getMainLooper()), this); new GraphicsDriverContentObserver(new Handler(Looper.getMainLooper()), this);
final Resources resources = context.getResources(); 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); mPreferenceTitle = resources.getString(R.string.graphics_driver_app_preference_title);
mPreferenceDefault = resources.getString(R.string.graphics_driver_app_preference_default); mPreferenceDefault = resources.getString(R.string.graphics_driver_app_preference_default);
mPreferenceGameDriver = mPreferenceGameDriver =
@@ -93,6 +98,7 @@ public class GraphicsDriverAppPreferenceController extends BasePreferenceControl
mPreferencePrereleaseDriver = mPreferencePrereleaseDriver =
resources.getString(R.string.graphics_driver_app_preference_prerelease_driver); resources.getString(R.string.graphics_driver_app_preference_prerelease_driver);
mPreferenceSystem = resources.getString(R.string.graphics_driver_app_preference_system); mPreferenceSystem = resources.getString(R.string.graphics_driver_app_preference_system);
mEntryList = constructEntryList();
// TODO: Move this task to background if there's potential ANR/Jank. // TODO: Move this task to background if there's potential ANR/Jank.
// Update the UI when all the app infos are ready. // Update the UI when all the app infos are ready.
@@ -189,6 +195,28 @@ public class GraphicsDriverAppPreferenceController extends BasePreferenceControl
updateState(mPreferenceGroup); 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 // AppInfo class to achieve loading the application label only once
class AppInfo { class AppInfo {
AppInfo(PackageManager packageManager, ApplicationInfo applicationInfo) { AppInfo(PackageManager packageManager, ApplicationInfo applicationInfo) {

View File

@@ -56,8 +56,9 @@ import java.util.Arrays;
public class GraphicsDriverAppPreferenceControllerTest { public class GraphicsDriverAppPreferenceControllerTest {
private static final int DEFAULT = 0; private static final int DEFAULT = 0;
private static final int GAME_DRIVER = 1; private static final int PRERELEASE_DRIVER = 1;
private static final int SYSTEM = 2; 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_APP_NAME = "testApp";
private static final String TEST_PKG_NAME = "testPkg"; private static final String TEST_PKG_NAME = "testPkg";
@@ -116,7 +117,7 @@ public class GraphicsDriverAppPreferenceControllerTest {
} }
@Test @Test
public void getAvailability_gameDriverOff_conditionallyUnavailable() { public void getAvailability_graphicsDriverOff_conditionallyUnavailable() {
loadDefaultConfig(); loadDefaultConfig();
Settings.Global.putInt(mResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_OFF); Settings.Global.putInt(mResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_OFF);
@@ -163,7 +164,7 @@ public class GraphicsDriverAppPreferenceControllerTest {
} }
@Test @Test
public void updateState_gameDriverOff_notVisible() { public void updateState_graphicsDriverOff_notVisible() {
Settings.Global.putInt(mResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_OFF); Settings.Global.putInt(mResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_OFF);
loadDefaultConfig(); loadDefaultConfig();
@@ -213,6 +214,8 @@ public class GraphicsDriverAppPreferenceControllerTest {
assertThat(preference.getDialogTitle()).isEqualTo(mDialogTitle); assertThat(preference.getDialogTitle()).isEqualTo(mDialogTitle);
assertThat(preference.getEntries()).isEqualTo(mValueList); assertThat(preference.getEntries()).isEqualTo(mValueList);
assertThat(preference.getEntryValues()).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); assertThat(preference.getSummary()).isEqualTo(mPreferencePrereleaseDriver);
} }
@@ -248,6 +251,23 @@ public class GraphicsDriverAppPreferenceControllerTest {
.isEqualTo(""); .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 @Test
public void onPreferenceChange_selectGAME_DRIVER_shouldUpdateAttributesAndSettingsGlobal() { public void onPreferenceChange_selectGAME_DRIVER_shouldUpdateAttributesAndSettingsGlobal() {
loadDefaultConfig(); loadDefaultConfig();
@@ -306,6 +326,8 @@ public class GraphicsDriverAppPreferenceControllerTest {
Settings.Global.putString(mResolver, Settings.Global.GAME_DRIVER_OPT_OUT_APPS, optOut); Settings.Global.putString(mResolver, Settings.Global.GAME_DRIVER_OPT_OUT_APPS, optOut);
mController = new GraphicsDriverAppPreferenceController(mContext, "testKey"); mController = new GraphicsDriverAppPreferenceController(mContext, "testKey");
mController.mEntryList = mContext.getResources().getStringArray(
R.array.graphics_driver_app_preference_values);
mGroup = spy(new PreferenceCategory(mContext)); mGroup = spy(new PreferenceCategory(mContext));
final PreferenceManager preferenceManager = new PreferenceManager(mContext); final PreferenceManager preferenceManager = new PreferenceManager(mContext);
when(mGroup.getContext()).thenReturn(mContext); when(mGroup.getContext()).thenReturn(mContext);