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

Commit be45f9c8 authored by Fan Zhang's avatar Fan Zhang
Browse files

Migrate more settings to SubSettingsLauncher

Bug: 73250851
Test: robotests
Change-Id: I4100bef20e2ed477e4e31c9b7816f1b03f3f2809
parent b1d6c76b
Loading
Loading
Loading
Loading
+0 −96
Original line number Diff line number Diff line
@@ -75,7 +75,6 @@ import com.android.settingslib.drawer.SettingsDrawerActivity;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

public class SettingsActivity extends SettingsDrawerActivity
        implements PreferenceManager.OnPreferenceTreeClickListener,
@@ -157,10 +156,6 @@ public class SettingsActivity extends SettingsDrawerActivity
    private CharSequence mInitialTitle;
    private int mInitialTitleResId;

    private static final String[] LIKE_SHORTCUT_INTENT_ACTION_ARRAY = {
            "android.settings.APPLICATION_DETAILS_SETTINGS"
    };

    private BroadcastReceiver mDevelopmentSettingsListener;

    private boolean mBatteryPresent = true;
@@ -184,12 +179,9 @@ public class SettingsActivity extends SettingsDrawerActivity
    private Button mNextButton;

    private boolean mIsShowingDashboard;
    private boolean mIsShortcut;

    private ViewGroup mContent;

    private MetricsFeatureProvider mMetricsFeatureProvider;

    // Categories
    private ArrayList<DashboardCategory> mCategories = new ArrayList<>();

@@ -237,22 +229,6 @@ public class SettingsActivity extends SettingsDrawerActivity
        return tag;
    }

    private static boolean isShortCutIntent(final Intent intent) {
        Set<String> categories = intent.getCategories();
        return (categories != null) && categories.contains("com.android.settings.SHORTCUT");
    }

    private static boolean isLikeShortCutIntent(final Intent intent) {
        String action = intent.getAction();
        if (action == null) {
            return false;
        }
        for (int i = 0; i < LIKE_SHORTCUT_INTENT_ACTION_ARRAY.length; i++) {
            if (LIKE_SHORTCUT_INTENT_ACTION_ARRAY[i].equals(action)) return true;
        }
        return false;
    }

    @Override
    protected void onCreate(Bundle savedState) {
        super.onCreate(savedState);
@@ -261,7 +237,6 @@ public class SettingsActivity extends SettingsDrawerActivity
        final FeatureFactory factory = FeatureFactory.getFactory(this);

        mDashboardFeatureProvider = factory.getDashboardFeatureProvider(this);
        mMetricsFeatureProvider = factory.getMetricsFeatureProvider();

        // Should happen before any call to getIntent()
        getMetaData();
@@ -274,9 +249,6 @@ public class SettingsActivity extends SettingsDrawerActivity
        // Getting Intent properties can only be done after the super.onCreate(...)
        final String initialFragmentName = intent.getStringExtra(EXTRA_SHOW_FRAGMENT);

        mIsShortcut = isShortCutIntent(intent) || isLikeShortCutIntent(intent) ||
                intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SHORTCUT, false);

        final ComponentName cn = intent.getComponent();
        final String className = cn.getClassName();

