Merge "Revert "Create CallStateRepository.isInCallFlow"" into 24D1-dev am: 134635786f

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Settings/+/27145129

Change-Id: Ica49442da20fcea404ad95a2591506991a8e55b4
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Priyanka Advani
2024-04-29 22:48:38 +00:00
committed by Automerger Merge Worker
8 changed files with 37 additions and 217 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2024 The Android Open Source Project
* 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.
@@ -17,7 +17,6 @@
package com.android.settings.network.telephony
import android.content.Context
import android.telephony.SubscriptionManager
import android.telephony.TelephonyCallback
import android.telephony.TelephonyManager
import androidx.test.core.app.ApplicationProvider
@@ -37,7 +36,7 @@ import org.mockito.kotlin.mock
import org.mockito.kotlin.spy
@RunWith(AndroidJUnit4::class)
class CallStateRepositoryTest {
class CallStateFlowTest {
private var callStateListener: TelephonyCallback.CallStateListener? = null
private val mockTelephonyManager = mock<TelephonyManager> {
@@ -48,24 +47,13 @@ class CallStateRepositoryTest {
}
}
private val mockSubscriptionManager = mock<SubscriptionManager> {
on { activeSubscriptionIdList } doReturn intArrayOf(SUB_ID)
on { addOnSubscriptionsChangedListener(any(), any()) } doAnswer {
val listener = it.arguments[1] as SubscriptionManager.OnSubscriptionsChangedListener
listener.onSubscriptionsChanged()
}
}
private val context: Context = spy(ApplicationProvider.getApplicationContext()) {
on { getSystemService(TelephonyManager::class.java) } doReturn mockTelephonyManager
on { subscriptionManager } doReturn mockSubscriptionManager
}
private val repository = CallStateRepository(context)
@Test
fun callStateFlow_initial_sendInitialState() = runBlocking {
val flow = repository.callStateFlow(SUB_ID)
val flow = context.callStateFlow(SUB_ID)
val state = flow.firstWithTimeoutOrNull()
@@ -75,7 +63,7 @@ class CallStateRepositoryTest {
@Test
fun callStateFlow_changed_sendChangedState() = runBlocking {
val listDeferred = async {
repository.callStateFlow(SUB_ID).toListWithTimeout()
context.callStateFlow(SUB_ID).toListWithTimeout()
}
delay(100)
@@ -86,27 +74,6 @@ class CallStateRepositoryTest {
.inOrder()
}
@Test
fun isInCallFlow_initial() = runBlocking {
val isInCall = repository.isInCallFlow().firstWithTimeoutOrNull()
assertThat(isInCall).isFalse()
}
@Test
fun isInCallFlow_changed_sendChangedState() = runBlocking {
val listDeferred = async {
repository.isInCallFlow().toListWithTimeout()
}
delay(100)
callStateListener?.onCallStateChanged(TelephonyManager.CALL_STATE_RINGING)
assertThat(listDeferred.await())
.containsExactly(false, true)
.inOrder()
}
private companion object {
const val SUB_ID = 1
}

View File

@@ -1,84 +0,0 @@
/*
* Copyright (C) 2024 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 androidx.test.core.app.ApplicationProvider
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.android.settings.network.SatelliteRepository
import com.android.settingslib.spa.testutils.firstWithTimeoutOrNull
import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.runBlocking
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.kotlin.doReturn
import org.mockito.kotlin.mock
import org.mockito.kotlin.stub
@RunWith(AndroidJUnit4::class)
class SubscriptionActivationRepositoryTest {
private val context: Context = ApplicationProvider.getApplicationContext()
private val mockCallStateRepository = mock<CallStateRepository>()
private val mockSatelliteRepository = mock<SatelliteRepository>()
private val repository =
SubscriptionActivationRepository(context, mockCallStateRepository, mockSatelliteRepository)
@Test
fun isActivationChangeableFlow_changeable() = runBlocking {
mockCallStateRepository.stub {
on { isInCallFlow() } doReturn flowOf(false)
}
mockSatelliteRepository.stub {
on { getIsSessionStartedFlow() } doReturn flowOf(false)
}
val changeable = repository.isActivationChangeableFlow().firstWithTimeoutOrNull()
assertThat(changeable).isTrue()
}
@Test
fun isActivationChangeableFlow_inCall_notChangeable() = runBlocking {
mockCallStateRepository.stub {
on { isInCallFlow() } doReturn flowOf(true)
}
mockSatelliteRepository.stub {
on { getIsSessionStartedFlow() } doReturn flowOf(false)
}
val changeable = repository.isActivationChangeableFlow().firstWithTimeoutOrNull()
assertThat(changeable).isFalse()
}
@Test
fun isActivationChangeableFlow_satelliteSessionStarted_notChangeable() = runBlocking {
mockCallStateRepository.stub {
on { isInCallFlow() } doReturn flowOf(false)
}
mockSatelliteRepository.stub {
on { getIsSessionStartedFlow() } doReturn flowOf(true)
}
val changeable = repository.isActivationChangeableFlow().firstWithTimeoutOrNull()
assertThat(changeable).isFalse()
}
}

View File

@@ -58,9 +58,7 @@ class WifiCallingPreferenceControllerTest {
}
private val preferenceScreen = PreferenceManager(context).createPreferenceScreen(context)
private val mockCallStateRepository = mock<CallStateRepository> {
on { callStateFlow(SUB_ID) } doReturn flowOf(TelephonyManager.CALL_STATE_IDLE)
}
private var callState = TelephonyManager.CALL_STATE_IDLE
private val mockWifiCallingRepository = mock<WifiCallingRepository> {
on { getWiFiCallingMode() } doReturn ImsMmTelManager.WIFI_MODE_UNKNOWN
@@ -73,7 +71,7 @@ class WifiCallingPreferenceControllerTest {
private val controller = WifiCallingPreferenceController(
context = context,
key = TEST_KEY,
callStateRepository = mockCallStateRepository,
callStateFlowFactory = { flowOf(callState) },
wifiCallingRepositoryFactory = { mockWifiCallingRepository },
).init(subId = SUB_ID, callingPreferenceCategoryController)
@@ -114,9 +112,7 @@ class WifiCallingPreferenceControllerTest {
@Test
fun isEnabled_callIdle_enabled() = runBlocking {
mockCallStateRepository.stub {
on { callStateFlow(SUB_ID) } doReturn flowOf(TelephonyManager.CALL_STATE_IDLE)
}
callState = TelephonyManager.CALL_STATE_IDLE
controller.onViewCreated(TestLifecycleOwner())
delay(100)
@@ -126,9 +122,7 @@ class WifiCallingPreferenceControllerTest {
@Test
fun isEnabled_notCallIdle_disabled() = runBlocking {
mockCallStateRepository.stub {
on { callStateFlow(SUB_ID) } doReturn flowOf(TelephonyManager.CALL_STATE_RINGING)
}
callState = TelephonyManager.CALL_STATE_RINGING
controller.onViewCreated(TestLifecycleOwner())
delay(100)