From cf61ca00e96f7fb723ca2d4406ec24485a60acd1 Mon Sep 17 00:00:00 2001 From: wangqi Date: Thu, 31 Aug 2017 15:32:55 -0700 Subject: 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 --- java/com/android/incallui/ContactInfoCache.java | 13 +++++++++++++ java/com/android/incallui/InCallPresenter.java | 8 ++++++++ java/com/android/incallui/StatusBarNotifier.java | 11 +++++++++++ java/com/android/incallui/answer/impl/AnswerFragment.java | 3 +++ .../android/incallui/contactgrid/ContactGridManager.java | 2 ++ .../res/layout/incall_contactgrid_bottom_row.xml | 1 - 6 files changed, 37 insertions(+), 1 deletion(-) (limited to 'java/com') diff --git a/java/com/android/incallui/ContactInfoCache.java b/java/com/android/incallui/ContactInfoCache.java index 9b92b487c..7bac6d329 100644 --- a/java/com/android/incallui/ContactInfoCache.java +++ b/java/com/android/incallui/ContactInfoCache.java @@ -25,6 +25,7 @@ import android.net.Uri; 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 @@ public class ContactInfoCache implements OnImageLoadCompleteListener { } 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 @@ public class ContactInfoCache implements OnImageLoadCompleteListener { @NonNull final DialerCall call, final boolean isIncoming, @NonNull ContactInfoCacheCallback callback) { + Trace.beginSection("ContactInfoCache.findInfo"); Assert.isMainThread(); Objects.requireNonNull(callback); @@ -364,6 +368,7 @@ public class ContactInfoCache implements OnImageLoadCompleteListener { callback.onContactInfoComplete(callId, cacheEntry); // If no other callbacks are in flight, we're done. if (callBacks == null) { + Trace.endSection(); return; } } @@ -374,6 +379,7 @@ public class ContactInfoCache implements OnImageLoadCompleteListener { 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 @@ public class ContactInfoCache implements OnImageLoadCompleteListener { callId, call.getNumberPresentation(), callerInfo, false, queryToken); sendInfoNotifications(callId, initialCacheEntry); } + Trace.endSection(); } @AnyThread @@ -421,6 +428,7 @@ public class ContactInfoCache implements OnImageLoadCompleteListener { CallerInfo callerInfo, boolean didLocalLookup, CallerInfoQueryToken queryToken) { + Trace.beginSection("ContactInfoCache.updateCallerInfoInCacheOnAnyThread"); Log.d( TAG, "updateCallerInfoInCacheOnAnyThread: callId = " @@ -488,6 +496,7 @@ public class ContactInfoCache implements OnImageLoadCompleteListener { Log.d(TAG, "put entry into map if not exists: " + cacheEntry); mInfoMap.putIfAbsent(callId, cacheEntry); } + Trace.endSection(); return cacheEntry; } @@ -644,6 +653,7 @@ public class ContactInfoCache implements OnImageLoadCompleteListener { /** 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 callBacks = mCallBacks.get(callId); if (callBacks != null) { @@ -651,10 +661,12 @@ public class ContactInfoCache implements OnImageLoadCompleteListener { callBack.onContactInfoComplete(callId, entry); } } + Trace.endSection(); } @MainThread private void sendImageNotifications(String callId, ContactCacheEntry entry) { + Trace.beginSection("ContactInfoCache.sendImageNotifications"); Assert.isMainThread(); final Set callBacks = mCallBacks.get(callId); if (callBacks != null && entry.photo != null) { @@ -662,6 +674,7 @@ public class ContactInfoCache implements OnImageLoadCompleteListener { 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 9b1f674bd..3f87a592d 100644 --- a/java/com/android/incallui/InCallPresenter.java +++ b/java/com/android/incallui/InCallPresenter.java @@ -769,15 +769,19 @@ public class InCallPresenter implements CallList.Listener { "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 @@ public class InCallPresenter implements CallList.Listener { * 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 @@ public class InCallPresenter implements CallList.Listener { // 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 @@ public class InCallPresenter implements CallList.Listener { LogUtil.i( "InCallPresenter.startOrFinishUi", "Undo the state change: " + newState + " -> " + mInCallState); + Trace.endSection(); return mInCallState; } @@ -1390,6 +1397,7 @@ public class InCallPresenter implements CallList.Listener { attemptCleanup(); } + Trace.endSection(); return newState; } diff --git a/java/com/android/incallui/StatusBarNotifier.java b/java/com/android/incallui/StatusBarNotifier.java index e6969c147..92ffae37c 100644 --- a/java/com/android/incallui/StatusBarNotifier.java +++ b/java/com/android/incallui/StatusBarNotifier.java @@ -40,6 +40,7 @@ import android.media.AudioAttributes; 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 @@ public class StatusBarNotifier @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 @@ public class StatusBarNotifier } } }); + 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 @@ public class StatusBarNotifier } else { notificationType = NOTIFICATION_IN_CALL; } + Trace.endSection(); // prepare work if (!checkForChangeAndSaveData( iconResId, @@ -323,6 +330,7 @@ public class StatusBarNotifier callState, notificationType, contactInfo.contactRingtoneUri)) { + Trace.endSection(); return; } @@ -409,6 +417,7 @@ public class StatusBarNotifier addPersonReference(builder, contactInfo, call); + Trace.beginSection("fire notification"); // Fire off the notification Notification notification = builder.build(); @@ -448,8 +457,10 @@ public class StatusBarNotifier 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 db6d43d49..18de72e8b 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.net.Uri; 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 @@ public class AnswerFragment extends Fragment @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 @@ public class AnswerFragment extends Fragment } } + Trace.endSection(); return view; } diff --git a/java/com/android/incallui/contactgrid/ContactGridManager.java b/java/com/android/incallui/contactgrid/ContactGridManager.java index ddf16e340..18bab6ab3 100644 --- a/java/com/android/incallui/contactgrid/ContactGridManager.java +++ b/java/com/android/incallui/contactgrid/ContactGridManager.java @@ -315,6 +315,7 @@ public class ContactGridManager { 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 @@ public class ContactGridManager { ((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 8850dd856..c545c25cd 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 @@