diff options
author | Tyler Gunn <tgunn@google.com> | 2015-08-11 15:31:01 -0700 |
---|---|---|
committer | Tyler Gunn <tgunn@google.com> | 2015-08-11 15:31:01 -0700 |
commit | 93a6fd8d4a6f3ff4732cb4fb3b9df7c522b92823 (patch) | |
tree | b99a55657b482fe032f6909a584942ce58f6efdd | |
parent | 15d3e25f65005f87c636aeeafc08aec0805652a5 (diff) |
Minimize the number of calls to PhoneNumberUtils.isLocalEmergencyNumber.
On a standard outgoing call, isLocalEmergencyNumber was being called
from 30-40 times. Each of these calls requires a system service
invocation.
A large number of these invocations were coming from InCall UI.
To fix this:
1. Added an isEmergencyCall property to the InCall Call object.
isLocalEmergencyNumber is recalculated any time the mTelecomCall's
handle changes.
2. Replaced calls to isLocalEmergencyNumber in CallCardPresenter with
calls to the InCall call cached version; this easily cuts out around 15
calls to isLocalEmergencyNumber.
3. Replaced code in InCallPresenter; this accounted for 2-3 calls to
isLocalEmergencyNumber.
Bug: 22985202
Change-Id: Ia61204bb0ed6171b24c116e8c681b3924ce54f1d
# Conflicts:
# src/com/android/incallui/Call.java
-rw-r--r-- | InCallUI/src/com/android/incallui/Call.java | 28 | ||||
-rw-r--r-- | InCallUI/src/com/android/incallui/CallCardPresenter.java | 9 | ||||
-rw-r--r-- | InCallUI/src/com/android/incallui/InCallPresenter.java | 10 |
3 files changed, 31 insertions, 16 deletions
diff --git a/InCallUI/src/com/android/incallui/Call.java b/InCallUI/src/com/android/incallui/Call.java index 7205b7326..191ffe791 100644 --- a/InCallUI/src/com/android/incallui/Call.java +++ b/InCallUI/src/com/android/incallui/Call.java @@ -31,6 +31,7 @@ import android.telecom.InCallService.VideoCall; import android.telecom.PhoneAccount; import android.telecom.PhoneAccountHandle; import android.telecom.VideoProfile; +import android.telephony.PhoneNumberUtils; import android.text.TextUtils; import java.util.ArrayList; @@ -244,6 +245,8 @@ public class Call { }; private android.telecom.Call mTelecommCall; + private boolean mIsEmergencyCall; + private Uri mHandle; private final String mId; private int mState = State.INVALID; private DisconnectCause mDisconnectCause; @@ -273,6 +276,7 @@ public class Call { public Call(android.telecom.Call telecommCall) { mTelecommCall = telecommCall; mId = ID_PREFIX + Integer.toString(sIdCounter++); + updateFromTelecommCall(); mTelecommCall.registerCallback(mTelecomCallCallback); } @@ -361,6 +365,14 @@ public class Call { } } } + + // If the handle of the call has changed, update state for the call determining if it is an + // emergency call. + Uri newHandle = mTelecommCall.getDetails().getHandle(); + if (!Objects.equals(mHandle, newHandle)) { + mHandle = newHandle; + updateEmergencyCallState(); + } } private static int translateState(int state) { @@ -406,6 +418,10 @@ public class Call { return mTelecommCall == null ? null : mTelecommCall.getDetails().getHandle(); } + public boolean isEmergencyCall() { + return mIsEmergencyCall; + } + public int getState() { if (mTelecommCall != null && mTelecommCall.getParent() != null) { return State.CONFERENCED; @@ -574,7 +590,7 @@ public class Call { public void setSessionModificationState(int state) { if (state == Call.SessionModificationState.RECEIVED_UPGRADE_TO_VIDEO_REQUEST) { Log.e(this, - "setSessionModificationState not to be called for RECEIVED_UPGRADE_TO_VIDEO_REQUEST"); + "setSessionModificationState not to be called for RECEIVED_UPGRADE_TO_VIDEO_REQUEST"); return; } @@ -587,6 +603,16 @@ public class Call { } } + /** + * Determines if the call handle is an emergency number or not and caches the result to avoid + * repeated calls to isEmergencyNumber. + */ + private void updateEmergencyCallState() { + Uri handle = mTelecommCall.getDetails().getHandle(); + mIsEmergencyCall = PhoneNumberUtils.isEmergencyNumber( + handle == null ? "" : handle.getSchemeSpecificPart()); + } + private void setModifyToVideoState(int newVideoState) { mModifyToVideoState = newVideoState; } diff --git a/InCallUI/src/com/android/incallui/CallCardPresenter.java b/InCallUI/src/com/android/incallui/CallCardPresenter.java index 0631d2a4b..6961e8a2e 100644 --- a/InCallUI/src/com/android/incallui/CallCardPresenter.java +++ b/InCallUI/src/com/android/incallui/CallCardPresenter.java @@ -437,11 +437,9 @@ public class CallCardPresenter extends Presenter<CallCardPresenter.CallCardUi> // 1. This is an emergency call. // 2. The phone is in Emergency Callback Mode, which means we should show the callback // number. - boolean isEmergencyCall = PhoneNumberUtils.isEmergencyNumber( - getNumberFromHandle(mPrimary.getHandle())); boolean showCallbackNumber = mPrimary.hasProperty(Details.PROPERTY_EMERGENCY_CALLBACK_MODE); - if (isEmergencyCall || showCallbackNumber) { + if (mPrimary.isEmergencyCall() || showCallbackNumber) { callbackNumber = getSubscriptionNumber(); } else { StatusHints statusHints = mPrimary.getTelecommCall().getDetails().getStatusHints(); @@ -461,7 +459,7 @@ public class CallCardPresenter extends Presenter<CallCardPresenter.CallCardUi> callbackNumber = null; } - getUi().setCallbackNumber(callbackNumber, isEmergencyCall || showCallbackNumber); + getUi().setCallbackNumber(callbackNumber, mPrimary.isEmergencyCall() || showCallbackNumber); } public void updateCallTime() { @@ -657,8 +655,7 @@ public class CallCardPresenter extends Presenter<CallCardPresenter.CallCardUi> } if (mEmergencyCallListener != null) { - boolean isEmergencyCall = PhoneNumberUtils.isEmergencyNumber( - getNumberFromHandle(mPrimary.getHandle())); + boolean isEmergencyCall = mPrimary.isEmergencyCall(); mEmergencyCallListener.onCallUpdated((BaseFragment) ui, isEmergencyCall); } } diff --git a/InCallUI/src/com/android/incallui/InCallPresenter.java b/InCallUI/src/com/android/incallui/InCallPresenter.java index cf162c728..2d7d40a1d 100644 --- a/InCallUI/src/com/android/incallui/InCallPresenter.java +++ b/InCallUI/src/com/android/incallui/InCallPresenter.java @@ -1138,7 +1138,7 @@ public class InCallPresenter implements CallList.Listener, * call. */ public static boolean isCallWithNoValidAccounts(Call call) { - if (call != null && !isEmergencyCall(call)) { + if (call != null && !call.isEmergencyCall()) { Bundle extras = call.getIntentExtras(); if (extras == null) { @@ -1157,14 +1157,6 @@ public class InCallPresenter implements CallList.Listener, return false; } - private static boolean isEmergencyCall(Call call) { - final Uri handle = call.getHandle(); - if (handle == null) { - return false; - } - return PhoneNumberUtils.isEmergencyNumber(handle.getSchemeSpecificPart()); - } - /** * Sets the DisconnectCause for a call that was disconnected because it was missing a * PhoneAccount or PhoneAccounts to select from. |