Lazy loading animation of hd icon.

This save us ~180ms on Go device. (analyzed by systrace)
This change also adds some trace information on incallui.

Bug: 64542087
Test: manual
PiperOrigin-RevId: 167201182
Change-Id: I0e8549cfb3534d518e3990696616855bcf7733f2
diff --git a/java/com/android/incallui/ContactInfoCache.java b/java/com/android/incallui/ContactInfoCache.java
index 9b92b48..7bac6d3 100644
--- a/java/com/android/incallui/ContactInfoCache.java
+++ b/java/com/android/incallui/ContactInfoCache.java
@@ -25,6 +25,7 @@
 import android.os.Build.VERSION;
 import android.os.Build.VERSION_CODES;
 import android.os.SystemClock;
+import android.os.Trace;
 import android.provider.ContactsContract.CommonDataKinds.Phone;
 import android.provider.ContactsContract.Contacts;
 import android.provider.ContactsContract.DisplayNameSources;
@@ -123,8 +124,10 @@
   }
 
   private ContactInfoCache(Context context) {
+    Trace.beginSection("ContactInfoCache constructor");
     mContext = context;
     mPhoneNumberService = Bindings.get(context).newPhoneNumberService(context);
+    Trace.endSection();
   }
 
   public static synchronized ContactInfoCache getInstance(Context mContext) {
@@ -343,6 +346,7 @@
       @NonNull final DialerCall call,
       final boolean isIncoming,
       @NonNull ContactInfoCacheCallback callback) {
+    Trace.beginSection("ContactInfoCache.findInfo");
     Assert.isMainThread();
     Objects.requireNonNull(callback);
 
@@ -364,6 +368,7 @@
       callback.onContactInfoComplete(callId, cacheEntry);
       // If no other callbacks are in flight, we're done.
       if (callBacks == null) {
+        Trace.endSection();
         return;
       }
     }
@@ -374,6 +379,7 @@
       callBacks.add(callback);
       if (!forceQuery) {
         Log.d(TAG, "No need to query again, just return and wait for existing query to finish");
+        Trace.endSection();
         return;
       }
     } else {
@@ -412,6 +418,7 @@
               callId, call.getNumberPresentation(), callerInfo, false, queryToken);
       sendInfoNotifications(callId, initialCacheEntry);
     }
+    Trace.endSection();
   }
 
   @AnyThread
@@ -421,6 +428,7 @@
       CallerInfo callerInfo,
       boolean didLocalLookup,
       CallerInfoQueryToken queryToken) {
+    Trace.beginSection("ContactInfoCache.updateCallerInfoInCacheOnAnyThread");
     Log.d(
         TAG,
         "updateCallerInfoInCacheOnAnyThread: callId = "
@@ -488,6 +496,7 @@
       Log.d(TAG, "put entry into map if not exists: " + cacheEntry);
       mInfoMap.putIfAbsent(callId, cacheEntry);
     }
+    Trace.endSection();
     return cacheEntry;
   }
 
@@ -644,6 +653,7 @@
   /** Sends the updated information to call the callbacks for the entry. */
   @MainThread
   private void sendInfoNotifications(String callId, ContactCacheEntry entry) {
+    Trace.beginSection("ContactInfoCache.sendInfoNotifications");
     Assert.isMainThread();
     final Set<ContactInfoCacheCallback> callBacks = mCallBacks.get(callId);
     if (callBacks != null) {
@@ -651,10 +661,12 @@
         callBack.onContactInfoComplete(callId, entry);
       }
     }
+    Trace.endSection();
   }
 
   @MainThread
   private void sendImageNotifications(String callId, ContactCacheEntry entry) {
+    Trace.beginSection("ContactInfoCache.sendImageNotifications");
     Assert.isMainThread();
     final Set<ContactInfoCacheCallback> callBacks = mCallBacks.get(callId);
     if (callBacks != null && entry.photo != null) {
@@ -662,6 +674,7 @@
         callBack.onImageLoadComplete(callId, entry);
       }
     }
