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:
Matthew Fritze
2017-12-11 09:57:54 -08:00
parent 2f7240ceb5
commit 7d2b4f5fc7
13 changed files with 355 additions and 71 deletions

View File

@@ -17,26 +17,23 @@ package com.android.settings.deviceinfo;
import android.content.Context;
import com.android.settings.core.BasePreferenceController;
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settingslib.core.AbstractPreferenceController;
public class AdditionalSystemUpdatePreferenceController extends
AbstractPreferenceController implements PreferenceControllerMixin {
public class AdditionalSystemUpdatePreferenceController extends BasePreferenceController {
private static final String KEY_UPDATE_SETTING = "additional_system_update_settings";
public AdditionalSystemUpdatePreferenceController(Context context) {
super(context);
super(context, KEY_UPDATE_SETTING);
}
@Override
public boolean isAvailable() {
public int getAvailabilityStatus() {
return mContext.getResources().getBoolean(
com.android.settings.R.bool.config_additional_system_update_setting_enable);
com.android.settings.R.bool.config_additional_system_update_setting_enable)
? AVAILABLE
: DISABLED_UNSUPPORTED;
}
@Override
public String getPreferenceKey() {
return KEY_UPDATE_SETTING;
}
}
}