Search in sources :

Example 6 with BasePreferenceController

use of com.android.settings.core.BasePreferenceController in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class BaseSearchIndexProvider method getPreferenceControllers.

@Override
public List<AbstractPreferenceController> getPreferenceControllers(Context context) {
    final List<AbstractPreferenceController> controllersFromCode = createPreferenceControllers(context);
    final List<SearchIndexableResource> res = getXmlResourcesToIndex(context, true);
    if (res == null || res.isEmpty()) {
        return controllersFromCode;
    }
    List<BasePreferenceController> controllersFromXml = new ArrayList<>();
    for (SearchIndexableResource sir : res) {
        controllersFromXml.addAll(PreferenceControllerListHelper.getPreferenceControllersFromXml(context, sir.xmlResId));
    }
    controllersFromXml = PreferenceControllerListHelper.filterControllers(controllersFromXml, controllersFromCode);
    final List<AbstractPreferenceController> allControllers = new ArrayList<>();
    if (controllersFromCode != null) {
        allControllers.addAll(controllersFromCode);
    }
    allControllers.addAll(controllersFromXml);
    return allControllers;
}
Also used : BasePreferenceController(com.android.settings.core.BasePreferenceController) SearchIndexableResource(android.provider.SearchIndexableResource) AbstractPreferenceController(com.android.settingslib.core.AbstractPreferenceController) ArrayList(java.util.ArrayList)

Example 7 with BasePreferenceController

use of com.android.settings.core.BasePreferenceController in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class SliceDataConverter method getSliceDataFromXML.

private List<SliceData> getSliceDataFromXML(int xmlResId, String fragmentName) {
    XmlResourceParser parser = null;
    final List<SliceData> xmlSliceData = new ArrayList<>();
    String controllerClassName = "";
    try {
        parser = mContext.getResources().getXml(xmlResId);
        int type;
        while ((type = parser.next()) != XmlPullParser.END_DOCUMENT && type != XmlPullParser.START_TAG) {
        // Parse next until start tag is found
        }
        String nodeName = parser.getName();
        if (!NODE_NAME_PREFERENCE_SCREEN.equals(nodeName)) {
            throw new RuntimeException("XML document must start with <PreferenceScreen> tag; found" + nodeName + " at " + parser.getPositionDescription());
        }
        final AttributeSet attrs = Xml.asAttributeSet(parser);
        final String screenTitle = PreferenceXmlParserUtils.getDataTitle(mContext, attrs);
        // TODO (b/67996923) Investigate if we need headers for Slices, since they never
        // correspond to an actual setting.
        final List<Bundle> metadata = PreferenceXmlParserUtils.extractMetadata(mContext, xmlResId, MetadataFlag.FLAG_NEED_KEY | MetadataFlag.FLAG_NEED_PREF_CONTROLLER | MetadataFlag.FLAG_NEED_PREF_TYPE | MetadataFlag.FLAG_NEED_PREF_TITLE | MetadataFlag.FLAG_NEED_PREF_ICON | MetadataFlag.FLAG_NEED_PREF_SUMMARY | MetadataFlag.FLAG_NEED_PLATFORM_SLICE_FLAG | MetadataFlag.FLAG_UNAVAILABLE_SLICE_SUBTITLE);
        for (Bundle bundle : metadata) {
            // TODO (b/67996923) Non-controller Slices should become intent-only slices.
            // Note that without a controller, dynamic summaries are impossible.
            controllerClassName = bundle.getString(METADATA_CONTROLLER);
            if (TextUtils.isEmpty(controllerClassName)) {
                continue;
            }
            final String key = bundle.getString(METADATA_KEY);
            final String title = bundle.getString(METADATA_TITLE);
            final String summary = bundle.getString(METADATA_SUMMARY);
            final int iconResId = bundle.getInt(METADATA_ICON);
            final int sliceType = SliceBuilderUtils.getSliceType(mContext, controllerClassName, key);
            final boolean isPlatformSlice = bundle.getBoolean(METADATA_PLATFORM_SLICE_FLAG);
            final String unavailableSliceSubtitle = bundle.getString(METADATA_UNAVAILABLE_SLICE_SUBTITLE);
            final SliceData xmlSlice = new SliceData.Builder().setKey(key).setTitle(title).setSummary(summary).setIcon(iconResId).setScreenTitle(screenTitle).setPreferenceControllerClassName(controllerClassName).setFragmentName(fragmentName).setSliceType(sliceType).setPlatformDefined(isPlatformSlice).setUnavailableSliceSubtitle(unavailableSliceSubtitle).build();
            final BasePreferenceController controller = SliceBuilderUtils.getPreferenceController(mContext, xmlSlice);
            // Only add pre-approved Slices available on the device.
            if (controller.isSliceable() && controller.isAvailable()) {
                xmlSliceData.add(xmlSlice);
            }
        }
    } catch (SliceData.InvalidSliceDataException e) {
        Log.w(TAG, "Invalid data when building SliceData for " + fragmentName, e);
        mMetricsFeatureProvider.action(SettingsEnums.PAGE_UNKNOWN, SettingsEnums.ACTION_VERIFY_SLICE_ERROR_INVALID_DATA, SettingsEnums.PAGE_UNKNOWN, controllerClassName, 1);
    } catch (XmlPullParserException | IOException | Resources.NotFoundException e) {
        Log.w(TAG, "Error parsing PreferenceScreen: ", e);
        mMetricsFeatureProvider.action(SettingsEnums.PAGE_UNKNOWN, SettingsEnums.ACTION_VERIFY_SLICE_PARSING_ERROR, SettingsEnums.PAGE_UNKNOWN, fragmentName, 1);
    } catch (Exception e) {
        Log.w(TAG, "Get slice data from XML failed ", e);
        mMetricsFeatureProvider.action(SettingsEnums.PAGE_UNKNOWN, SettingsEnums.ACTION_VERIFY_SLICE_OTHER_EXCEPTION, SettingsEnums.PAGE_UNKNOWN, fragmentName + "_" + controllerClassName, 1);
    } finally {
        if (parser != null)
            parser.close();
    }
    return xmlSliceData;
}
Also used : XmlResourceParser(android.content.res.XmlResourceParser) Bundle(android.os.Bundle) ArrayList(java.util.ArrayList) IOException(java.io.IOException) IOException(java.io.IOException) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) BasePreferenceController(com.android.settings.core.BasePreferenceController) AttributeSet(android.util.AttributeSet) XmlPullParserException(org.xmlpull.v1.XmlPullParserException)

