Show icon and network label when using Wifi.

+ Add Wifi icon and network label, to be shown when CAPABILITY_WIFI
is present on the primary call. Assume we can infer the network label
from the connection info returned by the WifiManager, supposing that
the phone can only be connected to one wifi network.
+ Add helper to strip quotation marks from wifi network name.
+ Reposition HD audio icon beneath the name, and to the left of the
number/location information.
+ Adjust assets and layout of call state and hd audio icons, to
center them in a more visually pleasing way in the view.

Bug: 19151850
Change-Id: Ic23d1e744960e80b65bc34a8e709266af508fe21
diff --git a/res/drawable-hdpi/ic_hd_18dp.png b/res/drawable-hdpi/ic_hd_18dp.png
new file mode 100644
index 0000000..ade1788
--- /dev/null
+++ b/res/drawable-hdpi/ic_hd_18dp.png
Binary files differ
diff --git a/res/drawable-hdpi/ic_hd_audio.png b/res/drawable-hdpi/ic_hd_audio.png
deleted file mode 100644
index cccaf49..0000000
--- a/res/drawable-hdpi/ic_hd_audio.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable-hdpi/ic_signal_wifi_4_bar_18dp.png b/res/drawable-hdpi/ic_signal_wifi_4_bar_18dp.png
new file mode 100644
index 0000000..d7b9805
--- /dev/null
+++ b/res/drawable-hdpi/ic_signal_wifi_4_bar_18dp.png
Binary files differ
diff --git a/res/drawable-mdpi/ic_hd_18dp.png b/res/drawable-mdpi/ic_hd_18dp.png
new file mode 100644
index 0000000..82c9726
--- /dev/null
+++ b/res/drawable-mdpi/ic_hd_18dp.png
Binary files differ
diff --git a/res/drawable-mdpi/ic_hd_audio.png b/res/drawable-mdpi/ic_hd_audio.png
deleted file mode 100644
index 6353b7a..0000000
--- a/res/drawable-mdpi/ic_hd_audio.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable-mdpi/ic_signal_wifi_4_bar_18dp.png b/res/drawable-mdpi/ic_signal_wifi_4_bar_18dp.png
new file mode 100644
index 0000000..d537ab4
--- /dev/null
+++ b/res/drawable-mdpi/ic_signal_wifi_4_bar_18dp.png
Binary files differ
diff --git a/res/drawable-xhdpi/ic_hd_18dp.png b/res/drawable-xhdpi/ic_hd_18dp.png
new file mode 100644
index 0000000..35bf51a
--- /dev/null
+++ b/res/drawable-xhdpi/ic_hd_18dp.png
Binary files differ
diff --git a/res/drawable-xhdpi/ic_hd_audio.png b/res/drawable-xhdpi/ic_hd_audio.png
deleted file mode 100644
index 6d05d45..0000000
--- a/res/drawable-xhdpi/ic_hd_audio.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable-xhdpi/ic_signal_wifi_4_bar_18dp.png b/res/drawable-xhdpi/ic_signal_wifi_4_bar_18dp.png
new file mode 100644
index 0000000..5a53192
--- /dev/null
+++ b/res/drawable-xhdpi/ic_signal_wifi_4_bar_18dp.png
Binary files differ
diff --git a/res/drawable-xxhdpi/ic_hd_18dp.png b/res/drawable-xxhdpi/ic_hd_18dp.png
new file mode 100644
index 0000000..510aa6e
--- /dev/null
+++ b/res/drawable-xxhdpi/ic_hd_18dp.png
Binary files differ
diff --git a/res/drawable-xxhdpi/ic_hd_audio.png b/res/drawable-xxhdpi/ic_hd_audio.png
deleted file mode 100644
index 44294ba..0000000
--- a/res/drawable-xxhdpi/ic_hd_audio.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable-xxhdpi/ic_signal_wifi_4_bar_18dp.png b/res/drawable-xxhdpi/ic_signal_wifi_4_bar_18dp.png
new file mode 100644
index 0000000..b627198
--- /dev/null
+++ b/res/drawable-xxhdpi/ic_signal_wifi_4_bar_18dp.png
Binary files differ
diff --git a/res/drawable-xxxhdpi/ic_hd_18dp.png b/res/drawable-xxxhdpi/ic_hd_18dp.png
new file mode 100644
index 0000000..dd08bbb
--- /dev/null
+++ b/res/drawable-xxxhdpi/ic_hd_18dp.png
Binary files differ
diff --git a/res/drawable-xxxhdpi/ic_hd_audio.png b/res/drawable-xxxhdpi/ic_hd_audio.png
deleted file mode 100644
index 459cd8f..0000000
--- a/res/drawable-xxxhdpi/ic_hd_audio.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable-xxxhdpi/ic_signal_wifi_4_bar_18dp.png b/res/drawable-xxxhdpi/ic_signal_wifi_4_bar_18dp.png
new file mode 100644
index 0000000..f4105ec
--- /dev/null
+++ b/res/drawable-xxxhdpi/ic_signal_wifi_4_bar_18dp.png
Binary files differ
diff --git a/res/layout/primary_call_info.xml b/res/layout/primary_call_info.xml
index 71369d4..8f0c0e2 100644
--- a/res/layout/primary_call_info.xml
+++ b/res/layout/primary_call_info.xml
@@ -43,22 +43,21 @@
         <!-- Subscription provider or WiFi calling icon displayed to the left of the label -->
         <ImageView android:id="@+id/callStateIcon"
             android:layout_width="16dp"
