Merge "Fix parentID for conference call support." into lmp-dev
diff --git a/InCallUI/res/layout/primary_call_info.xml b/InCallUI/res/layout/primary_call_info.xml
index 4231922..1f3b954 100644
--- a/InCallUI/res/layout/primary_call_info.xml
+++ b/InCallUI/res/layout/primary_call_info.xml
@@ -47,7 +47,7 @@
             android:layout_marginEnd="4dp"
             android:baselineAlignBottom="true"
             android:tint="@color/incall_accent_color"
-            android:alpha="0.7"
+            android:alpha="0.0"
             android:scaleType="centerInside"
             android:visibility="gone" />
 
diff --git a/InCallUI/res/layout/select_account_list_item.xml b/InCallUI/res/layout/select_account_list_item.xml
index 0b24c9b..1999fce 100644
--- a/InCallUI/res/layout/select_account_list_item.xml
+++ b/InCallUI/res/layout/select_account_list_item.xml
@@ -15,7 +15,8 @@
 -->
 
 <!-- Layout of a single item in the InCallUI Account Chooser Dialog. -->
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+<view class="com.android.contacts.common.widget.ActivityTouchLinearLayout"
+    xmlns:android="http://schemas.android.com/apk/res/android"
     android:orientation="horizontal"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
@@ -24,6 +25,7 @@
     <ImageView android:id="@+id/icon"
                android:layout_width="48dp"
                android:layout_height="48dp"
+               android:tint="@color/dialtacts_secondary_text_color"
                android:scaleType="center" />
 
     <TextView android:id="@+id/text"
@@ -33,4 +35,4 @@
               android:layout_width="0dp"
               android:layout_weight="1"
               android:layout_height="match_parent" />
-</LinearLayout>
+</view>
diff --git a/InCallUI/res/values/strings.xml b/InCallUI/res/values/strings.xml
index 964286a..fc2ee20 100644
--- a/InCallUI/res/values/strings.xml
+++ b/InCallUI/res/values/strings.xml
@@ -486,12 +486,30 @@
     -->
     <string name="description_delete_button">backspace</string>
 
-    <!-- Content description of the speakerphone enabled notification icon for accessibility (not shown on the screen). [CHAR LIMIT=NONE] -->
-    <string name="accessibility_speakerphone_enabled">Speakerphone enabled.</string>
+    <!-- String used by AccessibilityService to announce that the speakerphone has been selected for audio output [CHAR LIMIT=NONE]-->
+    <string name="accessibility_speakerphone_selected">Speakerphone selected</string>
 
-    <!-- Content description of the call muted notification icon for accessibility (not shown on the screen). [CHAR LIMIT=NONE] -->
+    <!-- String used by AccessibilityService to announce that the phone's earpiece has been selected for audio output [CHAR LIMIT=NONE]-->
+    <string name="accessibility_earpiece_selected">Earpiece selected</string>
+
+    <!-- String used by AccessibilityService to announce that the wired headset has been selected for audio output [CHAR LIMIT=NONE]-->
+    <string name="accessibility_wired_headset_selected">Wired headset selected</string>
+
+    <!-- String used by AccessibilityService to announce that the bluetooth headset has been selected for audio output [CHAR LIMIT=NONE]-->
+    <string name="accessibility_bluetooth_headset_selected">Bluetooth headset selected</string>
+
+    <!-- String used by AccessibilityService to announce that the call has been muted [CHAR LIMIT=NONE]-->
     <string name="accessibility_call_muted">Call muted.</string>
 
+    <!-- String used by AccessibilityService to announce that the call has been unmuted [CHAR LIMIT=NONE]-->
+    <string name="accessibility_call_unmuted">Call unmuted.</string>
+
+    <!-- String used by AccessibilityService to announce that the call has been put on hold [CHAR LIMIT=NONE]-->
+    <string name="accessibility_call_put_on_hold">Call put on hold.</string>
+
+    <!-- String used by AccessibilityService to announce that the call has been removed from hold [CHAR LIMIT=NONE]-->
+    <string name="accessibility_call_removed_from_hold">Call removed from hold.</string>
+
     <!-- Description of the answer target in the Slide unlock screen of Phone. [CHAR LIMIT=NONE] -->
     <string name="description_target_answer">Answer</string>
     <!-- Description of the send_sms target in the Slide unlock screen of Phone. [CHAR LIMIT=NONE] -->
