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

Commit 7009c008 authored by Chaohui Wang's avatar Chaohui Wang
Browse files

Fix search for MMS Message

Also display multiple results when there are multiple MMS Message on
different SIMs.

When doing indexing, we not also log sub id as part of the key.
When user clicks the result, using SpaSearchLandingActivity to do the
redirection, set arguments to the fragment.

Fix: 352245817
Flag: EXEMPT bug fix
Test: manual - search mms
Test: unit test
Change-Id: Id47a1151cb418c18f68f97e3be33dcd21c5f5102
parent 7477f4ea
Loading
Loading
Loading
Loading
+20 −0
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@ package com.android.settings.spa;
message SpaSearchLandingKey {
  oneof page {
    SpaSearchLandingSpaPage spa_page = 1;
    SpaSearchLandingFragment fragment = 2;
  }
}

@@ -12,3 +13,22 @@ message SpaSearchLandingSpaPage {
  /** The destination of SPA page. */
  optional string destination = 1;
}

message SpaSearchLandingFragment {
  /** The fragment class name. */
  optional string fragment_name = 1;

  /** The key of the preference to highlight the item. */
  optional string preference_key = 2;

  /** The arguments passed to the page. */
  map<string, BundleValue> arguments = 3;
}

/** A value in an Android Bundle. */
message BundleValue {
  oneof value {
    /** A 32-bit signed integer value. */
    int32 int_value = 1;
  }
}
+2 −0
Original line number Diff line number Diff line
@@ -112,10 +112,12 @@
            android:selectable="false"
            settings:searchable="false"/>

        <!-- Settings search is handled by MmsMessageSearchItem. -->
        <SwitchPreferenceCompat
            android:key="mms_message"
            android:title="@string/mms_message_title"
            android:summary="@string/mms_message_summary"
            settings:searchable="false"
            settings:controller="com.android.settings.network.telephony.MmsMessagePreferenceController"/>

        <SwitchPreferenceCompat