-            android:layout_height="16dp"
-            android:layout_marginEnd="4dp"
-            android:baselineAlignBottom="true"
+            android:layout_height="match_parent"
+            android:layout_marginEnd="8dp"
             android:tint="@color/incall_accent_color"
             android:alpha="0.0"
-            android:scaleType="centerInside"
+            android:scaleType="center"
             android:visibility="gone" />
 
         <ImageView android:id="@+id/videoCallIcon"
             android:src="@drawable/ic_toolbar_video"
             android:layout_width="16dp"
-            android:layout_height="16dp"
-            android:layout_marginEnd="4dp"
+            android:layout_height="match_parent"
+            android:layout_marginEnd="16dp"
             android:baselineAlignBottom="true"
             android:tint="@color/incall_accent_color"
-            android:scaleType="centerInside"
+            android:scaleType="center"
             android:visibility="gone" />
 
         <TextView android:id="@+id/callStateLabel"
@@ -96,29 +95,38 @@
         android:clipChildren="false"
         android:clipToPadding="false">
 
+        <ImageView android:id="@+id/hdAudioIcon"
+            android:src="@drawable/ic_hd_18dp"
+            android:layout_width="16dp"
+            android:layout_height="match_parent"
+            android:layout_marginEnd="8dp"
+            android:tint="@color/incall_call_banner_subtext_color"
+            android:scaleType="center"
+            android:visibility="gone" />
+
         <!-- Label (like "Mobile" or "Work", if present) and phone number, side by side -->
         <LinearLayout android:id="@+id/labelAndNumber"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:orientation="horizontal">
 
-                <TextView android:id="@+id/label"
-                    android:layout_width="wrap_content"
-                    android:layout_height="wrap_content"
-                    android:textAppearance="?android:attr/textAppearanceSmall"
-                    android:textColor="@color/incall_call_banner_subtext_color"
-                    android:textSize="@dimen/call_label_text_size"
-                    android:singleLine="true"
-                    android:textDirection="ltr" />
+            <TextView android:id="@+id/label"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:textAppearance="?android:attr/textAppearanceSmall"
+                android:textColor="@color/incall_call_banner_subtext_color"
+                android:textSize="@dimen/call_label_text_size"
+                android:singleLine="true"
+                android:textDirection="ltr" />
 
-                <TextView android:id="@+id/phoneNumber"
-                    android:layout_width="match_parent"
-                    android:layout_height="wrap_content"
-                    android:layout_marginStart="6dp"
-                    android:textAppearance="?android:attr/textAppearanceSmall"
-                    android:textColor="@color/incall_call_banner_subtext_color"
-                    android:textSize="@dimen/call_label_text_size"
-                    android:singleLine="true" />
+            <TextView android:id="@+id/phoneNumber"
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"
+                android:layout_marginStart="6dp"
+                android:textAppearance="?android:attr/textAppearanceSmall"
+                android:textColor="@color/incall_call_banner_subtext_color"
+                android:textSize="@dimen/call_label_text_size"
+                android:singleLine="true" />
 
         </LinearLayout>
 
@@ -127,7 +135,6 @@
             android:layout_width="0dp"
             android:layout_height="wrap_content"
             android:layout_weight="1"
-            android:layout_centerVertical="true"
             android:textAlignment="viewEnd"
             android:textAppearance="?android:attr/textAppearanceSmall"
             android:textColor="@color/incall_call_banner_subtext_color"
diff --git a/src/com/android/incallui/CallCardFragment.java b/src/com/android/incallui/CallCardFragment.java
index 81b9ff7..8148761 100644
--- a/src/com/android/incallui/CallCardFragment.java
+++ b/src/com/android/incallui/CallCardFragment.java
@@ -79,6 +79,7 @@
     private ImageView mCallStateVideoCallIcon;
     private TextView mCallStateLabel;
     private TextView mCallTypeLabel;