diff --git a/InCallUI/src/com/android/incallui/CallButtonFragment.java b/InCallUI/src/com/android/incallui/CallButtonFragment.java
index 9b141da..09a3bc2 100644
--- a/InCallUI/src/com/android/incallui/CallButtonFragment.java
+++ b/InCallUI/src/com/android/incallui/CallButtonFragment.java
@@ -16,9 +16,9 @@
 
 package com.android.incallui;
 
+import android.content.Context;
 import android.graphics.drawable.LayerDrawable;
 import android.os.Bundle;
-
 import android.telecomm.AudioState;
 import android.view.ContextThemeWrapper;
 import android.view.LayoutInflater;
@@ -26,6 +26,8 @@
 import android.view.MenuItem;
 import android.view.View;
 import android.view.ViewGroup;
+import android.view.accessibility.AccessibilityEvent;
+import android.view.accessibility.AccessibilityManager;
 import android.widget.CompoundButton;
 import android.widget.ImageButton;
 import android.widget.PopupMenu;
@@ -60,6 +62,8 @@
     private View mManageConferenceButton;
     private View mGenericMergeButton;
 
+    private int mPrevAudioMode = 0;
+
     // Constants for Drawable.setAlpha()
     private static final int HIDDEN = 0;
     private static final int VISIBLE = 255;
@@ -224,7 +228,11 @@
 
     @Override
     public void setMute(boolean value) {
-        mMuteButton.setSelected(value);
+        if (mMuteButton.isSelected() != value) {
+            mMuteButton.setSelected(value);
+            maybeSendAccessibilityEvent(mMuteButton, value ? R.string.accessibility_call_muted
+                    : R.string.accessibility_call_unmuted);
+        }
     }
 
     @Override
@@ -249,7 +257,12 @@
 
     @Override
     public void setHold(boolean value) {
-        mHoldButton.setSelected(value);
+        if (mHoldButton.isSelected() != value) {
+            mHoldButton.setSelected(value);
+            maybeSendAccessibilityEvent(mHoldButton,
+                    value ? R.string.accessibility_call_put_on_hold :
+                            R.string.accessibility_call_removed_from_hold);
+        }
     }
 
     @Override
@@ -372,6 +385,30 @@
     public void setAudio(int mode) {
         updateAudioButtons(getPresenter().getSupportedAudio());
         refreshAudioModePopup();
+
+        if (mPrevAudioMode != mode) {
+            if (mPrevAudioMode != 0) {
+                int stringId = 0;
+                switch (mode) {
+                    case AudioState.ROUTE_EARPIECE:
+                        stringId = R.string.accessibility_earpiece_selected;
+                        break;
+                    case AudioState.ROUTE_BLUETOOTH:
+                        stringId = R.string.accessibility_bluetooth_headset_selected;
+                        break;
+                    case AudioState.ROUTE_WIRED_HEADSET:
+                        stringId = R.string.accessibility_wired_headset_selected;
+                        break;
+                    case AudioState.ROUTE_SPEAKER:
+                        stringId = R.string.accessibility_speakerphone_selected;
+                        break;
+                }
+                if (stringId != 0) {
+                    maybeSendAccessibilityEvent(mAudioButton, stringId);
+                }
+            }
+            mPrevAudioMode = mode;
+        }
     }
 
     @Override
@@ -651,4 +688,19 @@
     public void hideExtraRow() {
        mExtraRowButton.setVisibility(View.GONE);
     }
+
+    private void maybeSendAccessibilityEvent(View view, int stringId) {
+        final Context context = getActivity();
+        AccessibilityManager manager =
+                (AccessibilityManager) context.getSystemService(Context.ACCESSIBILITY_SERVICE);
+        if (manager != null && manager.isEnabled()) {
+            AccessibilityEvent e = AccessibilityEvent.obtain();
+            e.setSource(view);
+            e.setEventType(AccessibilityEvent.TYPE_ANNOUNCEMENT);
+            e.setClassName(getClass().getName());
+            e.setPackageName(context.getPackageName());
+            e.getText().add(context.getResources().getString(stringId));
+            manager.sendAccessibilityEvent(e);
+        }
+    }
 }
