mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-21 17:29:32 +01:00
@@ -400,6 +400,7 @@ public class ConversationActivity extends PassphraseRequiredActivity
|
||||
private ConversationGroupViewModel groupViewModel;
|
||||
private MentionsPickerViewModel mentionsViewModel;
|
||||
private GroupCallViewModel groupCallViewModel;
|
||||
private VoiceRecorderWakeLock voiceRecorderWakeLock;
|
||||
|
||||
private LiveRecipient recipient;
|
||||
private long threadId;
|
||||
@@ -432,6 +433,8 @@ public class ConversationActivity extends PassphraseRequiredActivity
|
||||
return;
|
||||
}
|
||||
|
||||
voiceRecorderWakeLock = new VoiceRecorderWakeLock(this);
|
||||
|
||||
new FullscreenHelper(this).showSystemUI();
|
||||
|
||||
ConversationIntents.Args args = ConversationIntents.Args.from(getIntent());
|
||||
@@ -3033,12 +3036,14 @@ public class ConversationActivity extends PassphraseRequiredActivity
|
||||
|
||||
@Override
|
||||
public void onRecorderLocked() {
|
||||
voiceRecorderWakeLock.acquire();
|
||||
updateToggleButtonState();
|
||||
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRecorderFinished() {
|
||||
voiceRecorderWakeLock.release();
|
||||
updateToggleButtonState();
|
||||
Vibrator vibrator = ServiceUtil.getVibrator(this);
|
||||
vibrator.vibrate(20);
|
||||
@@ -3095,6 +3100,7 @@ public class ConversationActivity extends PassphraseRequiredActivity
|
||||
|
||||
@Override
|
||||
public void onRecorderCanceled() {
|
||||
voiceRecorderWakeLock.release();
|
||||
updateToggleButtonState();
|
||||
Vibrator vibrator = ServiceUtil.getVibrator(this);
|
||||
vibrator.vibrate(50);
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
package org.thoughtcrime.securesms.conversation
|
||||
|
||||
import android.os.Build
|
||||
import android.os.PowerManager
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.lifecycle.DefaultLifecycleObserver
|
||||
import androidx.lifecycle.LifecycleOwner
|
||||
import org.thoughtcrime.securesms.util.WakeLockUtil
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
/**
|
||||
* Holds on to and manages a wake-lock for the device proximity sensor.
|
||||
*
|
||||
* This class will register itself as an observe of the given activity's lifecycle and automatically
|
||||
* release the lock if it holds one in onPause
|
||||
*/
|
||||
class VoiceRecorderWakeLock(
|
||||
private val activity: ComponentActivity
|
||||
) : DefaultLifecycleObserver {
|
||||
|
||||
private var wakeLock: PowerManager.WakeLock? = null
|
||||
|
||||
init {
|
||||
activity.lifecycle.addObserver(this)
|
||||
}
|
||||
|
||||
fun acquire() {
|
||||
synchronized(this) {
|
||||
if (wakeLock?.isHeld == true) {
|
||||
return
|
||||
}
|
||||
|
||||
if (Build.VERSION.SDK_INT >= 21) {
|
||||
wakeLock = WakeLockUtil.acquire(activity, PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK, TimeUnit.HOURS.toMillis(1), "voiceRecorder")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun release() {
|
||||
synchronized(this) {
|
||||
if (wakeLock?.isHeld == true) {
|
||||
wakeLock?.release()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onPause(owner: LifecycleOwner) {
|
||||
release()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user