From 52d522ed375fc2f078428ef1bb69d0f4055d7035 Mon Sep 17 00:00:00 2001 From: Mario Danic Date: Wed, 27 Feb 2019 18:47:28 +0100 Subject: [PATCH] Improve code further with some conditionals & audio handling Signed-off-by: Mario Danic --- .../talk/controllers/CallController.java | 11 ++++++ .../talk/utils/power/PowerManagerUtils.java | 38 +++++++++++++++---- 2 files changed, 41 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/controllers/CallController.java b/app/src/main/java/com/nextcloud/talk/controllers/CallController.java index 3f266cc2c..968046319 100644 --- a/app/src/main/java/com/nextcloud/talk/controllers/CallController.java +++ b/app/src/main/java/com/nextcloud/talk/controllers/CallController.java @@ -496,8 +496,19 @@ public class CallController extends BaseController { final MagicAudioManager.AudioDevice device, final Set availableDevices) { Log.d(TAG, "onAudioManagerDevicesChanged: " + availableDevices + ", " + "selected: " + device); + + final boolean shouldDisableProximityLock = (device.equals(MagicAudioManager.AudioDevice.WIRED_HEADSET) + || device.equals(MagicAudioManager.AudioDevice.SPEAKER_PHONE) + || device.equals(MagicAudioManager.AudioDevice.BLUETOOTH)); + + if (shouldDisableProximityLock) { + powerManagerUtils.updatePhoneState(PowerManagerUtils.PhoneState.WITHOUT_PROXIMITY_SENSOR_LOCK); + } else { + powerManagerUtils.updatePhoneState(PowerManagerUtils.PhoneState.WITH_PROXIMITY_SENSOR_LOCK); + } } + private void cameraInitialization() { videoCapturer = createCameraCapturer(cameraEnumerator); diff --git a/app/src/main/java/com/nextcloud/talk/utils/power/PowerManagerUtils.java b/app/src/main/java/com/nextcloud/talk/utils/power/PowerManagerUtils.java index 0d7c10ef4..f2370639a 100644 --- a/app/src/main/java/com/nextcloud/talk/utils/power/PowerManagerUtils.java +++ b/app/src/main/java/com/nextcloud/talk/utils/power/PowerManagerUtils.java @@ -134,16 +134,31 @@ public class PowerManagerUtils { private synchronized void setWakeLockState(WakeLockState newState) { switch(newState) { case FULL: - fullLock.acquire(); - partialLock.acquire(); - wifiLock.acquire(); + if (!fullLock.isHeld()) { + fullLock.acquire(); + } + + if (!partialLock.isHeld()) { + partialLock.acquire(); + } + + if (!wifiLock.isHeld()) { + wifiLock.acquire(); + } + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { proximityLock.release(); } break; case PARTIAL: - partialLock.acquire(); - wifiLock.acquire(); + if (!partialLock.isHeld()) { + partialLock.acquire(); + } + + if (!wifiLock.isHeld()) { + wifiLock.acquire(); + } + fullLock.release(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { proximityLock.release(); @@ -158,9 +173,16 @@ public class PowerManagerUtils { } break; case PROXIMITY: - partialLock.acquire(); - wifiLock.acquire(); - fullLock.release(); + if (!partialLock.isHeld()) { + partialLock.acquire(); + } + + if (!wifiLock.isHeld()) { + wifiLock.acquire(); + } + fullLock.release( + + ); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { proximityLock.acquire(); }