+    private ImageView mHdAudioIcon;
     private View mCallNumberAndLabel;
     private ImageView mPhoto;
     private TextView mElapsedTime;
@@ -181,6 +182,7 @@
         mCallStateIcon = (ImageView) view.findViewById(R.id.callStateIcon);
         mCallStateVideoCallIcon = (ImageView) view.findViewById(R.id.videoCallIcon);
         mCallStateLabel = (TextView) view.findViewById(R.id.callStateLabel);
+        mHdAudioIcon = (ImageView) view.findViewById(R.id.hdAudioIcon);
         mCallNumberAndLabel = view.findViewById(R.id.labelAndNumber);
         mCallTypeLabel = (TextView) view.findViewById(R.id.callTypeLabel);
         mElapsedTime = (TextView) view.findViewById(R.id.elapsedTime);
@@ -796,6 +798,16 @@
     }
 
     /**
+     * Changes the visibility of the HD audio icon.
+     *
+     * @param visible {@code true} if the UI should show the HD audio icon.
+     */
+    @Override
+    public void showHdAudioIndicator(boolean visible) {
+        mHdAudioIcon.setVisibility(visible ? View.VISIBLE : View.GONE);
+    }
+
+    /**
      * Changes the visibility of the "manage conference call" button.
      *
      * @param visible Whether to set the button to be visible or not.
diff --git a/src/com/android/incallui/CallCardPresenter.java b/src/com/android/incallui/CallCardPresenter.java
index cb378a6..47e4328 100644
--- a/src/com/android/incallui/CallCardPresenter.java
+++ b/src/com/android/incallui/CallCardPresenter.java
@@ -23,7 +23,9 @@
 import android.content.pm.PackageManager;
 import android.graphics.drawable.Drawable;
 import android.net.Uri;
+import android.net.wifi.WifiManager;
 import android.os.Bundle;
+import android.telecom.Call.Details;
 import android.telecom.DisconnectCause;
 import android.telecom.PhoneAccount;
 import android.telecom.PhoneAccountHandle;
@@ -64,7 +66,9 @@
     private ContactCacheEntry mPrimaryContactInfo;
     private ContactCacheEntry mSecondaryContactInfo;
     private CallTimer mCallTimer;
+
     private Context mContext;
+    private WifiManager mWifiManager;
 
     public static class ContactLookupCallback implements ContactInfoCacheCallback {
         private final WeakReference<CallCardPresenter> mCallCardPresenter;
@@ -105,6 +109,7 @@
 
     public void init(Context context, Call call) {
         mContext = Preconditions.checkNotNull(context);
+        mWifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
 
         // Call may be null if disconnect happened already.
         if (call != null) {
@@ -219,7 +224,7 @@
         }
 
         // Start/stop timers.
-        if (mPrimary != null && mPrimary.getState() == Call.State.ACTIVE) {
+        if (isPrimaryCallActive()) {
             Log.d(this, "Starting the calltime timer");
             mCallTimer.start(CALL_TIME_UPDATE_INTERVAL_MS);
         } else {
@@ -242,6 +247,7 @@
                     null,
                     null,
                     null);
+            getUi().showHdAudioIndicator(false);
         }
 
         // Hide/show the contact photo based on the video state.
@@ -262,13 +268,11 @@
     }
 
     @Override
-    public void onDetailsChanged(Call call, android.telecom.Call.Details details) {
+    public void onDetailsChanged(Call call, Details details) {
         updatePrimaryCallState();
 
-        if (call.can(android.telecom.Call.Details.CAPABILITY_MANAGE_CONFERENCE) !=
-                android.telecom.Call.Details.can(
-                        details.getCallCapabilities(),
-                        android.telecom.Call.Details.CAPABILITY_MANAGE_CONFERENCE)) {
+        if (call.can(Details.CAPABILITY_MANAGE_CONFERENCE) !=
+                Details.can(details.getCallCapabilities(), Details.CAPABILITY_MANAGE_CONFERENCE)) {
             maybeShowManageConferenceCallButton();
         }
     }
@@ -298,6 +302,11 @@
                     getConnectionLabel(),
                     getCallStateIcon(),
                     getGatewayNumber());
+
+            boolean showHdAudioIndicator =
+                    isPrimaryCallActive() && primaryCallCan(Details.CAPABILITY_HIGH_DEF_AUDIO);
+            getUi().showHdAudioIndicator(showHdAudioIndicator);
+
             setCallbackNumber();
         }
     }
@@ -320,7 +329,7 @@
             return false;
         }
 
-        return mPrimary.can(android.telecom.Call.Details.CAPABILITY_MANAGE_CONFERENCE);
+        return mPrimary.can(Details.CAPABILITY_MANAGE_CONFERENCE);
     }
 
     private void setCallbackNumber() {
@@ -353,10 +362,10 @@
     public void updateCallTime() {
         final CallCardUi ui = getUi();
 
-        if (ui == null || mPrimary == null || mPrimary.getState() != Call.State.ACTIVE) {
-            if (ui != null) {
-                ui.setPrimaryCallElapsedTime(false, 0);
-            }
+        if (ui == null) {
+            mCallTimer.cancel();
+        } else if (!isPrimaryCallActive()) {
+            ui.setPrimaryCallElapsedTime(false, 0);
             mCallTimer.cancel();
         } else {
             final long callStart = mPrimary.getConnectTimeMillis();
@@ -591,6 +600,13 @@
             return statusHints.getLabel().toString();
         }
 
+        // Assume the SSID of the connection reported by the WifiManager is the name of the wifi
+        // network used for calling, since currently a phone only connects to a single wifi network.
+        if (isPrimaryCallActive() && primaryCallCan(Details.CAPABILITY_WIFI)
+                && mWifiManager.getConnectionInfo() != null) {
+            return formatWifiSSID(mWifiManager.getConnectionInfo().getSSID());
+        }
+
         if (hasOutgoingGatewayCall() && getUi() != null) {
             // Return the label for the gateway app on outgoing calls.
             final PackageManager pm = mContext.getPackageManager();
@@ -616,11 +632,8 @@
             }
         }
 
-        // Return high definition audio icon if the capability is indicated.
-        if (mPrimary.getTelecommCall().getDetails().can(
-                android.telecom.Call.Details.CAPABILITY_HIGH_DEF_AUDIO)
-                && mPrimary.getState() == Call.State.ACTIVE) {
-            return mContext.getResources().getDrawable(R.drawable.ic_hd_audio);
+        if (isPrimaryCallActive() && primaryCallCan(Details.CAPABILITY_WIFI)) {
+            return mContext.getResources().getDrawable(R.drawable.ic_signal_wifi_4_bar_18dp);
         }
 
         return null;
@@ -700,9 +713,16 @@
         ui.setCallCardVisible(!isFullScreenVideo);
     }
 
+    private boolean isPrimaryCallActive() {
+        return mPrimary != null && mPrimary.getState() == Call.State.ACTIVE;
+    }
+
+    private boolean primaryCallCan(int capability) {
+        return mPrimary.getTelecommCall().getDetails().can(capability);
+    }
+
     private String getConferenceString(Call call) {
-        boolean isGenericConference = call.can(
-                android.telecom.Call.Details.CAPABILITY_GENERIC_CONFERENCE);
+        boolean isGenericConference = call.can(Details.CAPABILITY_GENERIC_CONFERENCE);
         Log.v(this, "getConferenceString: " + isGenericConference);
 
         final int resId = isGenericConference
@@ -711,8 +731,7 @@
     }
 
     private Drawable getConferencePhoto(Call call) {
-        boolean isGenericConference = call.can(
-                android.telecom.Call.Details.CAPABILITY_GENERIC_CONFERENCE);
+        boolean isGenericConference = call.can(Details.CAPABILITY_GENERIC_CONFERENCE);
         Log.v(this, "getConferencePhoto: " + isGenericConference);
 
         final int resId = isGenericConference
@@ -722,6 +741,34 @@
         return photo;
     }
 
+    /**
+     * Strip quotations off the outside of a Wifi SSID identifier. For example, \"GoogleGuest\"
+     * becomes GoogleGuest.
+     *
+     * TODO: Move into utility class.
+     * TODO: Add unit tests.
+     *
+     * @param ssid The ssid of the wifi network.
+     */
+    private String formatWifiSSID(String ssid) {
+        if (TextUtils.isEmpty(ssid)) {
+            return "";
+        }
+
+        // Trim quotation if first character.
+        if (ssid.charAt(0) == '\"') {
+            ssid = ssid.substring(1);
+        }
+
+        // Trim quotation if last character.
+        int lastIndex = ssid.length() - 1;
+        if (lastIndex >= 0 && ssid.charAt(lastIndex) == '\"') {
+            ssid = ssid.substring(0, lastIndex);
+        }
+
+        return ssid;
+    }
+
     public interface CallCardUi extends Ui {
         void setVisible(boolean on);
         void setCallCardVisible(boolean visible);
@@ -741,6 +788,7 @@
         void setCallbackNumber(String number, boolean isEmergencyCalls);
         void setPhotoVisible(boolean isVisible);
         void setProgressSpinnerVisible(boolean visible);
+        void showHdAudioIndicator(boolean visible);
         void showManageConferenceCallButton(boolean visible);
         boolean isManageConferenceVisible();
     }