Merge "Fix call duration issue for conference" into atel.lnx.2.0-dev
diff --git a/InCallUI/src/com/android/incallui/InCallOrientationEventListener.java b/InCallUI/src/com/android/incallui/InCallOrientationEventListener.java
index 3cab6dc..ed10b73 100644
--- a/InCallUI/src/com/android/incallui/InCallOrientationEventListener.java
+++ b/InCallUI/src/com/android/incallui/InCallOrientationEventListener.java
@@ -20,7 +20,9 @@
import android.content.res.Configuration;
import android.view.OrientationEventListener;
import android.hardware.SensorManager;
+import android.view.Display;
import android.view.Surface;
+import android.view.WindowManager;
import android.content.pm.ActivityInfo;
/**
@@ -51,7 +53,7 @@
* within x degrees right or left of the screen orientation angles. If it's not within those
* ranges, we return SCREEN_ORIENTATION_UNKNOWN and ignore it.
*/
- private static int SCREEN_ORIENTATION_UNKNOWN = -1;
+ public static int SCREEN_ORIENTATION_UNKNOWN = -1;
// Rotation threshold is 10 degrees. So if the rotation angle is within 10 degrees of any of
// the above angles, we will notify orientation changed.
@@ -64,8 +66,11 @@
private static int sCurrentOrientation = SCREEN_ORIENTATION_0;
private boolean mEnabled = false;
+ private static WindowManager sWindowManager = null;
+
public InCallOrientationEventListener(Context context) {
super(context);
+ sWindowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
}
/**
@@ -175,4 +180,32 @@
private static boolean isInRightRange(int value, int center, int threshold) {
return isWithinRange(value, center, center + threshold);
}
+
+ /**
+ * Returns the current display orientation.
+ * return values 0, 90, 180 and 270
+ * -1 if unknown
+ */
+ public static int getCurrentUiOrientation() {
+ if (sWindowManager == null) return SCREEN_ORIENTATION_UNKNOWN;
+ Display display = sWindowManager.getDefaultDisplay();
+ if (display == null) return SCREEN_ORIENTATION_UNKNOWN;
+ int rotation = display.getRotation();
+ int orientation = SCREEN_ORIENTATION_UNKNOWN;
+ switch (rotation) {
+ case Surface.ROTATION_0:
+ orientation = SCREEN_ORIENTATION_0;
+ break;
+ case Surface.ROTATION_90:
+ orientation = SCREEN_ORIENTATION_90;
+ break;
+ case Surface.ROTATION_180:
+ orientation = SCREEN_ORIENTATION_180;
+ break;
+ case Surface.ROTATION_270:
+ orientation = SCREEN_ORIENTATION_270;
+ break;
+ }
+ return orientation;
+ }
}
diff --git a/InCallUI/src/com/android/incallui/InCallPresenter.java b/InCallUI/src/com/android/incallui/InCallPresenter.java
index 59c39a3..5a5d0cb 100644
--- a/InCallUI/src/com/android/incallui/InCallPresenter.java
+++ b/InCallUI/src/com/android/incallui/InCallPresenter.java
@@ -745,11 +745,7 @@
maybeShowErrorDialogOnDisconnect(call);
// Send broadcast to dismiss deflect dialog.
- if (Objects.equals(call.getId(), QtiCallUtils.getDeflectOrTransferCallId())) {
- Intent intent = new Intent(QtiCallUtils.INTENT_ACTION_DIALOG_DISMISS);
- mInCallActivity.sendBroadcast(intent);
- QtiCallUtils.setDeflectOrTransferCallId(null);
- }
+ dismissDeflectOrTransferDialog(call.getId());
// We need to do the run the same code as onCallListChange.
onCallListChange(mCallList);
@@ -771,6 +767,8 @@
if (call == null) {
return;
}
+ // Send broadcast to dismiss deflect dialog.
+ dismissDeflectOrTransferDialog(call.getId());
wakeUpScreen();
call.setRequestedVideoState(videoState);
@@ -782,6 +780,19 @@
}
/**
+ * Sends broadcast to dismiss Deflection or ECT dialog
+ */
+ private void dismissDeflectOrTransferDialog(String callId) {
+ Log.d(this, "dismissDeflectOrTransferDialog() callId = " + callId);
+ if (Objects.equals(callId, QtiCallUtils.getDeflectOrTransferCallId())) {
+ Intent intent = new Intent(QtiCallUtils.INTENT_ACTION_DIALOG_DISMISS);
+ mInCallActivity.sendBroadcast(intent);
+ QtiCallUtils.setDeflectOrTransferCallId(null);
+ }
+ }
+
+
+ /**
* Given the call list, return the state in which the in-call screen should be.
*/
public InCallState getPotentialStateFromCallList(CallList callList) {
diff --git a/InCallUI/src/com/android/incallui/VideoCallFragment.java b/InCallUI/src/com/android/incallui/VideoCallFragment.java
index a210e6e..fe1422f 100644
--- a/InCallUI/src/com/android/incallui/VideoCallFragment.java
+++ b/InCallUI/src/com/android/incallui/VideoCallFragment.java
@@ -780,13 +780,6 @@
}
mPreviewVideoContainer.setLayoutParams(containerParams);
}
-
- // The width and height are interchanged outside of this method based on the current
- // orientation, so we can transform using "width", which will be either the width or
- // the height.
- Matrix transform = new Matrix();
- transform.setScale(-1, 1, width/2, 0);
- preview.setTransform(transform);
}
}
@@ -813,7 +806,10 @@
return;
}
- preview.setRotation(orientation);
+ // Set transform matrix based on orientation
+ ViewGroup.LayoutParams params = preview.getLayoutParams();
+ setTransformMatrixForRotation(preview, orientation,
+ params.width, params.height);
}
}
@@ -969,6 +965,56 @@
}
/**
+ * Sets the transform matrix to textureview based on orientation so that image
+ * is always up right.
+ */
+ private void setTransformMatrixForRotation(TextureView textureView, int rotation,
+ int width, int height) {
+
+ Matrix matrix = new Matrix();
+
+ if (rotation != InCallOrientationEventListener.SCREEN_ORIENTATION_0) {
+
+ float[] srcArray = new float[] {
+ 0.f, 0.f, // top left
+ width, 0.f, // top right
+ 0.f, height, // bottom left
+ width, height, // bottom right
+ };
+
+ float[] destArray = srcArray;
+
+ // Rotate the image for landscape device orientations
+ if (rotation == InCallOrientationEventListener.SCREEN_ORIENTATION_90) {
+ destArray = new float[] {
+ 0.f, height, // top left
+ 0.f, 0.f, // top right
+ width, height, // bottom left
+ width, 0.f, // bottom right
+ };
+ } else if (rotation == InCallOrientationEventListener.SCREEN_ORIENTATION_270) {
+ destArray = new float[] {
+ width, 0.f, // top left
+ width, height, // top right
+ 0.f, 0.f, // bottom left
+ 0.f, height, // bottom right
+ };
+ } else if (rotation == InCallOrientationEventListener.SCREEN_ORIENTATION_180) {
+ // Flip the image vertically and horizontally for reverse portrait
+ destArray = new float[] {
+ width, height, // top left
+ 0.f, height, // top right
+ width, 0.f, // bottom left
+ 0.f, 0.f, // bottom right
+ };
+ }
+
+ matrix.setPolyToPoly(srcArray, 0, destArray, 0, 4);
+ }
+ textureView.setTransform(matrix);
+ }
+
+ /**
* Resizes a surface so that it has the same size as the full screen and so that it is
* centered vertically below the call card.
*
diff --git a/InCallUI/src/com/android/incallui/VideoCallPresenter.java b/InCallUI/src/com/android/incallui/VideoCallPresenter.java
index 90e625a..df05a34 100644
--- a/InCallUI/src/com/android/incallui/VideoCallPresenter.java
+++ b/InCallUI/src/com/android/incallui/VideoCallPresenter.java
@@ -284,6 +284,13 @@
return;
}
+ // Initialize current ui rotation
+ final int uiOrientation = InCallOrientationEventListener.getCurrentUiOrientation();
+ Log.d(this, "onUiReady: uiOrientation = " + uiOrientation);
+ if (uiOrientation != InCallOrientationEventListener.SCREEN_ORIENTATION_UNKNOWN) {
+ mDeviceOrientation = uiOrientation;
+ }
+
// Register for call state changes last
InCallPresenter.getInstance().addListener(this);
InCallPresenter.getInstance().addDetailsListener(this);
@@ -1240,6 +1247,7 @@
mPreviewSurfaceState = PreviewSurfaceState.CAPABILITIES_RECEIVED;
changePreviewDimensions(width, height);
+ ui.setPreviewRotation(mDeviceOrientation);
if (shallTransmitStaticImage()) {
setPauseImage();