Add PrefController in XML support
Add the ability to define a Preference Controller in xml using the 'controller' tag. This is useful for two reasons: - It allows the controllers to be instantiated via reflection for Slices and Dashboard fragment - Removes the requirement that controllers be defined manually in Fragments In order to be instantiable, they must have a unified construction following either: ClassName(Context) ClassName(Context, String) Also added a robotest that verifies that all controllers defined in XML follow the constructor schema, and extend BasePreferenceController. Test: robotests Bug: 67996923 Change-Id: I304b35dc666daebecf0c9e286696f3f2a510704a
This commit is contained in:
@@ -57,7 +57,9 @@ public class SystemUpdatePreferenceControllerTest {
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mController = new SystemUpdatePreferenceController(mContext, mUserManager);
|
||||
|
||||
when(mContext.getSystemService(Context.USER_SERVICE)).thenReturn(mUserManager);
|
||||
mController = new SystemUpdatePreferenceController(mContext);
|
||||
mPreference = new Preference(RuntimeEnvironment.application);
|
||||
mPreference.setKey(mController.getPreferenceKey());
|
||||
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
|
||||
@@ -82,7 +84,7 @@ public class SystemUpdatePreferenceControllerTest {
|
||||
|
||||
mController.updateNonIndexableKeys(keys);
|
||||
|
||||
assertThat(keys.size()).isEqualTo(1);
|
||||
assertThat(keys).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -94,8 +96,8 @@ public class SystemUpdatePreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void updateState_shouldSetToAndroidVersion() {
|
||||
mController = new SystemUpdatePreferenceController(
|
||||
RuntimeEnvironment.application, mUserManager);
|
||||
mController = new SystemUpdatePreferenceController(RuntimeEnvironment.application);
|
||||
|
||||
mController.updateState(mPreference);
|
||||
|
||||
assertThat(mPreference.getSummary())
|
||||
|
||||
Reference in New Issue
Block a user