+    Trace.endSection();
   }
 
   private void clearCallbacks(String callId) {
diff --git a/java/com/android/incallui/InCallPresenter.java b/java/com/android/incallui/InCallPresenter.java
index 9b1f674..3f87a59 100644
--- a/java/com/android/incallui/InCallPresenter.java
+++ b/java/com/android/incallui/InCallPresenter.java
@@ -769,15 +769,19 @@
         "InCallPresenter.onIncomingCall", "Phone switching state: " + oldState + " -> " + newState);
     mInCallState = newState;
 
+    Trace.beginSection("listener.onIncomingCall");
     for (IncomingCallListener listener : mIncomingCallListeners) {
       listener.onIncomingCall(oldState, mInCallState, call);
     }
+    Trace.endSection();
 
+    Trace.beginSection("onPrimaryCallStateChanged");
     if (mInCallActivity != null) {
       // Re-evaluate which fragment is being shown.
       mInCallActivity.onPrimaryCallStateChanged();
     }
     Trace.endSection();
+    Trace.endSection();
   }
 
   @Override
@@ -1278,6 +1282,7 @@
    * UI needs to be started or finished depending on the new state and does it.
    */
   private InCallState startOrFinishUi(InCallState newState) {
+    Trace.beginSection("InCallPresenter.startOrFinishUi");
     LogUtil.d(
         "InCallPresenter.startOrFinishUi", "startOrFinishUi: " + mInCallState + " -> " + newState);
 
@@ -1286,6 +1291,7 @@
     // If the state isn't changing we have already done any starting/stopping of activities in
     // a previous pass...so lets cut out early
     if (newState == mInCallState) {
+      Trace.endSection();
       return newState;
     }
 
@@ -1364,6 +1370,7 @@
       LogUtil.i(
           "InCallPresenter.startOrFinishUi",
           "Undo the state change: " + newState + " -> " + mInCallState);
+      Trace.endSection();
       return mInCallState;
     }
 
@@ -1390,6 +1397,7 @@
       attemptCleanup();
     }
 
+    Trace.endSection();
     return newState;
   }
 
diff --git a/java/com/android/incallui/StatusBarNotifier.java b/java/com/android/incallui/StatusBarNotifier.java
index e6969c1..92ffae3 100644
--- a/java/com/android/incallui/StatusBarNotifier.java
+++ b/java/com/android/incallui/StatusBarNotifier.java
@@ -40,6 +40,7 @@
 import android.net.Uri;
 import android.os.Build.VERSION;
 import android.os.Build.VERSION_CODES;
+import android.os.Trace;
 import android.support.annotation.ColorRes;
 import android.support.annotation.NonNull;
 import android.support.annotation.Nullable;
@@ -236,6 +237,7 @@
 
   @RequiresPermission(Manifest.permission.READ_PHONE_STATE)
   private void showNotification(final CallList callList, final DialerCall call) {
+    Trace.beginSection("StatusBarNotifier.showNotification");
     final boolean isIncoming =
         (call.getState() == DialerCall.State.INCOMING
             || call.getState() == DialerCall.State.CALL_WAITING);
@@ -269,20 +271,24 @@
             }
           }
         });
+    Trace.endSection();
   }
 
   /** Sets up the main Ui for the notification */
   @RequiresPermission(Manifest.permission.READ_PHONE_STATE)
   private void buildAndSendNotification(
       CallList callList, DialerCall originalCall, ContactCacheEntry contactInfo) {
+    Trace.beginSection("StatusBarNotifier.buildAndSendNotification");
     // This can get called to update an existing notification after contact information has come
     // back. However, it can happen much later. Before we continue, we need to make sure that
     // the call being passed in is still the one we want to show in the notification.
     final DialerCall call = getCallToShow(callList);
     if (call == null || !call.getId().equals(originalCall.getId())) {
+      Trace.endSection();
       return;
     }
 
+    Trace.beginSection("prepare work");
     final int callState = call.getState();
 
     // Check if data has changed; if nothing is different, don't issue another notification.
@@ -314,6 +320,7 @@
     } else {
       notificationType = NOTIFICATION_IN_CALL;
     }
