Update AOSP Dialer source from internal google3 repository at
cl/152373142.

Test: make, treehugger

This CL updates the AOSP Dialer source with all the changes that have
gone into the private google3 repository. This includes all the
changes from cl/151342913 (3/27/2017) to cl/152373142 (4/06/2017).

This goal of these drops is to keep the AOSP source in sync with the
internal google3 repository. Currently these sync are done by hand
with very minor modifications to the internal source code.
See the Android.mk file for list of modifications.
Our current goal is to do frequent drops (daily if possible) and
eventually switched to an automated process.

Change-Id: I2fbc88cf6867b90ac8b65f75e5e34468988c7217
diff --git a/java/com/android/incallui/CallCardPresenter.java b/java/com/android/incallui/CallCardPresenter.java
index 8cd9a07..6a34688 100644
--- a/java/com/android/incallui/CallCardPresenter.java
+++ b/java/com/android/incallui/CallCardPresenter.java
@@ -50,6 +50,8 @@
 import com.android.dialer.enrichedcall.EnrichedCallComponent;
 import com.android.dialer.enrichedcall.EnrichedCallManager;
 import com.android.dialer.enrichedcall.Session;
+import com.android.dialer.logging.Logger;
+import com.android.dialer.logging.nano.DialerImpression;
 import com.android.dialer.multimedia.MultimediaData;
 import com.android.dialer.oem.MotorolaUtils;
 import com.android.incallui.ContactInfoCache.ContactCacheEntry;
@@ -182,8 +184,6 @@
       mContactsPreferences.refreshValue(ContactsPreferences.DISPLAY_ORDER_KEY);
     }
 
-    EnrichedCallComponent.get(mContext).getEnrichedCallManager().registerStateChangedListener(this);
-
     // Contact search may have completed before ui is ready.
     if (mPrimaryContactInfo != null) {
       updatePrimaryDisplayInfo();
@@ -196,9 +196,26 @@
     InCallPresenter.getInstance().addInCallEventListener(this);
     isInCallScreenReady = true;
 
+    // Log location impressions
+    if (isOutgoingEmergencyCall(mPrimary)) {
+      Logger.get(mContext).logImpression(DialerImpression.Type.EMERGENCY_NEW_EMERGENCY_CALL);
+    } else if (isIncomingEmergencyCall(mPrimary) || isIncomingEmergencyCall(mSecondary)) {
+      Logger.get(mContext).logImpression(DialerImpression.Type.EMERGENCY_CALLBACK);
+    }
+
     // Showing the location may have been skipped if the UI wasn't ready during previous layout.
     if (shouldShowLocation()) {
       updatePrimaryDisplayInfo();
+
+      // Log location impressions
+      if (!hasLocationPermission()) {
+        Logger.get(mContext).logImpression(DialerImpression.Type.EMERGENCY_NO_LOCATION_PERMISSION);
+      } else if (isBatteryTooLowForEmergencyLocation()) {
+        Logger.get(mContext)
+            .logImpression(DialerImpression.Type.EMERGENCY_BATTERY_TOO_LOW_TO_GET_LOCATION);
+      } else if (!callLocation.canGetLocation(mContext)) {
+        Logger.get(mContext).logImpression(DialerImpression.Type.EMERGENCY_CANT_GET_LOCATION);
+      }
     }
   }
 
@@ -207,9 +224,6 @@
     LogUtil.i("CallCardController.onInCallScreenUnready", null);
     Assert.checkState(isInCallScreenReady);
 
-    EnrichedCallComponent.get(mContext)
-        .getEnrichedCallManager()
-        .unregisterStateChangedListener(this);
     // stop getting call state changes
     InCallPresenter.getInstance().removeListener(this);
     InCallPresenter.getInstance().removeIncomingCallListener(this);
@@ -714,7 +728,9 @@
               number,
               name,
               nameIsNumber,
-              mPrimaryContactInfo.location,
+              shouldShowLocationAsLabel(nameIsNumber, mPrimaryContactInfo.shouldShowLocation)
+                  ? mPrimaryContactInfo.location
+                  : null,
               isChildNumberShown || isCallSubjectShown ? null : mPrimaryContactInfo.label,
               mPrimaryContactInfo.photo,
               mPrimaryContactInfo.photoType,
@@ -739,6 +755,17 @@
     }
   }
 
+  private static boolean shouldShowLocationAsLabel(
+      boolean nameIsNumber, boolean shouldShowLocation) {
+    if (nameIsNumber) {
+      return true;
+    }
+    if (shouldShowLocation) {
+      return true;
+    }
+    return false;
+  }
+
   private Fragment getLocationFragment() {
     if (!ConfigProviderBindings.get(mContext)
         .getBoolean(CONFIG_ENABLE_EMERGENCY_LOCATION, CONFIG_ENABLE_EMERGENCY_LOCATION_DEFAULT)) {
@@ -1031,11 +1058,21 @@
 
   @Override
   public void onInCallScreenResumed() {
+    EnrichedCallComponent.get(mContext).getEnrichedCallManager().registerStateChangedListener(this);
+    updatePrimaryDisplayInfo();
+
     if (shouldSendAccessibilityEvent) {
       handler.postDelayed(sendAccessibilityEventRunnable, ACCESSIBILITY_ANNOUNCEMENT_DELAY_MILLIS);
     }
   }
 
+  @Override
+  public void onInCallScreenPaused() {
+    EnrichedCallComponent.get(mContext)
+        .getEnrichedCallManager()
+        .unregisterStateChangedListener(this);
+  }
+
   static boolean sendAccessibilityEvent(Context context, InCallScreen inCallScreen) {
     AccessibilityManager am =
         (AccessibilityManager) context.getSystemService(Context.ACCESSIBILITY_SERVICE);