diff --git a/InCallUI/src/com/android/incallui/CallCardFragment.java b/InCallUI/src/com/android/incallui/CallCardFragment.java
index 8ca1dd6..bd32684 100644
--- a/InCallUI/src/com/android/incallui/CallCardFragment.java
+++ b/InCallUI/src/com/android/incallui/CallCardFragment.java
@@ -369,7 +369,7 @@
     @Override
     public void setPrimaryName(String name, boolean nameIsNumber) {
         if (TextUtils.isEmpty(name)) {
-            mPrimaryName.setText("");
+            mPrimaryName.setText(null);
         } else {
             mPrimaryName.setText(name);
 
@@ -393,7 +393,7 @@
     public void setPrimaryPhoneNumber(String number) {
         // Set the number
         if (TextUtils.isEmpty(number)) {
-            mPhoneNumber.setText("");
+            mPhoneNumber.setText(null);
             mPhoneNumber.setVisibility(View.GONE);
         } else {
             mPhoneNumber.setText(number);
@@ -502,6 +502,7 @@
                 mCallStateIcon.setVisibility(View.GONE);
             } else {
                 mCallStateIcon.setVisibility(View.VISIBLE);
+                mCallStateIcon.setImageAlpha(255);
                 mCallStateIcon.setImageDrawable(connectionIcon);
             }
 
@@ -515,8 +516,10 @@
 
             if (state == Call.State.ACTIVE || state == Call.State.CONFERENCED) {
                 mCallStateLabel.clearAnimation();
+                mCallStateIcon.clearAnimation();
             } else {
                 mCallStateLabel.startAnimation(mPulseAnimation);
+                mCallStateIcon.startAnimation(mPulseAnimation);
             }
         } else {
             Animation callStateAnimation = mCallStateLabel.getAnimation();
@@ -526,6 +529,8 @@
             mCallStateLabel.setText(null);
             mCallStateLabel.setAlpha(0);
             mCallStateLabel.setVisibility(View.GONE);
+            mCallStateIcon.setImageAlpha(0);
+            mCallStateIcon.setVisibility(View.GONE);
 
             mCallStateVideoCallIcon.setVisibility(View.GONE);
         }
@@ -962,6 +967,7 @@
             @Override
             public void onAnimationStart(Animator animation) {
                 assignTranslateAnimation(mCallStateLabel, 1);
+                assignTranslateAnimation(mCallStateIcon, 1);
                 assignTranslateAnimation(mPrimaryName, 2);
                 assignTranslateAnimation(mCallNumberAndLabel, 3);
                 assignTranslateAnimation(mCallTypeLabel, 4);
diff --git a/InCallUI/src/com/android/incallui/CallCardPresenter.java b/InCallUI/src/com/android/incallui/CallCardPresenter.java
index 9308189..2dc4274 100644
--- a/InCallUI/src/com/android/incallui/CallCardPresenter.java
+++ b/InCallUI/src/com/android/incallui/CallCardPresenter.java
@@ -187,8 +187,6 @@
         Log.d(this, "Primary call: " + primary);
         Log.d(this, "Secondary call: " + secondary);
 
-        final boolean outgoingCallReady = newState == InCallState.OUTGOING &&
-                oldState == InCallState.PENDING_OUTGOING;
         final boolean primaryChanged = !Call.areSame(mPrimary, primary);
         final boolean secondaryChanged = !Call.areSame(mSecondary, secondary);
 
diff --git a/InCallUI/src/com/android/incallui/InCallActivity.java b/InCallUI/src/com/android/incallui/InCallActivity.java
index cbb2af2..02635dc 100644
--- a/InCallUI/src/com/android/incallui/InCallActivity.java
+++ b/InCallUI/src/com/android/incallui/InCallActivity.java
@@ -454,14 +454,20 @@
                 intent.removeExtra(NEW_OUTGOING_CALL);
 
                 Point touchPoint = null;
-                Call call = CallList.getInstance().getOutgoingCall();
-                if (call == null) {
-                    call = CallList.getInstance().getPendingOutgoingCall();
-                }
-                if (call != null) {
-                    Bundle extras = call.getTelecommCall().getDetails().getExtras();
-                    touchPoint = (Point) (extras == null ?
-                            null : extras.getParcelable(TouchPointManager.TOUCH_POINT));
+                if (TouchPointManager.getInstance().hasValidPoint()) {
+                    // Use the most immediate touch point in the InCallUi if available
+                    touchPoint = TouchPointManager.getInstance().getPoint();
+                } else {
+                    // Otherwise retrieve the touch point from the call intent
+                    Call call = CallList.getInstance().getOutgoingCall();
+                    if (call == null) {
+                        call = CallList.getInstance().getPendingOutgoingCall();
+                    }
+                    if (call != null) {
+                        Bundle extras = call.getTelecommCall().getDetails().getExtras();
+                        touchPoint = (Point) (extras == null ?
+                                null : extras.getParcelable(TouchPointManager.TOUCH_POINT));
+                    }
                 }
                 mCallCardFragment.animateForNewOutgoingCall(touchPoint);
             }
diff --git a/InCallUI/src/com/android/incallui/InCallPresenter.java b/InCallUI/src/com/android/incallui/InCallPresenter.java
index 38b5f54..77ef49d 100644
--- a/InCallUI/src/com/android/incallui/InCallPresenter.java
+++ b/InCallUI/src/com/android/incallui/InCallPresenter.java
@@ -804,16 +804,18 @@
 
         // A new outgoing call indicates that the user just now dialed a number and when that
         // happens we need to display the screen immediately or show an account picker dialog if
-        // no default is set.
+        // no default is set. However, if the main InCallUI is already visible, we do not want to
+        // re-initiate the start-up animation, so we do not need to do anything here.
         //
         // It is also possible to go into an intermediate state where the call has been initiated
         // but Telecomm has not yet returned with the details of the call (handle, gateway, etc.).
-        // This pending outgoing state also launches the call screen.
+        // This pending outgoing state can also launch the call screen.
         //
         // This is different from the incoming call sequence because we do not need to shock the
         // user with a top-level notification.  Just show the call UI normally.
+        final boolean mainUiNotVisible = !isShowingInCallUi() || !getCallCardFragmentVisible();
         final boolean showCallUi = ((InCallState.PENDING_OUTGOING == newState ||
-                InCallState.OUTGOING == newState) || showAccountPicker);
+                InCallState.OUTGOING == newState) && mainUiNotVisible);
 
         // TODO: Can we be suddenly in a call without it having been in the outgoing or incoming
         // state?  I havent seen that but if it can happen, the code below should be enabled.
@@ -829,7 +831,7 @@
             return mInCallState;
         }
 
