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:
Chaohui Wang
2023-12-15 12:10:31 +08:00
parent facd2f7197
commit 007ef134b6
5 changed files with 150 additions and 47 deletions

View File

@@ -79,6 +79,20 @@ class MmsMessagePreferenceControllerTest {
assertThat(availabilityStatus).isEqualTo(CONDITIONALLY_UNAVAILABLE)
}
@Test
fun getAvailabilityStatus_autoDataSwitch_returnUnavailable() {
mockTelephonyManager.stub {
on { isApnMetered(ApnSetting.TYPE_MMS) } doReturn true
on {
isMobileDataPolicyEnabled(TelephonyManager.MOBILE_DATA_POLICY_AUTO_DATA_SWITCH)
} doReturn true
}
val availabilityStatus = controller.getAvailabilityStatus(SUB_ID)
assertThat(availabilityStatus).isEqualTo(CONDITIONALLY_UNAVAILABLE)
}
@Test
fun getAvailabilityStatus_mobileDataOffWithValidSubId_returnAvailable() {
mockTelephonyManager.stub {

View File

@@ -0,0 +1,70 @@
/*
* Copyright (C) 2023 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.network.telephony
import android.content.Context
import android.telephony.SubscriptionManager
import androidx.test.core.app.ApplicationProvider
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.android.settingslib.spa.testutils.firstWithTimeoutOrNull
import com.android.settingslib.spa.testutils.toListWithTimeout
import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.async
import kotlinx.coroutines.delay
import kotlinx.coroutines.runBlocking
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.kotlin.any
import org.mockito.kotlin.doAnswer
import org.mockito.kotlin.doReturn
import org.mockito.kotlin.mock
import org.mockito.kotlin.spy
@RunWith(AndroidJUnit4::class)
class SubscriptionRepositoryTest {
private var subInfoListener: SubscriptionManager.OnSubscriptionsChangedListener? = null
private val mockSubscriptionManager = mock<SubscriptionManager> {
on { addOnSubscriptionsChangedListener(any(), any()) } doAnswer {
subInfoListener = it.arguments[1] as SubscriptionManager.OnSubscriptionsChangedListener
subInfoListener?.onSubscriptionsChanged()
}
}
private val context: Context = spy(ApplicationProvider.getApplicationContext()) {
on { getSystemService(SubscriptionManager::class.java) } doReturn mockSubscriptionManager
}
@Test
fun subscriptionsChangedFlow_hasInitialValue() = runBlocking {
val initialValue = context.subscriptionsChangedFlow().firstWithTimeoutOrNull()
assertThat(initialValue).isSameInstanceAs(Unit)
}
@Test
fun subscriptionsChangedFlow_changed() = runBlocking {
val listDeferred = async {
context.subscriptionsChangedFlow().toListWithTimeout()
}
delay(100)
subInfoListener?.onSubscriptionsChanged()
assertThat(listDeferred.await()).hasSize(2)
}
}