From 2fb58e8cabbed67c9674240d0d099e101af71577 Mon Sep 17 00:00:00 2001 From: Mario Danic Date: Wed, 27 Feb 2019 18:24:19 +0100 Subject: [PATCH] Improve orientation detection for Power management Signed-off-by: Mario Danic --- .../nextcloud/talk/controllers/CallController.java | 7 ++++++- .../nextcloud/talk/utils/power/PowerManagerUtils.java | 11 ++++++++++- 2 files changed, 16 insertions(+), 2 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 34e0d19d6..3f266cc2c 100644 --- a/app/src/main/java/com/nextcloud/talk/controllers/CallController.java +++ b/app/src/main/java/com/nextcloud/talk/controllers/CallController.java @@ -74,6 +74,7 @@ import com.nextcloud.talk.utils.animations.PulseAnimation; import com.nextcloud.talk.utils.bundle.BundleKeys; import com.nextcloud.talk.utils.database.user.UserUtils; import com.nextcloud.talk.utils.glide.GlideApp; +import com.nextcloud.talk.utils.power.PowerManagerUtils; import com.nextcloud.talk.utils.preferences.AppPreferences; import com.nextcloud.talk.utils.singletons.ApplicationWideCurrentRoomHolder; import com.nextcloud.talk.webrtc.*; @@ -209,6 +210,8 @@ public class CallController extends BaseController { private boolean hasExternalSignalingServer; private String conversationPassword; + private PowerManagerUtils powerManagerUtils; + public CallController(Bundle args) { super(args); NextcloudTalkApplication.getSharedApplication().getComponentApplication().inject(this); @@ -228,6 +231,7 @@ public class CallController extends BaseController { } isFromNotification = TextUtils.isEmpty(roomToken); + powerManagerUtils = new PowerManagerUtils(); } @Override @@ -717,7 +721,6 @@ public class CallController extends BaseController { if (localMediaStream != null && localMediaStream.videoTracks.size() > 0) { localMediaStream.videoTracks.get(0).setEnabled(enable); } - if (enable) { pipVideoView.setVisibility(View.VISIBLE); } else { @@ -1592,6 +1595,8 @@ public class CallController extends BaseController { @Subscribe(threadMode = ThreadMode.MAIN) public void onMessageEvent(ConfigurationChangeEvent configurationChangeEvent) { + powerManagerUtils.setOrientation(Objects.requireNonNull(getResources()).getConfiguration().orientation); + if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) { remoteRenderersLayout.setOrientation(LinearLayout.HORIZONTAL); } else if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) { 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 2e4f71c89..0d7c10ef4 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 @@ -25,6 +25,7 @@ package com.nextcloud.talk.utils.power; import android.annotation.SuppressLint; import android.content.Context; +import android.content.res.Configuration; import android.net.wifi.WifiManager; import android.os.Build; import android.os.PowerManager; @@ -50,6 +51,8 @@ public class PowerManagerUtils { private final boolean wifiLockEnforced; private boolean proximityDisabled = false; + private int orientation; + public enum PhoneState { IDLE, PROCESSING, //used when the phone is active but before the user should be alerted. @@ -65,6 +68,11 @@ public class PowerManagerUtils { PROXIMITY } + public void setOrientation(int newOrientation) { + orientation = newOrientation; + updateInCallWakeLockState(); + } + public PowerManagerUtils() { NextcloudTalkApplication.getSharedApplication().getComponentApplication().inject(this); @@ -84,6 +92,7 @@ public class PowerManagerUtils { wifiLock.setReferenceCounted(false); wifiLockEnforced = isWifiPowerActiveModeEnabled(context); + orientation = context.getResources().getConfiguration().orientation; } public void updatePhoneState(PhoneState state) { @@ -109,7 +118,7 @@ public class PowerManagerUtils { } private void updateInCallWakeLockState() { - if (wifiLockEnforced && !proximityDisabled) { + if (orientation != Configuration.ORIENTATION_LANDSCAPE && wifiLockEnforced && !proximityDisabled) { setWakeLockState(WakeLockState.PROXIMITY); } else { setWakeLockState(WakeLockState.FULL);