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

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

[Catalyst] Support deeplink for catalyst screen

Bug: 407910711
Flag: com.android.settings.flags.catalyst
Test: devtool
Change-Id: I8ed97f72f7098c526847161ad2e068f6846d0d81
parent 4ee80ae4
Loading
Loading
Loading
Loading
+57 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2025 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.settings

import android.content.Intent
import android.os.Bundle
import com.android.settingslib.metadata.EXTRA_BINDING_SCREEN_KEY
import com.android.settingslib.preference.PreferenceFragment

/**
 * Activity to load catalyst preference screen.
 *
 * @param bindingScreenKey preference screen key
 * @param fragmentClass fragment class to load the preference screen
 */
open class CatalystSettingsActivity
@JvmOverloads
constructor(
    private val bindingScreenKey: String,
    private val fragmentClass: Class<out PreferenceFragment> = CatalystFragment::class.java,
) : SettingsActivity() {

    override fun isValidFragment(fragmentName: String?) = fragmentName == fragmentClass.name

    override fun getInitialFragmentName(intent: Intent?): String = fragmentClass.name

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

/**
 * Fragment to load catalyst preference screen.
 *
 * `PreferenceFragment` class is not used as it does not support highlighting specific preference.
 */
class CatalystFragment : SettingsPreferenceFragment() {

    override fun getMetricsCategory() = 0

    override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
        preferenceScreen = createPreferenceScreen()
    }
}
+9 −3
Original line number Diff line number Diff line
@@ -249,7 +249,7 @@ public class SettingsActivity extends SettingsBaseActivity
        int category = SettingsEnums.PAGE_UNKNOWN;
        Bundle args = null;
        if (getIntent() != null) {
            args = getIntent().getBundleExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS);
            args = getInitialFragmentArguments(getIntent());
        }

        Fragment fragment = Utils.getTargetFragment(this, getMetricsTag(), args);
@@ -502,6 +502,12 @@ public class SettingsActivity extends SettingsBaseActivity
        return intent.getStringExtra(EXTRA_SHOW_FRAGMENT);
    }

    /** Returns the arguments to initial fragment that the activity will launch. */
    @VisibleForTesting
    public @Nullable Bundle getInitialFragmentArguments(Intent intent) {
        return intent.getBundleExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS);
    }

    @Override
    protected void onApplyThemeResource(Theme theme, int resid, boolean first) {
        theme.applyStyle(R.style.SetupWizardPartnerResource, true);
@@ -542,7 +548,7 @@ public class SettingsActivity extends SettingsBaseActivity

            setTitleFromIntent(intent);

            Bundle initialArguments = intent.getBundleExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS);
            Bundle initialArguments = getInitialFragmentArguments(intent);
            switchToFragment(initialFragmentName, initialArguments, true,
                    mInitialTitleResId, mInitialTitle);
        } else {
@@ -679,7 +685,7 @@ public class SettingsActivity extends SettingsBaseActivity
        if (startingFragment != null) {
            Intent modIntent = new Intent(superIntent);
            modIntent.putExtra(EXTRA_SHOW_FRAGMENT, startingFragment);
            Bundle args = superIntent.getBundleExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS);
            Bundle args = getInitialFragmentArguments(superIntent);
            if (args != null) {
                args = new Bundle(args);
            } else {