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

Commit c85e701b authored by Fan Zhang's avatar Fan Zhang Committed by Android (Google) Code Review
Browse files

Merge changes I1c3620d3,Ic0bf23f6

* changes:
  Move some subsetting launch to SubSettingLauncher
  Migrate more subsetting launching to SubSettingLauncher
parents a8d70f7c 3fff7bc3
Loading
Loading
Loading
Loading
+12 −14
Original line number Diff line number Diff line
@@ -59,6 +59,7 @@ import com.android.settings.Settings.WifiSettingsActivity;
import com.android.settings.applications.manageapplications.ManageApplications;
import com.android.settings.backup.BackupSettingsActivity;
import com.android.settings.core.FeatureFlags;
import com.android.settings.core.SubSettingLauncher;
import com.android.settings.core.gateway.SettingsGateway;
import com.android.settings.dashboard.DashboardFeatureProvider;
import com.android.settings.dashboard.DashboardSummary;
@@ -612,11 +613,10 @@ public class SettingsActivity extends SettingsDrawerActivity
     * @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 userHandle    The user for which the panel has to be started.
     */
    public void startPreferencePanelAsUser(Fragment caller, String fragmentClass,
            Bundle args, int titleRes, CharSequence titleText, UserHandle userHandle) {
            Bundle args, int titleRes, UserHandle userHandle) {
        // This is a workaround.
        //
        // Calling startWithFragmentAsUser() without specifying FLAG_ACTIVITY_NEW_TASK to the intent
@@ -628,19 +628,17 @@ public class SettingsActivity extends SettingsDrawerActivity
        // 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, titleText, null, 0);
        } else {
            String title = null;
            if (titleRes < 0) {
                if (titleText != null) {
                    title = titleText.toString();
            startPreferencePanel(caller, fragmentClass, args, titleRes, null /* titleText */,
                    null, 0);
        } else {
                    // There not much we can do in that case
                    title = "";
                }
            }
            Utils.startWithFragmentAsUser(this, fragmentClass, args, titleRes, title,
                    mIsShortcut, mMetricsFeatureProvider.getMetricsCategory(caller), userHandle);
            new SubSettingLauncher(this)
                    .setDestination(fragmentClass)
                    .setArguments(args)
                    .setTitle(titleRes)
                    .setIsShortCut(mIsShortcut)
                    .setSourceMetricsCategory(mMetricsFeatureProvider.getMetricsCategory(caller))
                    .setUserHandle(userHandle)
                    .launch();
        }
    }

