Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 58eda530 authored by Jason Chiu's avatar Jason Chiu
Browse files

[SettingsLib] Support master switch of inline toggle of Settings Injection v2

Allow developers to inject MasterSwitchPreference, a switch
preference with two tap targets, to Settings page.

Developers should declare keyhint and switch_uri for the activity
in AndroidManifest,and then implement a SwitchesProvider.

Bug: 132808482
Test: robotest
Change-Id: Id58ecd15475c428b3ae963831299b8bdf5e63e79
parent 499a579c
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.settingslib.drawer;

import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.pm.ComponentInfo;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
@@ -33,7 +34,7 @@ import java.util.Objects;
public class ActivityTile extends Tile {
    private static final String TAG = "ActivityTile";

    public ActivityTile(ComponentInfo info, String category) {
    public ActivityTile(ActivityInfo info, String category) {
        super(info, category);
        setMetaData(info.metaData);
    }
+35 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2019 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.settingslib.drawer;

import android.os.Bundle;

/**
 * A controller that manages event for master switch.
 */
public abstract class MasterSwitchController extends SwitchController {

    @Override
    protected final MetaData getMetaData() {
        throw new UnsupportedOperationException();
    }

    @Override
    final Bundle getBundle() {
        throw new UnsupportedOperationException();
    }
}
+2 −2
Original line number Diff line number Diff line
@@ -42,10 +42,10 @@ public class ProviderTile extends Tile {
    private String mAuthority;
    private String mKey;

    public ProviderTile(ComponentInfo info, String category, Bundle metaData) {
    public ProviderTile(ProviderInfo info, String category, Bundle metaData) {
        super(info, category);
        setMetaData(metaData);
        mAuthority = ((ProviderInfo) info).authority;
        mAuthority = info.authority;
        mKey = metaData.getString(META_DATA_PREFERENCE_KEYHINT);
    }

+1 −1
Original line number Diff line number Diff line
@@ -108,7 +108,7 @@ public abstract class SwitchController {
    Bundle getBundle() {
        final MetaData metaData = getMetaData();
        if (metaData == null) {
            throw new IllegalArgumentException("Should not return null in getMetaData()");
            throw new NullPointerException("Should not return null in getMetaData()");
        }

        final Bundle bundle = metaData.build();
+9 −4
Original line number Diff line number Diff line
@@ -55,7 +55,7 @@ public abstract class SwitchesProvider extends ContentProvider {

    private String mAuthority;
    private final Map<String, SwitchController> mControllerMap = new LinkedHashMap<>();
    private final List<Bundle> mSwitchList = new ArrayList<>();
    private final List<Bundle> mSwitchDataList = new ArrayList<>();

    /**
     * Get a list of {@link SwitchController} for this provider.
@@ -88,7 +88,9 @@ public abstract class SwitchesProvider extends ContentProvider {

            controller.setAuthority(mAuthority);
            mControllerMap.put(key, controller);
            mSwitchList.add(controller.getBundle());
            if (!(controller instanceof MasterSwitchController)) {
                mSwitchDataList.add(controller.getBundle());
            }
        });
        return true;
    }
@@ -101,7 +103,7 @@ public abstract class SwitchesProvider extends ContentProvider {
                : null;
        if (TextUtils.isEmpty(key)) {
            if (METHOD_GET_SWITCH_DATA.equals(method)) {
                bundle.putParcelableList(EXTRA_SWITCH_DATA, mSwitchList);
                bundle.putParcelableList(EXTRA_SWITCH_DATA, mSwitchDataList);
                return bundle;
            }
            return null;
@@ -114,7 +116,10 @@ public abstract class SwitchesProvider extends ContentProvider {

        switch (method) {
            case METHOD_GET_SWITCH_DATA:
                if (!(controller instanceof MasterSwitchController)) {
                    return controller.getBundle();
                }
                break;
            case METHOD_GET_PROVIDER_ICON:
                if (controller instanceof ProviderIcon) {
                    return ((ProviderIcon) controller).getProviderIcon();
Loading