Merge "TTY: Telecomm" into lmp-dev
diff --git a/src/com/android/telecomm/Call.java b/src/com/android/telecomm/Call.java
index 5f28df8..b830499 100644
--- a/src/com/android/telecomm/Call.java
+++ b/src/com/android/telecomm/Call.java
@@ -43,7 +43,6 @@
 import com.android.internal.telephony.SmsApplication;
 import com.android.telecomm.ContactsAsyncHelper.OnImageLoadCompleteListener;
 import com.google.common.base.Preconditions;
-import com.google.common.collect.Sets;
 
 import java.util.Collections;
 import java.util.LinkedList;
@@ -51,6 +50,7 @@
 import java.util.Locale;
 import java.util.Objects;
 import java.util.Set;
+import java.util.concurrent.CopyOnWriteArraySet;
 
 /**
  *  Encapsulates all aspects of a given phone call throughout its lifecycle, starting
@@ -81,6 +81,7 @@
         void onStatusHintsChanged(Call call);
         void onHandleChanged(Call call);
         void onCallerDisplayNameChanged(Call call);
+        void onVideoStateChanged(Call call);
     }
 
     abstract static class ListenerBase implements Listener {
@@ -122,6 +123,8 @@
         public void onHandleChanged(Call call) {}
         @Override
         public void onCallerDisplayNameChanged(Call call) {}
+        @Override
+        public void onVideoStateChanged(Call call) {}
     }
 
     private static final OnQueryCompleteListener sCallerInfoQueryListener =
@@ -216,7 +219,7 @@
     private Bundle mExtras = Bundle.EMPTY;
 
     /** Set of listeners on this call. */
-    private Set<Listener> mListeners = Sets.newHashSet();
+    private Set<Listener> mListeners = new CopyOnWriteArraySet<>();
 
     private CreateConnectionProcessor mCreateConnectionProcessor;
 
@@ -1067,6 +1070,9 @@
      */
     public void setVideoState(int videoState) {
         mVideoState = videoState;
+        for (Listener l : mListeners) {
+            l.onVideoStateChanged(this);
+        }
     }
 
     public boolean getAudioModeIsVoip() {
diff --git a/src/com/android/telecomm/CallsManager.java b/src/com/android/telecomm/CallsManager.java
index a78d750..36f8cea 100644
--- a/src/com/android/telecomm/CallsManager.java
+++ b/src/com/android/telecomm/CallsManager.java
@@ -57,6 +57,7 @@
         void onRequestingRingback(Call call, boolean ringback);
         void onIsConferencedChanged(Call call);
         void onAudioModeIsVoipChanged(Call call);
+        void onVideoStateChanged(Call call);
     }
 
     private static final CallsManager INSTANCE = new CallsManager();
@@ -206,6 +207,13 @@
         }
     }
 
+    @Override
+    public void onVideoStateChanged(Call call) {
+        for (CallsManagerListener listener : mListeners) {
+            listener.onVideoStateChanged(call);
+        }
+    }
+
     ImmutableCollection<Call> getCalls() {
         return ImmutableList.copyOf(mCalls);
     }
diff --git a/src/com/android/telecomm/CallsManagerListenerBase.java b/src/com/android/telecomm/CallsManagerListenerBase.java
index 86c723d..7753105 100644
--- a/src/com/android/telecomm/CallsManagerListenerBase.java
+++ b/src/com/android/telecomm/CallsManagerListenerBase.java
@@ -16,7 +16,6 @@
 
 package com.android.telecomm;
 
-import android.net.Uri;
 import android.telecomm.CallAudioState;
 import android.telecomm.CallState;
 
@@ -70,4 +69,8 @@
     @Override
     public void onAudioModeIsVoipChanged(Call call) {
     }
+
+    @Override
+    public void onVideoStateChanged(Call call) {
+    }
 }
diff --git a/src/com/android/telecomm/HeadsetMediaButton.java b/src/com/android/telecomm/HeadsetMediaButton.java
index 6f533a4..70af0fd 100644
--- a/src/com/android/telecomm/HeadsetMediaButton.java
+++ b/src/com/android/telecomm/HeadsetMediaButton.java
@@ -54,11 +54,9 @@
     HeadsetMediaButton(Context context, CallsManager callsManager) {
         mCallsManager = callsManager;
 
-        // Register a MediaSession but don't enable it yet. This is a
+        // Create a MediaSession but don't enable it yet. This is a
         // replacement for MediaButtonReceiver
-        MediaSessionManager msm =
-                (MediaSessionManager) context.getSystemService(Context.MEDIA_SESSION_SERVICE);
-        mSession = msm.createSession(HeadsetMediaButton.class.getSimpleName());
+        mSession = new MediaSession(context, HeadsetMediaButton.class.getSimpleName());
         mSession.addCallback(mSessionCallback);
         mSession.setFlags(MediaSession.FLAG_EXCLUSIVE_GLOBAL_PRIORITY
                 | MediaSession.FLAG_HANDLES_MEDIA_BUTTONS);
diff --git a/src/com/android/telecomm/InCallController.java b/src/com/android/telecomm/InCallController.java
index 3824c6f..7081dc9 100644
--- a/src/com/android/telecomm/InCallController.java
+++ b/src/com/android/telecomm/InCallController.java
@@ -90,6 +90,11 @@
         public void onCallerDisplayNameChanged(Call call) {
             updateCall(call);
         }
+
+        @Override
+        public void onVideoStateChanged(Call call) {
+            updateCall(call);
+        }
     };
 
     /** Maintains a binding connection to the in-call app. */
@@ -319,6 +324,6 @@
                 call.getHandlePresentation(), callerDisplayName,
                 call.getCallerDisplayNamePresentation(), call.getGatewayInfo(),
                 call.getPhoneAccount(), call.getCallVideoProvider(), parentCallId, childCallIds,
-                call.getStatusHints());
+                call.getStatusHints() , call.getVideoState());
     }
 }