Merge changes from topic 'mwd-merge-042415'

* changes:
  Fix build - renaming variables.
  Merge commit 'a62b505' into merge2
  Merge commit '77f10d8' into merge2
  Merge commit '569b54e' into merge2
  Merge commit 'f7aed89' into merge2
  Merge commit '0751e61' into merge2
  Merge commit '95ac444' into merge2
diff --git a/src/com/android/server/telecom/CallsManager.java b/src/com/android/server/telecom/CallsManager.java
index 9ee9ad2..182590d 100644
--- a/src/com/android/server/telecom/CallsManager.java
+++ b/src/com/android/server/telecom/CallsManager.java
@@ -1121,6 +1121,7 @@
         call.setConnectionCapabilities(parcelableConference.getConnectionCapabilities());
         call.setVideoState(parcelableConference.getVideoState());
         call.setVideoProvider(parcelableConference.getVideoProvider());
+        call.setStatusHints(parcelableConference.getStatusHints());
 
         // TODO: Move this to be a part of addCall()
         call.addListener(this);
diff --git a/src/com/android/server/telecom/ConnectionServiceWrapper.java b/src/com/android/server/telecom/ConnectionServiceWrapper.java
index f7f98d1..a2295a7 100644
--- a/src/com/android/server/telecom/ConnectionServiceWrapper.java
+++ b/src/com/android/server/telecom/ConnectionServiceWrapper.java
@@ -443,7 +443,8 @@
             try {
                 synchronized (mLock) {
                     logIncoming("setStatusHints %s %s", callId, statusHints);
-                    if (mCallIdMapper.isValidCallId(callId)) {
+                    if (mCallIdMapper.isValidCallId(callId)
+                            || mCallIdMapper.isValidConferenceId(callId)) {
                         Call call = mCallIdMapper.getCall(callId);
                         if (call != null) {
                             call.setStatusHints(statusHints);
diff --git a/src/com/android/server/telecom/InCallController.java b/src/com/android/server/telecom/InCallController.java
index ff75ca4..22ee132 100644
--- a/src/com/android/server/telecom/InCallController.java
+++ b/src/com/android/server/telecom/InCallController.java
@@ -36,6 +36,7 @@
 import android.telecom.InCallService;
 import android.telecom.ParcelableCall;
 import android.telecom.TelecomManager;
+import android.telecom.VideoCallImpl;
 import android.util.ArrayMap;
 
 // TODO: Needed for move to system service: import com.android.internal.R;
@@ -86,7 +87,7 @@
 
         @Override
         public void onVideoCallProviderChanged(Call call) {
-            updateCall(call);
+            updateCall(call, true /* videoProviderChanged */);
         }
 
         @Override
@@ -164,9 +165,8 @@
             for (Map.Entry<ComponentName, IInCallService> entry : mInCallServices.entrySet()) {
                 ComponentName componentName = entry.getKey();
                 IInCallService inCallService = entry.getValue();
-
                 ParcelableCall parcelableCall = toParcelableCall(call,
-                        componentName.equals(mInCallComponentName) /* includeVideoProvider */);
+                        true /* includeVideoProvider */);
                 try {
                     inCallService.addCall(parcelableCall);
                 } catch (RemoteException ignored) {
@@ -376,9 +376,7 @@
                 try {
                     // Track the call if we don't already know about it.
                     addCall(call);
-                    inCallService.addCall(toParcelableCall(
-                            call,
-                            componentName.equals(mInCallComponentName) /* includeVideoProvider */));
+                    inCallService.addCall(toParcelableCall(call, true /* includeVideoProvider */));
                 } catch (RemoteException ignored) {
                 }
             }
@@ -430,18 +428,28 @@
     }
 
     /**
-     * Informs all {@link InCallService} instances of the updated call information.  Changes to the
-     * video provider are only communicated to the default in-call UI.
+     * Informs all {@link InCallService} instances of the updated call information.
      *
      * @param call The {@link Call}.
      */
     private void updateCall(Call call) {
+        updateCall(call, false /* videoProviderChanged */);
+    }
+
+    /**
+     * Informs all {@link InCallService} instances of the updated call information.
+     *
+     * @param call The {@link Call}.
+     * @param videoProviderChanged {@code true} if the video provider changed, {@code false}
+     *      otherwise.
+     */
+    private void updateCall(Call call, boolean videoProviderChanged) {
         if (!mInCallServices.isEmpty()) {
             for (Map.Entry<ComponentName, IInCallService> entry : mInCallServices.entrySet()) {
                 ComponentName componentName = entry.getKey();
                 IInCallService inCallService = entry.getValue();
                 ParcelableCall parcelableCall = toParcelableCall(call,
-                        componentName.equals(mInCallComponentName) /* includeVideoProvider */);
+                        videoProviderChanged /* includeVideoProvider */);
                 Log.v(this, "updateCall %s ==> %s", call, parcelableCall);
                 try {
                     inCallService.updateCall(parcelableCall);
@@ -455,8 +463,10 @@
      * Parcels all information for a {@link Call} into a new {@link ParcelableCall} instance.
      *
      * @param call The {@link Call} to parcel.
-     * @param includeVideoProvider When {@code true}, the {@link IVideoProvider} is included in the
-     *      parceled call.  When {@code false}, the {@link IVideoProvider} is not included.
+     * @param includeVideoProvider {@code true} if the video provider should be parcelled with the
+     *      {@link Call}, {@code false} otherwise.  Since the {@link ParcelableCall#getVideoCall()}
+     *      method creates a {@link VideoCallImpl} instance on access it is important for the
+     *      recipient of the {@link ParcelableCall} to know if the video provider changed.
      * @return The {@link ParcelableCall} containing all call information from the {@link Call}.
      */
     private ParcelableCall toParcelableCall(Call call, boolean includeVideoProvider) {
@@ -538,6 +548,7 @@
                 call.getCallerDisplayNamePresentation(),
                 call.getGatewayInfo(),
                 call.getTargetPhoneAccount(),
+                includeVideoProvider,
                 includeVideoProvider ? call.getVideoProvider() : null,
                 parentCallId,
                 childCallIds,
diff --git a/testapps/AndroidManifest.xml b/testapps/AndroidManifest.xml
index 692d39b..c8d7105 100644
--- a/testapps/AndroidManifest.xml
+++ b/testapps/AndroidManifest.xml
@@ -54,7 +54,8 @@
         </service>
 
         <activity android:name="com.android.server.telecom.testapps.TestCallActivity"
-                  android:label="@string/testCallActivityLabel">
+                  android:label="@string/testCallActivityLabel"
+                  android:process="com.android.server.telecom.testapps.TestInCallService">
             <intent-filter>
                 <action android:name="android.intent.action.MAIN" />
                 <category android:name="android.intent.category.DEFAULT" />
@@ -76,6 +77,10 @@
                 <category android:name="android.intent.category.DEFAULT" />
                 <data android:scheme="int" />
             </intent-filter>
+            <intent-filter>
+                <action android:name="android.server.telecom.testapps.ACTION_SEND_UPDATE_REQUEST_FROM_TEST_INCALL_SERVICE" />
+                <category android:name="android.intent.category.DEFAULT" />
+            </intent-filter>
         </activity>
 
         <receiver android:name="com.android.server.telecom.testapps.CallNotificationReceiver"
diff --git a/testapps/src/com/android/server/telecom/testapps/TestCallActivity.java b/testapps/src/com/android/server/telecom/testapps/TestCallActivity.java
index 4ac151f..8198cd8 100644
--- a/testapps/src/com/android/server/telecom/testapps/TestCallActivity.java
+++ b/testapps/src/com/android/server/telecom/testapps/TestCallActivity.java
@@ -51,6 +51,12 @@
     public static final String ACTION_SEND_UPGRADE_REQUEST =
             "android.telecom.testapps.ACTION_SEND_UPGRADE_REQUEST";
 
+    /**
+     * Sends an upgrade to video request for any live calls.
+     */
+    public static final String ACTION_SEND_UPDATE_REQUEST_FROM_TEST_INCALL_SERVICE =
+            "android.server.telecom.testapps.ACTION_SEND_UPDATE_REQUEST_FROM_TEST_INCALL_SERVICE";
+
     @Override
     protected void onCreate(Bundle icicle) {
         super.onCreate(icicle);
@@ -65,6 +71,8 @@
             CallNotificationReceiver.hangupCalls(this);
         } else if (ACTION_SEND_UPGRADE_REQUEST.equals(action)) {
             CallNotificationReceiver.sendUpgradeRequest(this, data);
+        } else if (ACTION_SEND_UPDATE_REQUEST_FROM_TEST_INCALL_SERVICE.equals(action)) {
+            TestCallList.getInstance().sendUpgradeToVideoRequest();
         } else {
             CallServiceNotifier.getInstance().updateNotification(this);
         }
diff --git a/testapps/src/com/android/server/telecom/testapps/TestCallList.java b/testapps/src/com/android/server/telecom/testapps/TestCallList.java
new file mode 100644
index 0000000..7bb7a91
--- /dev/null
+++ b/testapps/src/com/android/server/telecom/testapps/TestCallList.java
@@ -0,0 +1,160 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License
+ */
+
+package com.android.server.telecom.testapps;
+
+import android.telecom.Call;
+import android.telecom.CameraCapabilities;
+import android.telecom.InCallService;
+import android.telecom.VideoProfile;
+import android.util.ArrayMap;
+import android.util.ArraySet;
+import android.util.Log;
+
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * Maintains a list of calls received via the {@link TestInCallServiceImpl}.
+ */
+public class TestCallList extends Call.Listener {
+    private static final TestCallList INSTANCE = new TestCallList();
+    private static final String TAG = "TestCallList";
+
+    private class TestVideoCallListener extends InCallService.VideoCall.Callback {
+        private Call mCall;
+
+        public TestVideoCallListener(Call call) {
+            mCall = call;
+        }
+
+        @Override
+        public void onSessionModifyRequestReceived(VideoProfile videoProfile) {
+            Log.v(TAG,
+                    "onSessionModifyRequestReceived: videoState = " + videoProfile.getVideoState()
+                            + " call = " + mCall);
+        }
+
+        @Override
+        public void onSessionModifyResponseReceived(int status, VideoProfile requestedProfile,
+                VideoProfile responseProfile) {
+            Log.v(TAG,
+                    "onSessionModifyResponseReceived: status = " + status + " videoState = "
+                            + responseProfile.getVideoState()
+                            + " call = " + mCall);
+        }
+
+        @Override
+        public void onCallSessionEvent(int event) {
+
+        }
+
+        @Override
+        public void onPeerDimensionsChanged(int width, int height) {
+
+        }
+
+        @Override
+        public void onVideoQualityChanged(int videoQuality) {
+            Log.v(TAG,
+                    "onVideoQualityChanged: videoQuality = " + videoQuality + " call = " + mCall);
+        }
+
+        @Override
+        public void onCallDataUsageChanged(long dataUsage) {
+
+        }
+
+        @Override
+        public void onCameraCapabilitiesChanged(CameraCapabilities cameraCapabilities) {
+
+        }
+    }
+
+    // The calls the call list knows about.
+    private Set<Call> mCalls = new ArraySet<Call>();
+    private Map<Call, TestVideoCallListener> mVideoCallListeners =
+            new ArrayMap<Call, TestVideoCallListener>();
+
+    /**
+     * Singleton accessor.
+     */
+    public static TestCallList getInstance() {
+        return INSTANCE;
+    }
+
+    public void addCall(Call call) {
+        if (mCalls.contains(call)) {
+            Log.e(TAG, "addCall: Call already added.");
+            return;
+        }
+        Log.v(TAG, "addCall: " + call + " " + System.identityHashCode(this));
+        mCalls.add(call);
+        call.addListener(this);
+    }
+
+    public void removeCall(Call call) {
+        if (!mCalls.contains(call)) {
+            Log.e(TAG, "removeCall: Call cannot be removed -- doesn't exist.");
+            return;
+        }
+        Log.v(TAG, "removeCall: " + call);
+        mCalls.remove(call);
+        call.removeListener(this);
+    }
+
+    public void clearCalls() {
+        mCalls.clear();
+        for (Call call : mVideoCallListeners.keySet()) {
+            if (call.getVideoCall() != null) {
+                call.getVideoCall().unregisterCallback();
+            }
+        }
+        mVideoCallListeners.clear();
+    }
+
+    /**
+     * For any video calls tracked, sends an upgrade to video request.
+     */
+    public void sendUpgradeToVideoRequest() {
+        Log.v(TAG, "sendUpgradeToVideoRequest "+mCalls.size()+ " " + System.identityHashCode(this));
+
+        for (Call call : mCalls) {
+            InCallService.VideoCall videoCall = call.getVideoCall();
+            Log.v(TAG, "sendUpgradeToVideoRequest: checkCall "+call);
+            if (videoCall == null) {
+                continue;
+            }
+
+            Log.v(TAG, "send upgrade to video request for call: " + call);
+            videoCall.sendSessionModifyRequest(new VideoProfile(
+                    VideoProfile.VideoState.BIDIRECTIONAL));
+        }
+    }
+
+    @Override
+    public void onVideoCallChanged(Call call, InCallService.VideoCall videoCall) {
+        Log.v(TAG, "onVideoCallChanged: call = " + call + " " + System.identityHashCode(this));
+        if (videoCall != null) {
+            if (!mVideoCallListeners.containsKey(call)) {
+                TestVideoCallListener listener = new TestVideoCallListener(call);
+                videoCall.registerCallback(listener);
+                mVideoCallListeners.put(call, listener);
+                Log.v(TAG, "onVideoCallChanged: added new listener");
+            }
+        }
+    }
+}
diff --git a/testapps/src/com/android/server/telecom/testapps/TestInCallServiceImpl.java b/testapps/src/com/android/server/telecom/testapps/TestInCallServiceImpl.java
index 1d7e805..68bbac9 100644
--- a/testapps/src/com/android/server/telecom/testapps/TestInCallServiceImpl.java
+++ b/testapps/src/com/android/server/telecom/testapps/TestInCallServiceImpl.java
@@ -16,6 +16,7 @@
 
 package com.android.server.telecom.testapps;
 
+import android.telecom.Call;
 import android.telecom.InCallService;
 import android.telecom.Phone;
 import android.util.Log;
@@ -34,12 +35,15 @@
 
     private Phone.Listener mPhoneListener = new Phone.Listener() {
         @Override
-        public void onCallAdded(Phone phone, android.telecom.Call call) {
-            Log.i(TAG, "onCallAdded: "+call.toString());
+        public void onCallAdded(Phone phone, Call call) {
+            Log.i(TAG, "onCallAdded: " + call.toString());
+            TestCallList.getInstance().addCall(call);
         }
+
         @Override
-        public void onCallRemoved(Phone phone, android.telecom.Call call) {
+        public void onCallRemoved(Phone phone, Call call) {
             Log.i(TAG, "onCallRemoved: "+call.toString());
+            TestCallList.getInstance().removeCall(call);
         }
     };
 
@@ -48,7 +52,7 @@
         Log.i(TAG, "onPhoneCreated");
         mPhone = phone;
         mPhone.addListener(mPhoneListener);
-
+        TestCallList.getInstance().clearCalls();
     }
 
     @Override
@@ -56,5 +60,6 @@
         Log.i(TAG, "onPhoneDestroyed");
         mPhone.removeListener(mPhoneListener);
         mPhone = null;
+        TestCallList.getInstance().clearCalls();
     }
 }
diff --git a/tests/src/com/android/server/telecom/tests/ConnectionServiceFixture.java b/tests/src/com/android/server/telecom/tests/ConnectionServiceFixture.java
index 5114a52..a8841cd 100644
--- a/tests/src/com/android/server/telecom/tests/ConnectionServiceFixture.java
+++ b/tests/src/com/android/server/telecom/tests/ConnectionServiceFixture.java
@@ -88,6 +88,7 @@
         IVideoProvider videoProvider;
         int videoState;
         long connectTimeMillis;
+        StatusHints statusHints;
     }
 
     public String mLatestConnectionId;
@@ -335,7 +336,8 @@
                 c.connectionIds,
                 c.videoProvider,
                 c.videoState,
-                c.connectTimeMillis);
+                c.connectTimeMillis,
+                c.statusHints);
     }
 
     private ParcelableConnection parcelable(ConnectionInfo c) {