@@ -583,74 +555,6 @@ public class SettingsActivity extends SettingsDrawerActivity
        return intentClass;
    }

    /**
     * Start a new fragment containing a preference panel.  If the preferences
     * are being displayed in multi-pane mode, the given fragment class will
     * be instantiated and placed in the appropriate pane.  If running in
     * single-pane mode, a new activity will be launched in which to show the
     * fragment.
     *
     * @param fragmentClass     Full name of the class implementing the fragment.
     * @param args              Any desired arguments to supply to the fragment.
     * @param titleRes          Optional resource identifier of the title of this
     *                          fragment.
     * @param titleText         Optional text of the title of this fragment.
     * @param resultTo          Optional fragment that result data should be sent to.
     *                          If non-null, resultTo.onActivityResult() will be called when this
     *                          preference panel is done.  The launched panel must use
     *                          {@link #finishPreferencePanel(Fragment, int, Intent)} when done.
     * @param resultRequestCode If resultTo is non-null, this is the caller's
     *                          request code to be received with the result.
     */
    @Deprecated
    public void startPreferencePanel(Fragment caller, String fragmentClass, Bundle args,
            int titleRes, CharSequence titleText, Fragment resultTo, int resultRequestCode) {
        String title = null;
        if (titleRes < 0 && titleText != null) {
            title = titleText.toString();
        }
        Utils.startWithFragment(this, fragmentClass, args, resultTo, resultRequestCode,
                titleRes, title, mIsShortcut, mMetricsFeatureProvider.getMetricsCategory(caller));
    }

    /**
     * Start a new fragment in a new activity containing a preference panel for a given user. If the
     * preferences are being displayed in multi-pane mode, the given fragment class will be
     * instantiated and placed in the appropriate pane. If running in single-pane mode, a new
     * activity will be launched in which to show the fragment.
     *
     * @param fragmentClass Full name of the class implementing the fragment.
     * @param args          Any desired arguments to supply to the fragment.
     * @param titleRes      Optional resource identifier of the title of this fragment.
     * @param userHandle    The user for which the panel has to be started.
     */
    public void startPreferencePanelAsUser(Fragment caller, String fragmentClass,
            Bundle args, int titleRes, UserHandle userHandle) {
        // This is a workaround.
        //
        // Calling startWithFragmentAsUser() without specifying FLAG_ACTIVITY_NEW_TASK to the intent
        // starting the fragment could cause a native stack corruption. See b/17523189. However,
        // adding that flag and start the preference panel with the same UserHandler will make it
        // impossible to use back button to return to the previous screen. See b/20042570.
        //
        // We work around this issue by adding FLAG_ACTIVITY_NEW_TASK to the intent, while doing
        // another check here to call startPreferencePanel() instead of startWithFragmentAsUser()
        // when we're calling it as the same user.
        if (userHandle.getIdentifier() == UserHandle.myUserId()) {
            startPreferencePanel(caller, fragmentClass, args, titleRes, null /* titleText */,
                    null, 0);
        } else {
            new SubSettingLauncher(this)
                    .setDestination(fragmentClass)
                    .setArguments(args)
                    .setTitle(titleRes)
                    .setIsShortCut(mIsShortcut)
                    .setSourceMetricsCategory(mMetricsFeatureProvider.getMetricsCategory(caller))
                    .setUserHandle(userHandle)
                    .launch();
        }
    }

    /**
     * Called by a preference panel fragment to finish itself.
     *
+16 −30
Original line number Diff line number Diff line
@@ -16,22 +16,22 @@

package com.android.settings.accessibility;

import android.app.Fragment;
import android.os.Bundle;
import android.text.TextUtils;
import android.support.v14.preference.PreferenceFragment;
import android.support.v7.preference.Preference;
import android.view.Menu;
import android.view.accessibility.AccessibilityEvent;

import com.android.settings.SettingsActivity;
import com.android.settings.core.SubSettingLauncher;
import com.android.settings.search.actionbar.SearchMenuController;
import com.android.settings.support.actionbar.HelpResourceProvider;
import com.android.settingslib.core.instrumentation.Instrumentable;

public class AccessibilitySettingsForSetupWizardActivity extends SettingsActivity {

    private static final String SAVE_KEY_TITLE = "activity_title";

    private boolean mSendExtraWindowStateChanged;

    @Override
    protected void onCreate(Bundle savedState) {
        super.onCreate(savedState);
@@ -52,12 +52,6 @@ public class AccessibilitySettingsForSetupWizardActivity extends SettingsActivit
        setTitle(savedState.getCharSequence(SAVE_KEY_TITLE));
    }

    @Override
    public void onResume() {
        super.onResume();
        mSendExtraWindowStateChanged = false;
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Return true, so we get notified when items in the menu are clicked.
@@ -76,28 +70,20 @@ public class AccessibilitySettingsForSetupWizardActivity extends SettingsActivit
    }

    @Override
    public void startPreferencePanel(Fragment caller, String fragmentClass, Bundle args,
            int titleRes, CharSequence titleText, Fragment resultTo, int resultRequestCode) {
        // Set the title.
        if (!TextUtils.isEmpty(titleText)) {
            setTitle(titleText);
        } else if (titleRes > 0) {
            setTitle(getString(titleRes));
    public boolean onPreferenceStartFragment(PreferenceFragment caller, Preference pref) {
        Bundle args = pref.getExtras();
        if (args == null) {
            args = new Bundle();
        }

        // Start the new Fragment.
        args.putInt(HelpResourceProvider.HELP_URI_RESOURCE_KEY, 0);
        args.putBoolean(SearchMenuController.NEED_SEARCH_ICON_IN_ACTION_BAR, false);
        startPreferenceFragment(Fragment.instantiate(this, fragmentClass, args), true);
        mSendExtraWindowStateChanged = true;
    }

    @Override
    public void onAttachFragment(Fragment fragment) {
        if (mSendExtraWindowStateChanged) {
            // Clear accessibility focus and let the screen reader announce the new title.
            getWindow().getDecorView()
                    .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
        }
        new SubSettingLauncher(this)
                .setDestination(pref.getFragment())
                .setArguments(args)
                .setSourceMetricsCategory(caller instanceof Instrumentable
                        ? ((Instrumentable) caller).getMetricsCategory()
                        : Instrumentable.METRICS_CATEGORY_UNKNOWN)
                .launch();
        return true;
    }
}
+11 −14
Original line number Diff line number Diff line
@@ -15,17 +15,16 @@
 */
package com.android.settings.bluetooth;

import android.app.Fragment;
import android.content.Context;
import android.os.UserHandle;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceScreen;

