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

Commit 7c6b213c authored by SongFerng Wang's avatar SongFerng Wang Committed by Android (Google) Code Review
Browse files

Merge "VideoCalling UI adds the init value" into main

parents 5087754b 8e6bc6f2
Loading
Loading
Loading
Loading
+12 −8
Original line number Diff line number Diff line
@@ -44,12 +44,12 @@ constructor(
    context: Context,
    key: String,
    private val callStateRepository: CallStateRepository = CallStateRepository(context),
    private val videoCallingRepository: VideoCallingRepository = VideoCallingRepository(context),
) : TogglePreferenceController(context, key), On4gLteUpdateListener {

    private var subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID
    private var preference: TwoStatePreference? = null
    private var callingPreferenceCategoryController: CallingPreferenceCategoryController? = null
    private val repository = VideoCallingRepository(context)

    private var videoCallEditable = false
    private var isInCall = false
@@ -71,11 +71,15 @@ constructor(
    override fun displayPreference(screen: PreferenceScreen) {
        super.displayPreference(screen)
        preference = screen.findPreference(preferenceKey)
        Log.d(TAG, "init ui")
        preference?.isVisible = false
        callingPreferenceCategoryController?.updateChildVisible(preferenceKey, false)
    }

    override fun onViewCreated(viewLifecycleOwner: LifecycleOwner) {
        repository.isVideoCallReadyFlow(subId).collectLatestWithLifecycle(viewLifecycleOwner) {
            isReady ->
        videoCallingRepository.isVideoCallReadyFlow(subId)
            .collectLatestWithLifecycle(viewLifecycleOwner) { isReady ->
                Log.d(TAG, "isVideoCallReadyFlow: update visible")
                preference?.isVisible = isReady
                callingPreferenceCategoryController?.updateChildVisible(preferenceKey, isReady)
            }
@@ -129,10 +133,10 @@ constructor(

        class VideoCallingSearchItem(private val context: Context) :
            MobileNetworkSettingsSearchItem {
            private val repository = VideoCallingRepository(context)
            private val videoCallingRepository = VideoCallingRepository(context)

            private fun isAvailable(subId: Int): Boolean = runBlocking {
                repository.isVideoCallReadyFlow(subId).first()
                videoCallingRepository.isVideoCallReadyFlow(subId).first()
            }

            override fun getSearchResult(subId: Int): MobileNetworkSettingsSearchResult? {
+45 −0
Original line number Diff line number Diff line
@@ -47,6 +47,8 @@ class VideoCallingPreferenceControllerTest {
    private val context: Context = ApplicationProvider.getApplicationContext()

    private val mockCallStateRepository = mock<CallStateRepository> {}
    private val mockVideoCallingRepository = mock<VideoCallingRepository> {}


    private var controller =
        spy(
@@ -54,6 +56,7 @@ class VideoCallingPreferenceControllerTest {
                context = context,
                key = TEST_KEY,
                callStateRepository = mockCallStateRepository,
                videoCallingRepository = mockVideoCallingRepository
            )
        ) {
            on { queryImsState(SUB_ID) } doReturn mockVtQueryImsState
@@ -70,6 +73,42 @@ class VideoCallingPreferenceControllerTest {
        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
    fun updateState_4gLteOff_disabledAndUnchecked() {
        mockQueryVoLteState.stub { on { isEnabledByUser } doReturn false }
@@ -82,6 +121,9 @@ class VideoCallingPreferenceControllerTest {

    @Test
    fun updateState_4gLteOnWithoutCall_enabledAndChecked() = runBlocking {
        mockVideoCallingRepository.stub {
            on { isVideoCallReadyFlow(SUB_ID) } doReturn flowOf(true)
        }
        mockVtQueryImsState.stub {
            on { isEnabledByUser } doReturn true
            on { isAllowUserControl } doReturn true
@@ -101,6 +143,9 @@ class VideoCallingPreferenceControllerTest {

    @Test
    fun updateState_4gLteOnWithCall_disabledAndChecked() = runBlocking {
        mockVideoCallingRepository.stub {
            on { isVideoCallReadyFlow(SUB_ID) } doReturn flowOf(true)
        }
        mockVtQueryImsState.stub {
            on { isEnabledByUser } doReturn true
            on { isAllowUserControl } doReturn true