VideoCalling UI adds the init value

Bug: 367696228
Test: atest VideoCallingPreferenceControllerTest
Flag: EXEMPT bugfix
Change-Id: I1a1de9e3174a9211be619c96c104607f831b51a2
This commit is contained in:
songferngwang
2024-10-03 13:49:56 +00:00
parent 1955144ffc
commit 8e6bc6f289
2 changed files with 57 additions and 8 deletions

View File

@@ -44,12 +44,12 @@ constructor(
context: Context, context: Context,
key: String, key: String,
private val callStateRepository: CallStateRepository = CallStateRepository(context), private val callStateRepository: CallStateRepository = CallStateRepository(context),
private val videoCallingRepository: VideoCallingRepository = VideoCallingRepository(context),
) : TogglePreferenceController(context, key), On4gLteUpdateListener { ) : TogglePreferenceController(context, key), On4gLteUpdateListener {
private var subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID private var subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID
private var preference: TwoStatePreference? = null private var preference: TwoStatePreference? = null
private var callingPreferenceCategoryController: CallingPreferenceCategoryController? = null private var callingPreferenceCategoryController: CallingPreferenceCategoryController? = null
private val repository = VideoCallingRepository(context)
private var videoCallEditable = false private var videoCallEditable = false
private var isInCall = false private var isInCall = false
@@ -71,14 +71,18 @@ constructor(
override fun displayPreference(screen: PreferenceScreen) { override fun displayPreference(screen: PreferenceScreen) {
super.displayPreference(screen) super.displayPreference(screen)
preference = screen.findPreference(preferenceKey) preference = screen.findPreference(preferenceKey)
Log.d(TAG, "init ui")
preference?.isVisible = false
callingPreferenceCategoryController?.updateChildVisible(preferenceKey, false)
} }
override fun onViewCreated(viewLifecycleOwner: LifecycleOwner) { override fun onViewCreated(viewLifecycleOwner: LifecycleOwner) {
repository.isVideoCallReadyFlow(subId).collectLatestWithLifecycle(viewLifecycleOwner) { videoCallingRepository.isVideoCallReadyFlow(subId)
isReady -> .collectLatestWithLifecycle(viewLifecycleOwner) { isReady ->
preference?.isVisible = isReady Log.d(TAG, "isVideoCallReadyFlow: update visible")
callingPreferenceCategoryController?.updateChildVisible(preferenceKey, isReady) preference?.isVisible = isReady
} callingPreferenceCategoryController?.updateChildVisible(preferenceKey, isReady)
}
callStateRepository.callStateFlow(subId).collectLatestWithLifecycle(viewLifecycleOwner) { callStateRepository.callStateFlow(subId).collectLatestWithLifecycle(viewLifecycleOwner) {
callState -> callState ->
isInCall = callState != TelephonyManager.CALL_STATE_IDLE isInCall = callState != TelephonyManager.CALL_STATE_IDLE
@@ -129,10 +133,10 @@ constructor(
class VideoCallingSearchItem(private val context: Context) : class VideoCallingSearchItem(private val context: Context) :
MobileNetworkSettingsSearchItem { MobileNetworkSettingsSearchItem {
private val repository = VideoCallingRepository(context) private val videoCallingRepository = VideoCallingRepository(context)
private fun isAvailable(subId: Int): Boolean = runBlocking { private fun isAvailable(subId: Int): Boolean = runBlocking {
repository.isVideoCallReadyFlow(subId).first() videoCallingRepository.isVideoCallReadyFlow(subId).first()
} }
override fun getSearchResult(subId: Int): MobileNetworkSettingsSearchResult? { override fun getSearchResult(subId: Int): MobileNetworkSettingsSearchResult? {

View File

@@ -47,6 +47,8 @@ class VideoCallingPreferenceControllerTest {
private val context: Context = ApplicationProvider.getApplicationContext() private val context: Context = ApplicationProvider.getApplicationContext()
private val mockCallStateRepository = mock<CallStateRepository> {} private val mockCallStateRepository = mock<CallStateRepository> {}
private val mockVideoCallingRepository = mock<VideoCallingRepository> {}
private var controller = private var controller =
spy( spy(
@@ -54,6 +56,7 @@ class VideoCallingPreferenceControllerTest {
context = context, context = context,
key = TEST_KEY, key = TEST_KEY,
callStateRepository = mockCallStateRepository, callStateRepository = mockCallStateRepository,
videoCallingRepository = mockVideoCallingRepository
) )
) { ) {
on { queryImsState(SUB_ID) } doReturn mockVtQueryImsState on { queryImsState(SUB_ID) } doReturn mockVtQueryImsState
@@ -70,6 +73,42 @@ class VideoCallingPreferenceControllerTest {
controller.displayPreference(preferenceScreen) controller.displayPreference(preferenceScreen)
} }
@Test
fun displayPreference_uiInitState_isHidden() {
assertThat(preference.isVisible).isFalse()
}
@Test
fun onViewCreated_videoCallIsNotReady_isHidden() = runBlocking {
mockVideoCallingRepository.stub {
on { isVideoCallReadyFlow(SUB_ID) } doReturn flowOf(false)
}
mockCallStateRepository.stub {
on { callStateFlow(SUB_ID) } doReturn flowOf(TelephonyManager.CALL_STATE_IDLE)
}
controller.onViewCreated(TestLifecycleOwner())
delay(100)
assertThat(preference.isVisible).isFalse()
}
@Test
fun onViewCreated_videoCallIsNotReady_isShown() = runBlocking {
mockVideoCallingRepository.stub {
on { isVideoCallReadyFlow(SUB_ID) } doReturn flowOf(true)
}
mockCallStateRepository.stub {
on { callStateFlow(SUB_ID) } doReturn flowOf(TelephonyManager.CALL_STATE_IDLE)
}
controller.onViewCreated(TestLifecycleOwner())
delay(100)
assertThat(preference.isVisible).isTrue()
}
@Test @Test
fun updateState_4gLteOff_disabledAndUnchecked() { fun updateState_4gLteOff_disabledAndUnchecked() {
mockQueryVoLteState.stub { on { isEnabledByUser } doReturn false } mockQueryVoLteState.stub { on { isEnabledByUser } doReturn false }
@@ -82,6 +121,9 @@ class VideoCallingPreferenceControllerTest {
@Test @Test
fun updateState_4gLteOnWithoutCall_enabledAndChecked() = runBlocking { fun updateState_4gLteOnWithoutCall_enabledAndChecked() = runBlocking {
mockVideoCallingRepository.stub {
on { isVideoCallReadyFlow(SUB_ID) } doReturn flowOf(true)
}
mockVtQueryImsState.stub { mockVtQueryImsState.stub {
on { isEnabledByUser } doReturn true on { isEnabledByUser } doReturn true
on { isAllowUserControl } doReturn true on { isAllowUserControl } doReturn true
@@ -101,6 +143,9 @@ class VideoCallingPreferenceControllerTest {
@Test @Test
fun updateState_4gLteOnWithCall_disabledAndChecked() = runBlocking { fun updateState_4gLteOnWithCall_disabledAndChecked() = runBlocking {
mockVideoCallingRepository.stub {
on { isVideoCallReadyFlow(SUB_ID) } doReturn flowOf(true)
}
mockVtQueryImsState.stub { mockVtQueryImsState.stub {
on { isEnabledByUser } doReturn true on { isEnabledByUser } doReturn true
on { isAllowUserControl } doReturn true on { isAllowUserControl } doReturn true