+1 −45
Original line number Diff line number Diff line
@@ -412,26 +412,6 @@ public final class Utils extends com.android.settingslib.Utils {
                metricsCategory);
    }


    /**
     * Start a new instance of the activity, showing only the given fragment.
     * When launched in this mode, the given preference fragment will be instantiated and fill the
     * entire activity.
     *
     * @param context The context.
     * @param fragmentName The name of the fragment to display.
     * @param titleResId resource id for the String to display for the title of this set
     *                   of preferences.
     * @param metricsCategory The current metricsCategory for logging source when fragment starts
     * @param intentFlags flag that should be added to the intent.
     */
    public static void startWithFragment(Context context, String fragmentName, int titleResId,
            int metricsCategory, int intentFlags) {
        startWithFragment(context, fragmentName, null, null, 0,
                null /* titleResPackageName */, titleResId, null, false /* not a shortcut */,
                metricsCategory, intentFlags);
    }

    /**
     * Start a new instance of the activity, showing only the given fragment.
     * When launched in this mode, the given preference fragment will be instantiated and fill the
@@ -463,17 +443,9 @@ public final class Utils extends com.android.settingslib.Utils {
    public static void startWithFragment(Context context, String fragmentName, Bundle args,
            Fragment resultTo, int resultRequestCode, String titleResPackageName, int titleResId,
            CharSequence title, boolean isShortcut, int metricsCategory) {
        startWithFragment(context, fragmentName, args, resultTo, resultRequestCode,
                titleResPackageName, titleResId, title, isShortcut, metricsCategory,
                Intent.FLAG_ACTIVITY_NEW_TASK);
    }

    public static void startWithFragment(Context context, String fragmentName, Bundle args,
            Fragment resultTo, int resultRequestCode, String titleResPackageName, int titleResId,
            CharSequence title, boolean isShortcut, int metricsCategory, int flags) {
        Intent intent = onBuildStartFragmentIntent(context, fragmentName, args, titleResPackageName,
                titleResId, title, isShortcut, metricsCategory);
        intent.addFlags(flags);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        if (resultTo == null) {
            context.startActivity(intent);
        } else {
@@ -481,22 +453,6 @@ public final class Utils extends com.android.settingslib.Utils {
        }
    }

    public static void startWithFragmentAsUser(Context context, String fragmentName, Bundle args,
            int titleResId, CharSequence title, boolean isShortcut, int metricsCategory,
            UserHandle userHandle) {
        // workaround to avoid crash in b/17523189
        if (userHandle.getIdentifier() == UserHandle.myUserId()) {
            startWithFragment(context, fragmentName, args, null, 0, titleResId, title, isShortcut,
                    metricsCategory);
        } else {
            Intent intent = onBuildStartFragmentIntent(context, fragmentName, args,
                    null /* titleResPackageName */, titleResId, title, isShortcut, metricsCategory);
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
            context.startActivityAsUser(intent, userHandle);
        }
    }

    /**
     * Build an Intent to launch a new activity showing the selected fragment.
     * The implementation constructs an Intent that re-launches the current activity with the
+1 −1
Original line number Diff line number Diff line
@@ -88,7 +88,7 @@ public class BluetoothMasterSwitchPreferenceController extends AbstractPreferenc
    public boolean handlePreferenceTreeClick(Preference preference) {
        if (KEY_TOGGLE_BLUETOOTH.equals(preference.getKey())) {
            mActivity.startPreferencePanelAsUser(mFragment, BluetoothSettings.class.getName(), null,
                    R.string.bluetooth, null, new UserHandle(UserHandle.myUserId()));
                    R.string.bluetooth, new UserHandle(UserHandle.myUserId()));
            return true;
        }
        return super.handlePreferenceTreeClick(preference);
+1 −1
Original line number Diff line number Diff line
@@ -60,7 +60,7 @@ public class BluetoothPairingPreferenceController extends AbstractPreferenceCont
    public boolean handlePreferenceTreeClick(Preference preference) {
        if (KEY_PAIRING.equals(preference.getKey())) {
            mActivity.startPreferencePanelAsUser(mFragment, BluetoothPairingDetail.class.getName(),
                    null, R.string.bluetooth_pairing_page_title, null,
                    null, R.string.bluetooth_pairing_page_title,
                    new UserHandle(UserHandle.myUserId()));
            return true;
        }
+12 −4
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import android.content.Intent;
import android.os.Bundle;
import android.os.UserHandle;
import android.support.annotation.VisibleForTesting;
import android.text.TextUtils;

import com.android.settings.SettingsActivity;
import com.android.settings.SubSettings;
@@ -102,8 +103,17 @@ public class SubSettingLauncher {
        mLaunched = true;
        final Intent intent = new Intent(Intent.ACTION_MAIN);
        intent.setClass(mContext, SubSettings.class);

        if (TextUtils.isEmpty(mLaunchRequest.destinationName)) {
            throw new IllegalArgumentException("Destination fragment must be set");
        }
        intent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT, mLaunchRequest.destinationName);

        if (mLaunchRequest.sourceMetricsCategory <= 0) {
            throw new IllegalArgumentException("Source metrics category must be set");
        }
        intent.putExtra(VisibilityLoggerMixin.EXTRA_SOURCE_METRICS_CATEGORY,
                mLaunchRequest.sourceMetricsCategory);

        intent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_ARGUMENTS, mLaunchRequest.arguments);
        intent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_TITLE_RES_PACKAGE_NAME,
                mLaunchRequest.titleResPackageName);
@@ -112,8 +122,6 @@ public class SubSettingLauncher {
        intent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_TITLE, mLaunchRequest.title);
        intent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_AS_SHORTCUT,
                mLaunchRequest.isShortCut);
        intent.putExtra(VisibilityLoggerMixin.EXTRA_SOURCE_METRICS_CATEGORY,
                mLaunchRequest.sourceMetricsCategory);
        intent.addFlags(mLaunchRequest.flags);

        if (mLaunchRequest.userHandle != null
@@ -150,7 +158,7 @@ public class SubSettingLauncher {
        String titleResPackageName;
        CharSequence title;
        boolean isShortCut;
        int sourceMetricsCategory;
        int sourceMetricsCategory = -100;
        int flags;
        Fragment mResultListener;
        int mRequestCode;
Loading