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

Commit 615563db authored by Fan Zhang's avatar Fan Zhang
Browse files

Migrate more subsetting launching to SubSettingLauncher

Bug: 73250851
Test: robotests
Change-Id: Ic0bf23f6ac6f717bdd3d477fdb84af68badae8e6
parent 2ecef333
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();
        }
    }

+0 −16
Original line number Diff line number Diff line
@@ -481,22 +481,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