Эх сурвалжийг харах

Improve orientation detection for Power management

Signed-off-by: Mario Danic <mario@lovelyhq.com>
Mario Danic 6 жил өмнө
parent
commit
2fb58e8cab

+ 6 - 1
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) {

+ 10 - 1
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);