Example 8 with BasePreferenceController

use of com.android.settings.core.BasePreferenceController in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class SettingsSliceProvider method loadSlice.

@VisibleForTesting
void loadSlice(Uri uri) {
    long startBuildTime = System.currentTimeMillis();
    final SliceData sliceData;
    try {
        sliceData = mSlicesDatabaseAccessor.getSliceDataFromUri(uri);
    } catch (IllegalStateException e) {
        Log.d(TAG, "Could not create slicedata for uri: " + uri, e);
        return;
    }
    final BasePreferenceController controller = SliceBuilderUtils.getPreferenceController(getContext(), sliceData);
    final IntentFilter filter = controller.getIntentFilter();
    if (filter != null) {
        registerIntentToUri(filter, uri);
    }
    ThreadUtils.postOnMainThread(() -> startBackgroundWorker(controller, uri));
    mSliceWeakDataCache.put(uri, sliceData);
    getContext().getContentResolver().notifyChange(uri, null);
    Log.d(TAG, "Built slice (" + uri + ") in: " + (System.currentTimeMillis() - startBuildTime));
}
Also used : BasePreferenceController(com.android.settings.core.BasePreferenceController) IntentFilter(android.content.IntentFilter) VisibleForTesting(androidx.annotation.VisibleForTesting)

Example 9 with BasePreferenceController

use of com.android.settings.core.BasePreferenceController in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class SliceBroadcastReceiver method handleCopyAction.

private void handleCopyAction(Context context, String key, boolean isPlatformSlice) {
    if (TextUtils.isEmpty(key)) {
        throw new IllegalArgumentException("No key passed to Intent for controller");
    }
    final BasePreferenceController controller = getPreferenceController(context, key);
    if (!(controller instanceof Sliceable)) {
        throw new IllegalArgumentException("Copyable action passed for a non-copyable key:" + key);
    }
    if (!controller.isAvailable()) {
        Log.w(TAG, "Can't update " + key + " since the setting is unavailable");
        if (!controller.hasAsyncUpdate()) {
            updateUri(context, key, isPlatformSlice);
        }
        return;
    }
    controller.copy();
}
Also used : BasePreferenceController(com.android.settings.core.BasePreferenceController)

Example 10 with BasePreferenceController

use of com.android.settings.core.BasePreferenceController in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class SliceBroadcastReceiver method handleToggleAction.

private void handleToggleAction(Context context, String key, boolean isChecked, boolean isPlatformSlice) {
    if (TextUtils.isEmpty(key)) {
        throw new IllegalStateException("No key passed to Intent for toggle controller");
    }
    final BasePreferenceController controller = getPreferenceController(context, key);
    if (!(controller instanceof TogglePreferenceController)) {
        throw new IllegalStateException("Toggle action passed for a non-toggle key: " + key);
    }
    if (!controller.isAvailable()) {
        Log.w(TAG, "Can't update " + key + " since the setting is unavailable");
        if (!controller.hasAsyncUpdate()) {
            updateUri(context, key, isPlatformSlice);
        }
        return;
    }
    // TODO post context.getContentResolver().notifyChanged(uri, null) in the Toggle controller
    // so that it's automatically broadcast to any slice.
    final TogglePreferenceController toggleController = (TogglePreferenceController) controller;
    toggleController.setChecked(isChecked);
    logSliceValueChange(context, key, isChecked ? 1 : 0);
    if (!controller.hasAsyncUpdate()) {
        updateUri(context, key, isPlatformSlice);
    }
}
Also used : BasePreferenceController(com.android.settings.core.BasePreferenceController) TogglePreferenceController(com.android.settings.core.TogglePreferenceController)

Aggregations

BasePreferenceController (com.android.settings.core.BasePreferenceController)13 AbstractPreferenceController (com.android.settingslib.core.AbstractPreferenceController)5 ArrayList (java.util.ArrayList)5 Context (android.content.Context)3 Test (org.junit.Test)3 Bundle (android.os.Bundle)2 SearchIndexableResource (android.provider.SearchIndexableResource)2 CallSuper (androidx.annotation.CallSuper)2 VisibleForTesting (androidx.annotation.VisibleForTesting)2 Indexable (com.android.settings.search.Indexable)2 Activity (android.app.Activity)1 SettingsEnums (android.app.settings.SettingsEnums)1 IntentFilter (android.content.IntentFilter)1 XmlResourceParser (android.content.res.XmlResourceParser)1 TextUtils (android.text.TextUtils)1 ArrayMap (android.util.ArrayMap)1 ArraySet (android.util.ArraySet)1 AttributeSet (android.util.AttributeSet)1 Log (android.util.Log)1 Fragment (androidx.fragment.app.Fragment)1