Hide MMS messages if switch mobile data automatically
Per designer's comment, hide the "MMS messages" if user cannot use it to control MMS. Fix: 303759893 Test: manual - turn "Switch mobile data automatically" on / off Test: unit test Change-Id: I874524c0cedb48f7daf87f32920e26428ae78c89
This commit is contained in:
@@ -17,33 +17,25 @@
|
||||
package com.android.settings.network.telephony
|
||||
|
||||
import android.content.Context
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import android.telephony.SubscriptionManager
|
||||
import android.telephony.TelephonyManager
|
||||
import android.telephony.data.ApnSetting
|
||||
import androidx.lifecycle.DefaultLifecycleObserver
|
||||
import androidx.lifecycle.LifecycleOwner
|
||||
import androidx.preference.PreferenceScreen
|
||||
import com.android.settings.network.MobileDataContentObserver
|
||||
import com.android.settings.network.mobileDataEnabledFlow
|
||||
import com.android.settingslib.spa.framework.util.collectLatestWithLifecycle
|
||||
import kotlinx.coroutines.flow.combine
|
||||
|
||||
/**
|
||||
* Preference controller for "MMS messages"
|
||||
*/
|
||||
class MmsMessagePreferenceController(context: Context, key: String) :
|
||||
TelephonyTogglePreferenceController(context, key), DefaultLifecycleObserver {
|
||||
TelephonyTogglePreferenceController(context, key) {
|
||||
|
||||
private lateinit var telephonyManager: TelephonyManager
|
||||
|
||||
private var preferenceScreen: PreferenceScreen? = null
|
||||
|
||||
private val mobileDataContentObserver =
|
||||
MobileDataContentObserver(Handler(Looper.getMainLooper())).apply {
|
||||
setOnMobileDataChangedListener {
|
||||
preferenceScreen?.let { super.displayPreference(it) }
|
||||
}
|
||||
}
|
||||
|
||||
fun init(subId: Int) {
|
||||
mSubId = subId
|
||||
telephonyManager = mContext.getSystemService(TelephonyManager::class.java)!!
|
||||
@@ -53,26 +45,25 @@ class MmsMessagePreferenceController(context: Context, key: String) :
|
||||
override fun getAvailabilityStatus(subId: Int) =
|
||||
if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID &&
|
||||
!telephonyManager.isDataEnabled &&
|
||||
telephonyManager.isApnMetered(ApnSetting.TYPE_MMS)
|
||||
telephonyManager.isApnMetered(ApnSetting.TYPE_MMS) &&
|
||||
!telephonyManager.isMobileDataPolicyEnabled(
|
||||
TelephonyManager.MOBILE_DATA_POLICY_AUTO_DATA_SWITCH
|
||||
)
|
||||
) AVAILABLE else CONDITIONALLY_UNAVAILABLE
|
||||
|
||||
override fun onStart(owner: LifecycleOwner) {
|
||||
if (mSubId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
|
||||
mobileDataContentObserver.register(mContext, mSubId)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onStop(owner: LifecycleOwner) {
|
||||
if (mSubId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
|
||||
mobileDataContentObserver.unRegister(mContext)
|
||||
}
|
||||
}
|
||||
|
||||
override fun displayPreference(screen: PreferenceScreen) {
|
||||
super.displayPreference(screen)
|
||||
preferenceScreen = screen
|
||||
}
|
||||
|
||||
override fun onViewCreated(viewLifecycleOwner: LifecycleOwner) {
|
||||
combine(
|
||||
mContext.mobileDataEnabledFlow(mSubId),
|
||||
mContext.subscriptionsChangedFlow(), // Capture isMobileDataPolicyEnabled() changes
|
||||
) { _, _ -> }.collectLatestWithLifecycle(viewLifecycleOwner) {
|
||||
preferenceScreen?.let { super.displayPreference(it) } }
|
||||
}
|
||||
|
||||
override fun isChecked(): Boolean = telephonyManager.isMobileDataPolicyEnabled(
|
||||
TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED
|
||||
)
|
||||
|
Reference in New Issue
Block a user