diff options
-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. |