Optimization for incoming call latency.

There are many binder call triggered by IPC on main thread. This change will try to reduce them by caching thing that's bound to a call. It reduce total binder transaction from 1002 to 664 and saves ~11% latency of incoming call on locked screen.

1. Cache isVoiceMailNumber in DialerCall
2. Cache call capable accounts in DialerCall
3. Cache current country iso in DialerCall
4. Don't set orientation change if it's not changed.

This change also add lots of trace info. It won't affect release build though since they are stripped out by proguard.

Bug: 64542087
Test: manual
PiperOrigin-RevId: 171901266
Change-Id: Iec48f030529aa59974212147276f6d0ae121872a
diff --git a/java/com/android/incallui/call/DialerCall.java b/java/com/android/incallui/call/DialerCall.java
index 6829203..47a4a70 100644
--- a/java/com/android/incallui/call/DialerCall.java
+++ b/java/com/android/incallui/call/DialerCall.java
@@ -16,6 +16,7 @@
 
 package com.android.incallui.call;
 
+import android.Manifest.permission;
 import android.content.Context;
 import android.hardware.camera2.CameraCharacteristics;
 import android.net.Uri;
@@ -58,11 +59,14 @@
 import com.android.dialer.enrichedcall.EnrichedCallManager.StateChangedListener;
 import com.android.dialer.enrichedcall.Session;
 import com.android.dialer.lightbringer.LightbringerComponent;
+import com.android.dialer.location.GeoUtil;
 import com.android.dialer.logging.ContactLookupResult;
 import com.android.dialer.logging.ContactLookupResult.Type;
 import com.android.dialer.logging.DialerImpression;
 import com.android.dialer.logging.Logger;
+import com.android.dialer.telecom.TelecomUtil;
 import com.android.dialer.theme.R;
+import com.android.dialer.util.PermissionsUtil;
 import com.android.incallui.audiomode.AudioModeProvider;
 import com.android.incallui.latencyreport.LatencyReport;
 import com.android.incallui.util.TelecomCallUtil;
@@ -158,6 +162,9 @@
 
   private com.android.dialer.logging.VideoTech.Type selectedAvailableVideoTechType =
       com.android.dialer.logging.VideoTech.Type.NONE;
+  private boolean isVoicemailNumber;
+  private List<PhoneAccountHandle> callCapableAccounts;
+  private String countryIso;
 
   public static String getNumberFromHandle(Uri handle) {
     return handle == null ? "" : handle.getSchemeSpecificPart();
@@ -450,6 +457,30 @@
     return mLogState.conferencedCalls != 0;
   }
 
+  public boolean isVoiceMailNumber() {
+    return isVoicemailNumber;
+  }
+
+  public List<PhoneAccountHandle> getCallCapableAccounts() {
+    return callCapableAccounts;
+  }
+
+  public String getCountryIso() {
+    return countryIso;
+  }
+
+  private void updateIsVoiceMailNumber() {
+    if (getHandle() != null && PhoneAccount.SCHEME_VOICEMAIL.equals(getHandle().getScheme())) {
+      isVoicemailNumber = true;
+    }
+
+    if (!PermissionsUtil.hasPermission(mContext, permission.READ_PHONE_STATE)) {
+      isVoicemailNumber = false;
+    }
+
+    isVoicemailNumber = TelecomUtil.isVoicemailNumber(mContext, getAccountHandle(), getNumber());
+  }
+
   private void update() {
     Trace.beginSection("DialerCall.update");
     int oldState = getState();
@@ -475,6 +506,7 @@
     Trace.endSection();
   }
 
+  @SuppressWarnings("MissingPermission")
   private void updateFromTelecomCall() {
     Trace.beginSection("DialerCall.updateFromTelecomCall");
     LogUtil.v("DialerCall.updateFromTelecomCall", mTelecomCall.toString());
@@ -510,6 +542,7 @@
       updateEmergencyCallState();
     }
 
+    TelecomManager telecomManager = mContext.getSystemService(TelecomManager.class);
     // If the phone account handle of the call is set, cache capability bit indicating whether
     // the phone account supports call subjects.
     PhoneAccountHandle newPhoneAccountHandle = mTelecomCall.getDetails().getAccountHandle();
@@ -517,14 +550,18 @@
       mPhoneAccountHandle = newPhoneAccountHandle;
 
       if (mPhoneAccountHandle != null) {
-        PhoneAccount phoneAccount =
-            mContext.getSystemService(TelecomManager.class).getPhoneAccount(mPhoneAccountHandle);
+        PhoneAccount phoneAccount = telecomManager.getPhoneAccount(mPhoneAccountHandle);
         if (phoneAccount != null) {
           mIsCallSubjectSupported =
               phoneAccount.hasCapabilities(PhoneAccount.CAPABILITY_CALL_SUBJECT);
         }
       }
     }
+    if (PermissionsUtil.hasPermission(mContext, permission.READ_PHONE_STATE)) {
+      updateIsVoiceMailNumber();
+      callCapableAccounts = telecomManager.getCallCapablePhoneAccounts();
+      countryIso = GeoUtil.getCurrentCountryIso(mContext);
+    }
     Trace.endSection();
   }
 
@@ -1148,9 +1185,7 @@
     if (callProviderLabel == null) {
       PhoneAccount account = getPhoneAccount();
       if (account != null && !TextUtils.isEmpty(account.getLabel())) {
-        List<PhoneAccountHandle> accounts =
-            mContext.getSystemService(TelecomManager.class).getCallCapablePhoneAccounts();
-        if (accounts != null && accounts.size() > 1) {
+        if (callCapableAccounts != null && callCapableAccounts.size() > 1) {
           callProviderLabel = account.getLabel().toString();
         }
       }
@@ -1220,9 +1255,11 @@
 
   @Override
   public void onSessionModificationStateChanged() {
+    Trace.beginSection("DialerCall.onSessionModificationStateChanged");
     for (DialerCallListener listener : mListeners) {
       listener.onDialerCallSessionModificationStateChange();
     }
+    Trace.endSection();
   }
 
   @Override