Improve code further with some conditionals & audio handling

Signed-off-by: Mario Danic <mario@lovelyhq.com>
This commit is contained in:
Mario Danic 2019-02-27 18:47:28 +01:00
parent 2fb58e8cab
commit 52d522ed37
2 changed files with 41 additions and 8 deletions

View file

@ -496,8 +496,19 @@ public class CallController extends BaseController {
final MagicAudioManager.AudioDevice device, final Set<MagicAudioManager.AudioDevice> 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);

View file

@ -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();
}