-        if (showCallUi) {
+        if (showCallUi || showAccountPicker) {
             Log.i(this, "Start in call UI");
             showInCall(false /* showDialpad */, !showAccountPicker /* newOutgoingCall */);
         } else if (startStartupSequence) {
@@ -1014,6 +1016,18 @@
     }
 
     /**
+     * Returns whether the call card fragment is currently visible.
+     *
+     * @return True if the call card fragment is visible.
+     */
+    public boolean getCallCardFragmentVisible() {
+        if (mInCallActivity != null) {
+            return mInCallActivity.getCallCardFragment().isVisible();
+        }
+        return false;
+    }
+
+    /**
      * @return True if the application is currently running in a right-to-left locale.
      */
     public static boolean isRtl() {
diff --git a/InCallUI/src/com/android/incallui/TelecommAdapter.java b/InCallUI/src/com/android/incallui/TelecommAdapter.java
index 22aff11..1f5c9c5 100644
--- a/InCallUI/src/com/android/incallui/TelecommAdapter.java
+++ b/InCallUI/src/com/android/incallui/TelecommAdapter.java
@@ -220,5 +220,9 @@
         }  else {
             Log.e(this, "error phoneAccountSelected, mAdapter is null");
         }
+
+        if (accountHandle == null) {
+            Log.e(this, "error phoneAccountSelected, accountHandle is null");
+        }
     }
 }