Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support element call widget (PSG-627) #6616

Merged
merged 20 commits into from
Jul 22, 2022
Merged

Conversation

onurays
Copy link
Contributor

@onurays onurays commented Jul 21, 2022

Type of change

  • Feature
  • Bugfix
  • Technical
  • Other :

Content

We implement Element Call as a widget with some extra functionalities.

Motivation and context

Since this is a call widget we need to make it run in the background, provide a picture-in-picture mode and also preserve the current native WebRTC call implementation for rooms which does not have an active Element Call widget.

This PR is a cherry-pick version of PR #6464 which additionally implements a Bluetooth connection with push-to-talk devices. Since it is an experimental PR with a hardcoded device name and service address without a good UX, we wanted to create this PR to be able to merge into develop.

Screenshots / GIFs

element_call_widget.mp4

Tests

  • Request an invite (from me?) to the room which has an active Element Call widget
  • Click voice call button and this should navigate you to the widget
  • Choose a DM room without EC widget and you should be able to make a regular voice call with the same button

Tested devices

  • Physical
  • Emulator
  • OS version(s):

Checklist

@onurays onurays requested review from a team and mnaturel and removed request for a team July 21, 2022 14:28
@@ -28,7 +28,8 @@ private val DEFINED_TYPES by lazy {
WidgetType.StickerPicker,
WidgetType.Grafana,
WidgetType.Custom,
WidgetType.IntegrationManager
WidgetType.IntegrationManager,
WidgetType.ElementCall
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we have a trailing comma for the last item?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Of course, done.

* @param request WebView permission request of onPermissionRequest function
* @return true if WebView permissions are already granted, false otherwise
*/
fun checkWebViewPermissions(activity: Activity, request: PermissionRequest): Boolean {
Copy link
Contributor

@mnaturel mnaturel Jul 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we could extract this method into a dedicated use case such as CheckWebViewPermissionsUseCase? This way, it may be possible to inject the ApplicationContext instead of passing the activity as an argument.

We could also add unit tests on it as bonus.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea, done.

@@ -26,4 +26,5 @@ sealed class WidgetAction : VectorViewModelAction {
object DeleteWidget : WidgetAction()
object RevokeWidget : WidgetAction()
object OnTermsReviewed : WidgetAction()
object HangupElementCall : WidgetAction()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we rename the action CloseWidget to avoid introducing too specific action?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed.

override fun onUserLeaveHint() {
super.onUserLeaveHint()
val widgetArgs: WidgetArgs? = intent?.extras?.getParcelable(Mavericks.KEY_ARG)
if (widgetArgs?.kind == WidgetKind.ELEMENT_CALL) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am wondering if we should move if (widgetArgs?.kind == WidgetKind.ELEMENT_CALL) inside the enterPictureInPicture. Like this:

override fun onUserLeaveHint() {
    super.onUserLeaveHint()
    enterPictureInPicture()
}

private fun enterPictureInPicture() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        val widgetArgs: WidgetArgs? = intent?.extras?.getParcelable(Mavericks.KEY_ARG)
        val params = when(widgetArgs?.kind) {
            WidgetKind.ELEMENT_CALL -> createElementCallPipParams()
                else -> null
        }
        params?.let {
           enterPictureInPictureMode(it)
       }
    }
}

This way we could easily add picture in picture for other widget in the future.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactored.

Copy link
Contributor

@mnaturel mnaturel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work! I have just added some suggestions. I have just one question about the picture in picture mode. Should/can we do something to have a better UI in this mode? Now, it looks like a reduced version of the current larger UI.

@mnaturel
Copy link
Contributor

I have also seen there is one security hotspot to be reviewed in the Sonar analysis. It is about registering a broadcast receiver. I think it is worth checking if everything is okay.

@onurays onurays requested a review from mnaturel July 22, 2022 11:50

@Before
fun setup() {
MockKAnnotations.init(this)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure this is needed. MockKAnnotations.init() is useful when we use the annotations for mockking objects like @MockK.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, I started with using @Mockk then forgot to remove it. Done.


@Test
fun `given an audio permission is granted when the web client requests audio permission then use case returns true`() {
val permissionRequest = givenAPermissionRequest(arrayOf(PermissionRequest.RESOURCE_AUDIO_CAPTURE))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To ease the reading in tests, we should separate them in 3 blocks (given, when, then). We would have something like:

val permissionRequest = givenAPermissionRequest(arrayOf(PermissionRequest.RESOURCE_AUDIO_CAPTURE))
every { checkSelfPermission(activity.applicationContext, any()) } returns PackageManager.PERMISSION_GRANTED

val result = checkWebViewPermissionsUseCase.execute(activity, permissionRequest)

result shouldBe true

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


every { checkSelfPermission(activity.applicationContext, any()) } returns PackageManager.PERMISSION_GRANTED

checkWebViewPermissionsUseCase.execute(activity, permissionRequest) shouldBe true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we could add a verify bloc on the call to checkSelfPermission in the tests. For this test for example:

PERMISSIONS_FOR_AUDIO_IP_CALL.forEach { permission ->
    every { checkSelfPermission(activity.applicationContext, permission) }
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea, done.

@onurays
Copy link
Contributor Author

onurays commented Jul 22, 2022

Nice work! I have just added some suggestions. I have just one question about the picture in picture mode. Should/can we do something to have a better UI in this mode? Now, it looks like a reduced version of the current larger UI.

Web team made a CSS trick to show the mic in the middle of the PIP screen but I think it is not in production yet.

@onurays
Copy link
Contributor Author

onurays commented Jul 22, 2022

I have also seen there is one security hotspot to be reviewed in the Sonar analysis. It is about registering a broadcast receiver. I think it is worth checking if everything is okay.

LocalBroadcastManager is not working with PIP. I think this is not a big issue? We are using it in several places.

Copy link
Contributor

@mnaturel mnaturel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the updates!

@sonarqubecloud
Copy link

SonarCloud Quality Gate failed.    Quality Gate failed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot E 1 Security Hotspot
Code Smell A 2 Code Smells

16.1% 16.1% Coverage
0.0% 0.0% Duplication

@onurays onurays merged commit 75de805 into develop Jul 22, 2022
@onurays onurays deleted the feature/ons/element_call_widget branch July 22, 2022 16:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants