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

Supporting rotation during voice recordings #4556

Merged
merged 7 commits into from
Nov 29, 2021
Merged

Conversation

ouchadam
Copy link
Contributor

Fixes #4067 Allows the device to rotate whilst recording a voice message

  • Makes the VoiceMessagePlaybackTracker a singleton to avoid losing any state on activity destruction (means we need to be extra careful with releasing the listeners)
  • Holds onto the recording start time in order to maintain the current recording length after rotation
  • Checks if the device is actively recording a voice message and going through a configuration change, if so we don't stop the recording or save any drafts
BEFORE AFTER
before-vm-rotation after-vm-rotation

…rotation

- this means we need to be extra careful about releasing any listeners
@@ -158,22 +162,23 @@ class VoiceMessageRecorderView @JvmOverloads constructor(
dragState = newDragState
}

private fun startRecordingTicker() {
private fun startRecordingTicker(startFromLocked: Boolean, startAt: Long) {
val startMs = ((System.currentTimeMillis() - startAt)).coerceAtLeast(0)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

ideally we'd have a Clock abstraction to avoid directly calling into the system time, would help out massively for testing

what do people think?

Copy link
Member

Choose a reason for hiding this comment

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

Good idea!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added 7d2c8e6

@github-actions
Copy link

github-actions bot commented Nov 24, 2021

Unit Test Results

  66 files  ±0    66 suites  ±0   1m 10s ⏱️ +6s
135 tests ±0  135 ✔️ ±0  0 💤 ±0  0 ±0 
418 runs  ±0  418 ✔️ ±0  0 💤 ±0  0 ±0 

Results for commit fdfac8d. ± Comparison against base commit 32441eb.

♻️ This comment has been updated with latest results.

Copy link
Member

@bmarty bmarty left a comment

Choose a reason for hiding this comment

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

LGTM, I did not test it though.

@@ -158,22 +162,23 @@ class VoiceMessageRecorderView @JvmOverloads constructor(
dragState = newDragState
}

private fun startRecordingTicker() {
private fun startRecordingTicker(startFromLocked: Boolean, startAt: Long) {
val startMs = ((System.currentTimeMillis() - startAt)).coerceAtLeast(0)
Copy link
Member

Choose a reason for hiding this comment

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

Good idea!

Copy link
Member

@bmarty bmarty 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 update. 2 more remarks but you can merge the PR whenever you want.


class DefaultClock @Inject constructor() : Clock {
override fun epochMillis(): Long {
return System.currentTimeMillis()
Copy link
Member

Choose a reason for hiding this comment

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

A bit out of scope of this PR, but we will probably want to replace all System.currentTimeMillis() usages by this new Clock?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

💯 that would be the dream! I'll create an issue

Copy link
Contributor Author

Choose a reason for hiding this comment

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

import javax.inject.Inject

interface Clock {
fun epochMillis(): Long
Copy link
Member

Choose a reason for hiding this comment

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

It's worth noting that the current impl rely on the system date, which can be set by the user (and at any time).
This can lead to bugs...
Also when the clock change automatically (Winter?Summer time) we can have bugs (my experience is talking here).

Copy link
Contributor Author

@ouchadam ouchadam Nov 25, 2021

Choose a reason for hiding this comment

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

unless we use a server time is there a way to avoid this? analytics SDKs will rely on a mix of server received at timestamps and client sent at

the currentTimeMillis epoch is UTC, unless a user sets a custom time using their local time (eg UTC+11) but with UTC+0 timezone 😅

it's becoming rarer for users to misconfigure their time due to automatic network times and a lot apps/websites start complaining about SSL errors if the current time/date is wildly wrong

EDIT: I'll add some java doc to explain this time could be incorrect

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@bmarty bmarty merged commit b59ae53 into develop Nov 29, 2021
@bmarty bmarty deleted the feature/adm/voice-rotation branch November 29, 2021 10:40
@marclaporte
Copy link

I have this issue on Element v1.4.32 (2022-08-10) from F-Droid.

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.

Voice Message stops recording on Phone Rotation
3 participants