Merge "Do not post notifications for logged self-managed connections" into oc-dr1-dev
diff --git a/src/com/android/server/telecom/Call.java b/src/com/android/server/telecom/Call.java
index 41832da..ad9ac35 100644
--- a/src/com/android/server/telecom/Call.java
+++ b/src/com/android/server/telecom/Call.java
@@ -807,7 +807,8 @@
                 fixParentAfterDisconnect();
             }
             if (mState == CallState.DISCONNECTED &&
-                    mDisconnectCause.getCode() == DisconnectCause.MISSED) {
+                    (mDisconnectCause.getCode() == DisconnectCause.MISSED ||
+                            mDisconnectCause.getCode() == DisconnectCause.REJECTED)) {
                 // Ensure when an incoming call is missed that the video state history is updated.
                 mVideoStateHistory |= mVideoState;
             }
diff --git a/src/com/android/server/telecom/CallAudioModeStateMachine.java b/src/com/android/server/telecom/CallAudioModeStateMachine.java
index 3d778f2..df912ed 100644
--- a/src/com/android/server/telecom/CallAudioModeStateMachine.java
+++ b/src/com/android/server/telecom/CallAudioModeStateMachine.java
@@ -208,12 +208,6 @@
             if (mCallAudioManager.startRinging()) {
                 mAudioManager.requestAudioFocusForCall(AudioManager.STREAM_RING,
                         AudioManager.AUDIOFOCUS_GAIN_TRANSIENT);
-                if (mMostRecentMode == AudioManager.MODE_IN_CALL) {
-                    // Preserving behavior from the old CallAudioManager.
-                    Log.i(LOG_TAG, "Transition from IN_CALL -> RINGTONE."
-                            + "  Resetting to NORMAL first.");
-                    mAudioManager.setMode(AudioManager.MODE_NORMAL);
-                }
                 mAudioManager.setMode(AudioManager.MODE_RINGTONE);
                 mCallAudioManager.setCallAudioRouteFocusState(CallAudioRouteStateMachine.RINGING_FOCUS);
             } else {
diff --git a/src/com/android/server/telecom/CallsManager.java b/src/com/android/server/telecom/CallsManager.java
index 77a9d6d..115280a 100644
--- a/src/com/android/server/telecom/CallsManager.java
+++ b/src/com/android/server/telecom/CallsManager.java
@@ -2261,6 +2261,10 @@
             if (handoverState == HandoverState.HANDOVER_FROM_STARTED) {
                 // Disconnect before handover was accepted.
                 Log.i(this, "setCallState: disconnect before handover accepted");
+                // Let the handover destination know that the source has disconnected prior to
+                // completion of the handover.
+                call.getHandoverDestinationCall().sendCallEvent(
+                        android.telecom.Call.EVENT_HANDOVER_SOURCE_DISCONNECTED, null);
             } else if (handoverState == HandoverState.HANDOVER_ACCEPTED) {
                 Log.i(this, "setCallState: handover from complete");
                 completeHandoverFrom(call);
diff --git a/testapps/src/com/android/server/telecom/testapps/TestCertActivity.java b/testapps/src/com/android/server/telecom/testapps/TestCertActivity.java
index 0df836c..312b447 100644
--- a/testapps/src/com/android/server/telecom/testapps/TestCertActivity.java
+++ b/testapps/src/com/android/server/telecom/testapps/TestCertActivity.java
@@ -54,6 +54,7 @@
 import java.net.ProtocolException;
 import java.net.URL;
 import java.util.ArrayList;
+import java.util.Date;
 
 import android.util.Base64;
 
@@ -83,16 +84,6 @@
         mCertUrlView.setText(mURL);
     }
 
-    public static PublicKey makeKeyObject(byte[] publicKeyBytes) {
-        try {
-            X509EncodedKeySpec pubKeySpec = new X509EncodedKeySpec(publicKeyBytes);
-            return KeyFactory.getInstance("RSA").generatePublic(pubKeySpec);
-        } catch (InvalidKeySpecException | NoSuchAlgorithmException ex) {
-            Log.e(LOG_TAG, "Error makeKeyObject: unable to convert into PublicKey", ex);
-        }
-        return null;
-    }
-
     /**
      * Class to get json by making HTTP call
      */
@@ -152,8 +143,6 @@
 
         private void savePublicKey(String key, int type, String identifier) {
             byte[] keyBytes = Base64.decode(key.getBytes(), Base64.DEFAULT);
-            PublicKey publicKey = makeKeyObject(keyBytes);
-            Log.i(LOG_TAG, "generated public key: " + publicKey);
             final TelephonyManager telephonyManager =
                     (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
 
@@ -168,7 +157,7 @@
             }
 
             ImsiEncryptionInfo imsiEncryptionInfo = new ImsiEncryptionInfo(mcc,
-                    mnc, type, identifier, publicKey);
+                    mnc, type, identifier, keyBytes, new Date());
             telephonyManager.setCarrierInfoForImsiEncryption(imsiEncryptionInfo);
             keyList.add(imsiEncryptionInfo.getKeyType() + "," +
                     imsiEncryptionInfo.getKeyIdentifier());
diff --git a/tests/src/com/android/server/telecom/tests/BasicCallTests.java b/tests/src/com/android/server/telecom/tests/BasicCallTests.java
index ce774a7..749f3c6 100644
--- a/tests/src/com/android/server/telecom/tests/BasicCallTests.java
+++ b/tests/src/com/android/server/telecom/tests/BasicCallTests.java
@@ -871,6 +871,38 @@
     }
 
     /**
+     * Ensure that when an incoming video call is missed, the video state history still includes
+     * video calling. This is important for the call log.
+     */
+    @LargeTest
+    public void testIncomingVideoCallMissedCheckVideoHistory() throws Exception {
+        IdPair ids = startIncomingPhoneCall("650-555-1212", mPhoneAccountA0.getAccountHandle(),
+                VideoProfile.STATE_BIDIRECTIONAL, mConnectionServiceFixtureA);
+        com.android.server.telecom.Call call = mTelecomSystem.getCallsManager().getCalls()
+                .iterator().next();
+
+        mConnectionServiceFixtureA.sendSetDisconnected(ids.mConnectionId, DisconnectCause.MISSED);
+
+        assertTrue(VideoProfile.isVideo(call.getVideoStateHistory()));
+    }
+
+    /**
+     * Ensure that when an incoming video call is rejected, the video state history still includes
+     * video calling. This is important for the call log.
+     */
+    @LargeTest
+    public void testIncomingVideoCallRejectedCheckVideoHistory() throws Exception {
+        IdPair ids = startIncomingPhoneCall("650-555-1212", mPhoneAccountA0.getAccountHandle(),
+                VideoProfile.STATE_BIDIRECTIONAL, mConnectionServiceFixtureA);
+        com.android.server.telecom.Call call = mTelecomSystem.getCallsManager().getCalls()
+                .iterator().next();
+
+        mConnectionServiceFixtureA.sendSetDisconnected(ids.mConnectionId, DisconnectCause.REJECTED);
+
+        assertTrue(VideoProfile.isVideo(call.getVideoStateHistory()));
+    }
+
+    /**
      * Test scenario where the user starts an outgoing video call with no selected PhoneAccount, and
      * then subsequently selects a PhoneAccount which does not support video calling.
      * @throws Exception