Loading src/com/android/settings/network/telephony/VideoCallingPreferenceController.kt +12 −8 Original line number Diff line number Diff line Loading @@ -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 Loading @@ -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) } Loading Loading @@ -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? { Loading tests/spa_unit/src/com/android/settings/network/telephony/VideoCallingPreferenceControllerTest.kt +45 −0 Original line number Diff line number Diff line Loading @@ -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( Loading @@ -54,6 +56,7 @@ class VideoCallingPreferenceControllerTest { context = context, key = TEST_KEY, callStateRepository = mockCallStateRepository, videoCallingRepository = mockVideoCallingRepository ) ) { on { queryImsState(SUB_ID) } doReturn mockVtQueryImsState Loading @@ -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 } Loading @@ -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 Loading @@ -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 Loading Loading
src/com/android/settings/network/telephony/VideoCallingPreferenceController.kt +12 −8 Original line number Diff line number Diff line Loading @@ -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 Loading @@ -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) } Loading Loading @@ -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? { Loading
tests/spa_unit/src/com/android/settings/network/telephony/VideoCallingPreferenceControllerTest.kt +45 −0 Original line number Diff line number Diff line Loading @@ -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( Loading @@ -54,6 +56,7 @@ class VideoCallingPreferenceControllerTest { context = context, key = TEST_KEY, callStateRepository = mockCallStateRepository, videoCallingRepository = mockVideoCallingRepository ) ) { on { queryImsState(SUB_ID) } doReturn mockVtQueryImsState Loading @@ -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 } Loading @@ -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 Loading @@ -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 Loading