import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.settings.R;
import com.android.settings.SettingsActivity;
import com.android.settings.core.InstrumentedPreferenceFragment;
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settings.core.SubSettingLauncher;
import com.android.settings.overlay.FeatureFactory;
import com.android.settings.widget.MasterSwitchController;
import com.android.settings.widget.MasterSwitchPreference;
@@ -50,27 +49,22 @@ public class BluetoothMasterSwitchPreferenceController extends AbstractPreferenc
    private BluetoothEnabler mBluetoothEnabler;
    private BluetoothSummaryUpdater mSummaryUpdater;
    private RestrictionUtils mRestrictionUtils;
    private Fragment mFragment;
    private SettingsActivity mActivity;
    private BluetoothFeatureProvider mBluetoothFeatureProvider;
    private InstrumentedPreferenceFragment mFragment;

    public BluetoothMasterSwitchPreferenceController(Context context,
            LocalBluetoothManager bluetoothManager, Fragment fragment, SettingsActivity activity) {
        this(context, bluetoothManager, new RestrictionUtils(), fragment, activity);
            LocalBluetoothManager bluetoothManager, InstrumentedPreferenceFragment fragment) {
        this(context, bluetoothManager, new RestrictionUtils(), fragment);
    }

    @VisibleForTesting
    public BluetoothMasterSwitchPreferenceController(Context context,
            LocalBluetoothManager bluetoothManager, RestrictionUtils restrictionUtils,
            Fragment fragment, SettingsActivity activity) {
            InstrumentedPreferenceFragment fragment) {
        super(context);
        mBluetoothManager = bluetoothManager;
        mSummaryUpdater = new BluetoothSummaryUpdater(mContext, this, mBluetoothManager);
        mRestrictionUtils = restrictionUtils;
        mFragment = fragment;
        mActivity = activity;
        mBluetoothFeatureProvider = FeatureFactory.getFactory(
                mContext).getBluetoothFeatureProvider(mContext);
    }

    @Override
@@ -87,8 +81,11 @@ public class BluetoothMasterSwitchPreferenceController extends AbstractPreferenc
    @Override
    public boolean handlePreferenceTreeClick(Preference preference) {
        if (KEY_TOGGLE_BLUETOOTH.equals(preference.getKey())) {
            mActivity.startPreferencePanelAsUser(mFragment, BluetoothSettings.class.getName(), null,
                    R.string.bluetooth, new UserHandle(UserHandle.myUserId()));
            new SubSettingLauncher(mContext)
                    .setDestination(BluetoothSettings.class.getName())
                    .setTitle(R.string.bluetooth)
                    .setSourceMetricsCategory(mFragment.getMetricsCategory())
                    .launch();
            return true;
        }
        return super.handlePreferenceTreeClick(preference);
+11 −12
Original line number Diff line number Diff line
@@ -17,13 +17,12 @@
package com.android.settings.bluetooth;

import android.content.Context;
import android.support.v14.preference.PreferenceFragment;
import android.support.v7.preference.Preference;
import android.os.UserHandle;

import com.android.settings.SettingsActivity;
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settings.R;
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settings.core.SubSettingLauncher;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settingslib.core.AbstractPreferenceController;


@@ -35,15 +34,12 @@ public class BluetoothPairingPreferenceController extends AbstractPreferenceCont
    private static final String TAG = "BluetoothPairingPrefCtrl";

    public static final String KEY_PAIRING = "pref_bt_pairing";
    private PreferenceFragment mFragment;
    private SettingsActivity mActivity;
    private DashboardFragment mFragment;
    private Preference mPreference;

    public BluetoothPairingPreferenceController(Context context, PreferenceFragment fragment,
            SettingsActivity activity) {
    public BluetoothPairingPreferenceController(Context context, DashboardFragment fragment) {
        super(context);
        mFragment = fragment;
        mActivity = activity;
    }

    @Override
@@ -59,9 +55,12 @@ public class BluetoothPairingPreferenceController extends AbstractPreferenceCont
    @Override
    public boolean handlePreferenceTreeClick(Preference preference) {
        if (KEY_PAIRING.equals(preference.getKey())) {
            mActivity.startPreferencePanelAsUser(mFragment, BluetoothPairingDetail.class.getName(),
                    null, R.string.bluetooth_pairing_page_title,
                    new UserHandle(UserHandle.myUserId()));
            new SubSettingLauncher(mContext)
                    .setDestination(BluetoothPairingDetail.class.getName())
                    .setTitle(R.string.bluetooth_pairing_page_title)
                    .setSourceMetricsCategory(mFragment.getMetricsCategory())
                    .launch();

            return true;
        }

+1 −2
Original line number Diff line number Diff line
@@ -367,8 +367,7 @@ public class BluetoothSettings extends DeviceListPreferenceFragment implements I
        final List<AbstractPreferenceController> controllers = new ArrayList<>();
        final Lifecycle lifecycle = getLifecycle();
        mDeviceNamePrefController = new BluetoothDeviceNamePreferenceController(context, lifecycle);
        mPairingPrefController = new BluetoothPairingPreferenceController(context, this,
                (SettingsActivity) getActivity());
        mPairingPrefController = new BluetoothPairingPreferenceController(context, this);
        controllers.add(mDeviceNamePrefController);
        controllers.add(mPairingPrefController);
        controllers.add(new BluetoothFilesPreferenceController(context));
Loading