From 6bf47f6274feb9da1711988f142316e911ce75df Mon Sep 17 00:00:00 2001 From: Hai Zhang Date: Tue, 11 May 2021 00:45:21 -0700 Subject: [PATCH] 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 --- .../storage/StorageSelectionPreferenceController.java | 3 ++- tests/unit/Android.bp | 6 ++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/com/android/settings/deviceinfo/storage/StorageSelectionPreferenceController.java b/src/com/android/settings/deviceinfo/storage/StorageSelectionPreferenceController.java index 03fddecea56..d6dcbf149bc 100644 --- a/src/com/android/settings/deviceinfo/storage/StorageSelectionPreferenceController.java +++ b/src/com/android/settings/deviceinfo/storage/StorageSelectionPreferenceController.java @@ -100,7 +100,8 @@ public class StorageSelectionPreferenceController extends BasePreferenceControll if (mOnItemSelectedListener == null) { return; } - mOnItemSelectedListener.onItemSelected(mStorageAdapter.getItem(position)); + mOnItemSelectedListener.onItemSelected( + (StorageEntry) mSpinnerPreference.getSelectedItem()); } @Override diff --git a/tests/unit/Android.bp b/tests/unit/Android.bp index 5582ff4dc8d..249ce7223fc 100644 --- a/tests/unit/Android.bp +++ b/tests/unit/Android.bp @@ -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.