Don't add SettingsLib to static_libs in Settings unit test.

Adding them results in duplicate classes and causes conflict for the R
classes and resource loading.

Meanwhile, correctly removing the SettingsLibSettingsSpinner resulted
in the test failing to find the getSelectedItem() method which is
unused inside Settings app. This is an inherent issue when unit
testing an optimized (and shrunk) app, and since there's no other way
for the test to get the current selected item, this change simply
changes the Settings code to invoke getSelectedItem() as well. This
has exactly the same effect because SettingsSpinnerPreference updates
its mPosition right before calling the OnItemSelectedListener in its
implementation.

Bug: 183340630
Bug: 177638625
Bug: 183342958
Test: atest SettingsSliderPreferenceControllerTest
Test: atest PrivateVolumeForgetTest
Change-Id: Ia26ca923369b41291614fb9bd50dfbd2aac2f0fa
This commit is contained in:
Hai Zhang
2021-05-11 00:45:21 -07:00
parent 525659c291
commit 6bf47f6274
2 changed files with 4 additions and 5 deletions

View File

@@ -100,7 +100,8 @@ public class StorageSelectionPreferenceController extends BasePreferenceControll
if (mOnItemSelectedListener == null) {
return;
}
mOnItemSelectedListener.onItemSelected(mStorageAdapter.getItem(position));
mOnItemSelectedListener.onItemSelected(
(StorageEntry) mSpinnerPreference.getSelectedItem());
}
@Override

View File

@@ -32,10 +32,8 @@ android_test {
"platform-test-annotations",
"truth-prebuilt",
"ub-uiautomator",
"SettingsLibSettingsSpinner",
"SettingsLibUsageProgressBarPreference",
"SettingsLibTwoTargetPreference",
"SettingsLibMainSwitchPreference",
// Don't add SettingsLib libraries here - you can use them directly as they are in the
// instrumented Settings app.
],
// Include all test java files.