IMS-VT: Optimize handling of orientation requests
-Invoking setInCallAllowsOrientationChange API triggers
multiple events which send data across binder. This
could cause performance degradations in some cases.
-Enable/disable orientation listeners when primary call
changes
Change-Id: I457141ec6db7b5234be6aa537d39892e61efff6e
diff --git a/InCallUI/src/com/android/incallui/InCallOrientationEventListener.java b/InCallUI/src/com/android/incallui/InCallOrientationEventListener.java
index d3334a3..3cab6dc 100644
--- a/InCallUI/src/com/android/incallui/InCallOrientationEventListener.java
+++ b/InCallUI/src/com/android/incallui/InCallOrientationEventListener.java
@@ -62,6 +62,7 @@
* Cache the current rotation of the device.
*/
private static int sCurrentOrientation = SCREEN_ORIENTATION_0;
+ private boolean mEnabled = false;
public InCallOrientationEventListener(Context context) {
super(context);
@@ -97,7 +98,13 @@
* @param notify true or false. Notify device orientation changed if true.
*/
public void enable(boolean notify) {
+ if (mEnabled) {
+ Log.v(this, "enable: Orientation listener is already enabled. Ignoring...");
+ return;
+ }
+
super.enable();
+ mEnabled = true;
if (notify) {
InCallPresenter.getInstance().onDeviceOrientationChange(sCurrentOrientation);
}
@@ -111,6 +118,26 @@
}
/**
+ * Disables the OrientationEventListener.
+ */
+ public void disable() {
+ if (!mEnabled) {
+ Log.v(this, "enable: Orientation listener is already disabled. Ignoring...");
+ return;
+ }
+
+ mEnabled = false;
+ super.disable();
+ }
+
+ /**
+ * Returns true the OrientationEventListener is enabled, false otherwise.
+ */
+ public boolean isEnabled() {
+ return mEnabled;
+ }
+
+ /**
* Converts sensor rotation in degrees to screen orientation constants.
* @param rotation sensor rotation angle in degrees
* @return Screen orientation angle in degrees (0, 90, 180, 270). Returns -1 for degrees not
diff --git a/InCallUI/src/com/android/incallui/VideoCallPresenter.java b/InCallUI/src/com/android/incallui/VideoCallPresenter.java
index cd10a99..e5fc7d8 100644
--- a/InCallUI/src/com/android/incallui/VideoCallPresenter.java
+++ b/InCallUI/src/com/android/incallui/VideoCallPresenter.java
@@ -557,6 +557,7 @@
updateCameraSelection(newPrimaryCall);
enterVideoMode(newPrimaryCall);
}
+ checkForOrientationAllowedChange(newPrimaryCall);
}
private boolean isVideoMode() {