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

Commit b84bb725 authored by Jacky Wang's avatar Jacky Wang
Browse files

[Catalyst] Support deep link for parameterized screen

Bug: 415125776
Flag: EXEMPT refactor
Test: manual
Change-Id: Ia5f25aaa9589394d68da29695d9e589a25a95d12
parent 049a330a
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import android.content.Intent
import android.os.Bundle
import com.android.settings.dashboard.DashboardFragment
import com.android.settingslib.core.instrumentation.Instrumentable
import com.android.settingslib.metadata.EXTRA_BINDING_SCREEN_ARGS
import com.android.settingslib.metadata.EXTRA_BINDING_SCREEN_KEY
import com.android.settingslib.preference.PreferenceFragment

@@ -41,7 +42,10 @@ constructor(
    override fun getInitialFragmentName(intent: Intent?): String = fragmentClass.name

    override fun getInitialFragmentArguments(intent: Intent?): Bundle? =
        Bundle().apply { putString(EXTRA_BINDING_SCREEN_KEY, bindingScreenKey) }
        (super.getInitialFragmentArguments(intent) ?: Bundle()).apply {
            putString(EXTRA_BINDING_SCREEN_KEY, bindingScreenKey)
            putBundle(EXTRA_BINDING_SCREEN_ARGS, intent?.getBundleExtra(EXTRA_BINDING_SCREEN_ARGS))
        }
}

/**
+2 −8
Original line number Diff line number Diff line
@@ -247,10 +247,7 @@ public class SettingsActivity extends SettingsBaseActivity

    private int lookupMetricsCategory() {
        int category = SettingsEnums.PAGE_UNKNOWN;
        Bundle args = null;
        if (getIntent() != null) {
            args = getInitialFragmentArguments(getIntent());
        }
        Bundle args = getInitialFragmentArguments(getIntent());

        Fragment fragment = Utils.getTargetFragment(this, getMetricsTag(), args);

@@ -263,10 +260,7 @@ public class SettingsActivity extends SettingsBaseActivity
    }

    private String getMetricsTag() {
        String tag = null;
        if (getIntent() != null && getIntent().hasExtra(EXTRA_SHOW_FRAGMENT)) {
            tag = getInitialFragmentName(getIntent());
        }
        String tag = getInitialFragmentName(getIntent());

        if (TextUtils.isEmpty(tag)) {
            Log.w(LOG_TAG, "MetricsTag is invalid " + tag);
+4 −2
Original line number Diff line number Diff line
@@ -131,8 +131,10 @@ public abstract class AppInfoBase extends SettingsPreferenceFragment
    protected String retrieveAppEntry() {
        final Bundle args = getArguments();
        mPackageName = (args != null) ? args.getString(ARG_PACKAGE_NAME) : null;
        Intent intent = (args == null) ?
                getIntent() : (Intent) args.getParcelable("intent");
        Intent intent = args != null ? args.getParcelable("intent", Intent.class) : null;
        if (intent == null) {
            intent = getIntent();
        }
        if (mPackageName == null) {
            if (intent != null && intent.getData() != null) {
                mPackageName = intent.getData().getSchemeSpecificPart();
+30 −1
Original line number Diff line number Diff line
@@ -19,10 +19,12 @@ package com.android.settings.utils
import android.app.Activity
import android.content.Context
import android.content.Intent
import android.os.Bundle
import com.android.settings.SettingsActivity.EXTRA_FRAGMENT_ARG_KEY
import com.android.settingslib.metadata.EXTRA_BINDING_SCREEN_ARGS

/**
 * Returns the [Intent] to start given settings activity and locate the preference.
 * Returns the [Intent] to start given settings activity and highlight a specific preference.
 *
 * @param context context
 * @param activityClass activity to start
@@ -31,6 +33,33 @@ import com.android.settings.SettingsActivity.EXTRA_FRAGMENT_ARG_KEY
fun makeLaunchIntent(context: Context, activityClass: Class<out Activity>, key: String?) =
    Intent(context, activityClass).apply { highlightPreference(key) }

/**
 * Returns the [Intent] to start given settings activity that is parameterized screen and then
 * highlight a specific preference.
 *
 * @param context context
 * @param activityClass activity to start
 * @param arguments arguments of the parameterized screen
 * @param key preference key to locate
 */
fun makeLaunchIntent(
    context: Context,
    activityClass: Class<out Activity>,
    arguments: Bundle,
    key: String?,
) = Intent(context, activityClass).apply { highlightPreference(arguments, key) }

/**
 * Sets the intent extra to highlight given preference on a parameterized screen.
 *
 * @param arguments arguments of the parameterized screen
 * @param key preference to highlight
 */
fun Intent.highlightPreference(arguments: Bundle, key: String?) {
    putExtra(EXTRA_BINDING_SCREEN_ARGS, arguments)
    if (key != null) putExtra(EXTRA_FRAGMENT_ARG_KEY, key)
}

/** Sets the intent extra to highlight given preference. */
fun Intent.highlightPreference(key: String?) {
    if (key != null) putExtra(EXTRA_FRAGMENT_ARG_KEY, key)