+    Trace.endSection(); // prepare work
 
     if (!checkForChangeAndSaveData(
         iconResId,
@@ -323,6 +330,7 @@
         callState,
         notificationType,
         contactInfo.contactRingtoneUri)) {
+      Trace.endSection();
       return;
     }
 
@@ -409,6 +417,7 @@
 
     addPersonReference(builder, contactInfo, call);
 
+    Trace.beginSection("fire notification");
     // Fire off the notification
     Notification notification = builder.build();
 
@@ -448,8 +457,10 @@
               memoryInfo.availMem),
           e);
     }
+    Trace.endSection();
     call.getLatencyReport().onNotificationShown();
     mCurrentNotification = notificationType;
+    Trace.endSection();
   }
 
   @Nullable
diff --git a/java/com/android/incallui/answer/impl/AnswerFragment.java b/java/com/android/incallui/answer/impl/AnswerFragment.java
index db6d43d..18de72e 100644
--- a/java/com/android/incallui/answer/impl/AnswerFragment.java
+++ b/java/com/android/incallui/answer/impl/AnswerFragment.java
@@ -29,6 +29,7 @@
 import android.os.Bundle;
 import android.os.Handler;
 import android.os.Looper;
+import android.os.Trace;
 import android.support.annotation.DrawableRes;
 import android.support.annotation.FloatRange;
 import android.support.annotation.NonNull;
@@ -657,6 +658,7 @@
   @Override
   public View onCreateView(
       LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
+    Trace.beginSection("AnswerFragment.onCreateView");
     Bundle arguments = getArguments();
     Assert.checkState(arguments.containsKey(ARG_CALL_ID));
     Assert.checkState(arguments.containsKey(ARG_IS_VIDEO_CALL));
@@ -729,6 +731,7 @@
       }
     }
 
+    Trace.endSection();
     return view;
   }
 
diff --git a/java/com/android/incallui/contactgrid/ContactGridManager.java b/java/com/android/incallui/contactgrid/ContactGridManager.java
index ddf16e3..18bab6a 100644
--- a/java/com/android/incallui/contactgrid/ContactGridManager.java
+++ b/java/com/android/incallui/contactgrid/ContactGridManager.java
@@ -315,6 +315,7 @@
         info.isAssistedDialedVisisble ? View.VISIBLE : View.GONE);
     if (hdIconImageView.getVisibility() == View.GONE) {
       if (info.isHdAttemptingIconVisible) {
+        hdIconImageView.setImageResource(R.drawable.asd_hd_icon);
         hdIconImageView.setVisibility(View.VISIBLE);
         hdIconImageView.setActivated(false);
         Drawable drawableCurrent = hdIconImageView.getDrawable().getCurrent();
@@ -322,6 +323,7 @@
           ((Animatable) drawableCurrent).start();
         }
       } else if (info.isHdIconVisible) {
+        hdIconImageView.setImageResource(R.drawable.asd_hd_icon);
         hdIconImageView.setVisibility(View.VISIBLE);
         hdIconImageView.setActivated(true);
       }
diff --git a/java/com/android/incallui/contactgrid/res/layout/incall_contactgrid_bottom_row.xml b/java/com/android/incallui/contactgrid/res/layout/incall_contactgrid_bottom_row.xml
index 8850dd8..c545c25 100644
--- a/java/com/android/incallui/contactgrid/res/layout/incall_contactgrid_bottom_row.xml
+++ b/java/com/android/incallui/contactgrid/res/layout/incall_contactgrid_bottom_row.xml
@@ -29,7 +29,6 @@
   <ImageView
       android:id="@+id/contactgrid_hdIcon"
       style="@style/BottomRowIcon"
-      android:src="@drawable/asd_hd_icon"
       android:visibility="gone"/>
   <ImageView
       android:id="@+id/contactgrid_assistedDialingIcon"