+1 −1
Original line number Diff line number Diff line
@@ -34,7 +34,7 @@ object EmbeddedDeepLinkUtils {
    private const val TAG = "EmbeddedDeepLinkUtils"

    @JvmStatic
    fun Activity.tryStartMultiPaneDeepLink(
    fun Context.tryStartMultiPaneDeepLink(
        intent: Intent,
        highlightMenuKey: String? = null,
    ): Boolean {
+70 −33
Original line number Diff line number Diff line
@@ -22,46 +22,38 @@ import android.telephony.TelephonyManager
import android.telephony.data.ApnSetting
import androidx.lifecycle.LifecycleOwner
import androidx.preference.PreferenceScreen
import com.android.settings.R
import com.android.settings.Settings.MobileNetworkActivity.EXTRA_MMS_MESSAGE
import com.android.settings.core.TogglePreferenceController
import com.android.settings.network.telephony.MobileNetworkSettingsSearchIndex.MobileNetworkSettingsSearchItem
import com.android.settingslib.spa.framework.util.collectLatestWithLifecycle
import kotlinx.coroutines.flow.combine

/**
 * Preference controller for "MMS messages"
 */
class MmsMessagePreferenceController @JvmOverloads constructor(
/** Preference controller for "MMS messages" */
class MmsMessagePreferenceController
@JvmOverloads
constructor(
    context: Context,
    key: String,
    private val getDefaultDataSubId: () -> Int = {
        SubscriptionManager.getDefaultDataSubscriptionId()
    },
) : TelephonyTogglePreferenceController(context, key) {
) : TogglePreferenceController(context, key) {

    private lateinit var telephonyManager: TelephonyManager
    private var subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID
    private var telephonyManager: TelephonyManager =
        context.getSystemService(TelephonyManager::class.java)!!

    private var preferenceScreen: PreferenceScreen? = null

    fun init(subId: Int) {
        mSubId = subId
        telephonyManager = mContext.getSystemService(TelephonyManager::class.java)!!
            .createForSubscriptionId(subId)
        this.subId = subId
        telephonyManager = telephonyManager.createForSubscriptionId(subId)
    }

    override fun getAvailabilityStatus(subId: Int) =
        if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID &&
            this::telephonyManager.isInitialized &&
            !telephonyManager.isDataEnabled &&
            telephonyManager.isApnMetered(ApnSetting.TYPE_MMS) &&
            !isFallbackDataEnabled()
        ) AVAILABLE else CONDITIONALLY_UNAVAILABLE

    private fun isFallbackDataEnabled(): Boolean {
        val defaultDataSubId = getDefaultDataSubId()
        return defaultDataSubId != mSubId &&
            telephonyManager.createForSubscriptionId(defaultDataSubId).isDataEnabled &&
            telephonyManager.isMobileDataPolicyEnabled(
                TelephonyManager.MOBILE_DATA_POLICY_AUTO_DATA_SWITCH
            )
    }
    override fun getAvailabilityStatus() =
        if (getAvailabilityStatus(telephonyManager, subId, getDefaultDataSubId)) AVAILABLE
        else CONDITIONALLY_UNAVAILABLE

    override fun displayPreference(screen: PreferenceScreen) {
        super.displayPreference(screen)
@@ -70,16 +62,20 @@ class MmsMessagePreferenceController @JvmOverloads constructor(

    override fun onViewCreated(viewLifecycleOwner: LifecycleOwner) {
        combine(
            MobileDataRepository(mContext).mobileDataEnabledChangedFlow(mSubId),
                MobileDataRepository(mContext).mobileDataEnabledChangedFlow(subId),
                mContext.subscriptionsChangedFlow(), // Capture isMobileDataPolicyEnabled() changes
        ) { _, _ -> }.collectLatestWithLifecycle(viewLifecycleOwner) {
            ) { _, _ ->
            }
            .collectLatestWithLifecycle(viewLifecycleOwner) {
                preferenceScreen?.let { super.displayPreference(it) }
            }
    }

    override fun isChecked(): Boolean = telephonyManager.isMobileDataPolicyEnabled(
        TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED
    )
    override fun getSliceHighlightMenuRes() = NO_RES

    override fun isChecked(): Boolean =
        telephonyManager.isMobileDataPolicyEnabled(
            TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED)

    override fun setChecked(isChecked: Boolean): Boolean {
        telephonyManager.setMobileDataPolicyEnabled(
@@ -88,4 +84,45 @@ class MmsMessagePreferenceController @JvmOverloads constructor(
        )
        return true
    }

    companion object {
        private fun getAvailabilityStatus(
            telephonyManager: TelephonyManager,
            subId: Int,
            getDefaultDataSubId: () -> Int,
        ): Boolean {
            return SubscriptionManager.isValidSubscriptionId(subId) &&
                !telephonyManager.isDataEnabled &&
                telephonyManager.isApnMetered(ApnSetting.TYPE_MMS) &&
                !isFallbackDataEnabled(telephonyManager, subId, getDefaultDataSubId())
        }

        private fun isFallbackDataEnabled(
            telephonyManager: TelephonyManager,
            subId: Int,
            defaultDataSubId: Int,
        ): Boolean {
            return defaultDataSubId != subId &&
                telephonyManager.createForSubscriptionId(defaultDataSubId).isDataEnabled &&
                telephonyManager.isMobileDataPolicyEnabled(
                    TelephonyManager.MOBILE_DATA_POLICY_AUTO_DATA_SWITCH)
        }

        class MmsMessageSearchItem(
            context: Context,
            private val getDefaultDataSubId: () -> Int = {
                SubscriptionManager.getDefaultDataSubscriptionId()
            },
        ) : MobileNetworkSettingsSearchItem {
            private var telephonyManager: TelephonyManager =
                context.getSystemService(TelephonyManager::class.java)!!

            override val key: String = EXTRA_MMS_MESSAGE
            override val title: String = context.getString(R.string.mms_message_title)

            override fun isAvailable(subId: Int): Boolean =
                getAvailabilityStatus(
                    telephonyManager.createForSubscriptionId(subId), subId, getDefaultDataSubId)
        }
    }
}
+2 −6
Original line number Diff line number Diff line
@@ -467,14 +467,10 @@ public class MobileNetworkSettings extends AbstractMobileNetworkSettings impleme

    public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
            new BaseSearchIndexProvider(R.xml.mobile_network_settings) {

                /** suppress full page if user is not admin */
                @Override
                protected boolean isPageSearchEnabled(Context context) {
                    boolean isAirplaneOff = Settings.Global.getInt(context.getContentResolver(),
                            Settings.Global.AIRPLANE_MODE_ON, 0) == 0;
                    return isAirplaneOff && SubscriptionUtil.isSimHardwareVisible(context)
                            && context.getSystemService(UserManager.class).isAdminUser();
                    return MobileNetworkSettingsSearchIndex
                            .isMobileNetworkSettingsSearchable(context);
                }
            };

Loading