Search in sources :

Example 6 with ImsException

use of com.android.ims.ImsException in project android_frameworks_opt_telephony by LineageOS.

the class ImsPhoneCallTracker method switchWaitingOrHoldingAndActive.

public void switchWaitingOrHoldingAndActive() throws CallStateException {
    if (DBG)
        log("switchWaitingOrHoldingAndActive");
    if (mRingingCall.getState() == ImsPhoneCall.State.INCOMING) {
        throw new CallStateException("cannot be in the incoming state");
    }
    if (mForegroundCall.getState() == ImsPhoneCall.State.ACTIVE) {
        ImsCall imsCall = mForegroundCall.getImsCall();
        if (imsCall == null) {
            throw new CallStateException("no ims call");
        }
        // Swap the ImsCalls pointed to by the foreground and background ImsPhoneCalls.
        // If hold or resume later fails, we will swap them back.
        boolean switchingWithWaitingCall = !mBackgroundCall.getState().isAlive() && mRingingCall != null && mRingingCall.getState() == ImsPhoneCall.State.WAITING;
        mSwitchingFgAndBgCalls = true;
        if (switchingWithWaitingCall) {
            mCallExpectedToResume = mRingingCall.getImsCall();
        } else {
            mCallExpectedToResume = mBackgroundCall.getImsCall();
        }
        mForegroundCall.switchWith(mBackgroundCall);
        // be resumed.
        try {
            imsCall.hold();
            mMetrics.writeOnImsCommand(mPhone.getPhoneId(), imsCall.getSession(), ImsCommand.IMS_CMD_HOLD);
            // If there is no background call to resume, then don't expect there to be a switch.
            if (mCallExpectedToResume == null) {
                log("mCallExpectedToResume is null");
                mSwitchingFgAndBgCalls = false;
            }
        } catch (ImsException e) {
            mForegroundCall.switchWith(mBackgroundCall);
            throw new CallStateException(e.getMessage());
        }
    } else if (mBackgroundCall.getState() == ImsPhoneCall.State.HOLDING) {
        resumeWaitingOrHolding();
    }
}
Also used : CallStateException(com.android.internal.telephony.CallStateException) ImsCall(com.android.ims.ImsCall) ImsException(com.android.ims.ImsException)

Example 7 with ImsException

use of com.android.ims.ImsException in project android_frameworks_opt_telephony by LineageOS.

the class ImsPhoneMmiCode method onQueryComplete.

private void onQueryComplete(AsyncResult ar) {
    StringBuilder sb = new StringBuilder(getScString());
    sb.append("\n");
    if (ar.exception != null) {
        mState = State.FAILED;
        if (ar.exception instanceof ImsException) {
            ImsException error = (ImsException) ar.exception;
            if (error.getMessage() != null) {
                sb.append(error.getMessage());
            } else {
                sb.append(getErrorMessage(ar));
            }
        } else {
            sb.append(getErrorMessage(ar));
        }
    } else {
        int[] ints = (int[]) ar.result;
        if (ints.length != 0) {
            if (ints[0] == 0) {
                sb.append(mContext.getText(com.android.internal.R.string.serviceDisabled));
            } else if (mSc.equals(SC_WAIT)) {
                // Call Waiting includes additional data in the response.
                sb.append(createQueryCallWaitingResultMessage(ints[1]));
            } else if (ints[0] == 1) {
                // for all other services, treat it as a boolean
                sb.append(mContext.getText(com.android.internal.R.string.serviceEnabled));
            } else {
                sb.append(mContext.getText(com.android.internal.R.string.mmiError));
            }
        } else {
            sb.append(mContext.getText(com.android.internal.R.string.mmiError));
        }
        mState = State.COMPLETE;
    }
    mMessage = sb;
    Rlog.d(LOG_TAG, "onQueryComplete mmi=" + this);
    mPhone.onMMIDone(this);
}
Also used : SpannableStringBuilder(android.text.SpannableStringBuilder) ImsException(com.android.ims.ImsException)

Example 8 with ImsException

use of com.android.ims.ImsException in project android_frameworks_opt_telephony by LineageOS.

the class ImsPhoneMmiCode method onSetComplete.

private void onSetComplete(Message msg, AsyncResult ar) {
    StringBuilder sb = new StringBuilder(getScString());
    sb.append("\n");
    if (ar.exception != null) {
        mState = State.FAILED;
        if (ar.exception instanceof CommandException) {
            CommandException err = (CommandException) ar.exception;
            if (err.getCommandError() == CommandException.Error.PASSWORD_INCORRECT) {
                sb.append(mContext.getText(com.android.internal.R.string.passwordIncorrect));
            } else if (err.getMessage() != null) {
                sb.append(err.getMessage());
            } else {
                sb.append(mContext.getText(com.android.internal.R.string.mmiError));
            }
        } else {
            ImsException error = (ImsException) ar.exception;
            if (error.getMessage() != null) {
                sb.append(error.getMessage());
            } else {
                sb.append(getErrorMessage(ar));
            }
        }
    } else if (isActivate()) {
        mState = State.COMPLETE;
        if (mIsCallFwdReg) {
            sb.append(mContext.getText(com.android.internal.R.string.serviceRegistered));
        } else {
            sb.append(mContext.getText(com.android.internal.R.string.serviceEnabled));
        }
    } else if (isDeactivate()) {
        mState = State.COMPLETE;
        sb.append(mContext.getText(com.android.internal.R.string.serviceDisabled));
    } else if (isRegister()) {
        mState = State.COMPLETE;
        sb.append(mContext.getText(com.android.internal.R.string.serviceRegistered));
    } else if (isErasure()) {
        mState = State.COMPLETE;
        sb.append(mContext.getText(com.android.internal.R.string.serviceErased));
    } else {
        mState = State.FAILED;
        sb.append(mContext.getText(com.android.internal.R.string.mmiError));
    }
    mMessage = sb;
    Rlog.d(LOG_TAG, "onSetComplete: mmi=" + this);
    mPhone.onMMIDone(this);
}
Also used : SpannableStringBuilder(android.text.SpannableStringBuilder) ImsException(com.android.ims.ImsException) CommandException(com.android.internal.telephony.CommandException)

Example 9 with ImsException

use of com.android.ims.ImsException in project android_frameworks_opt_telephony by LineageOS.

the class ImsPhoneCallTrackerTest method testDialImsServiceUnavailable.

@Test
@SmallTest
public void testDialImsServiceUnavailable() throws ImsException {
    doThrow(new ImsException("Test Exception", ImsReasonInfo.CODE_LOCAL_IMS_SERVICE_DOWN)).when(mImsManager).createCallProfile(anyInt(), anyInt(), anyInt());
    // ms
    mCTUT.mRetryTimeout = () -> 0;
    assertEquals(Call.State.IDLE, mCTUT.mForegroundCall.getState());
    assertEquals(PhoneConstants.State.IDLE, mCTUT.getState());
    try {
        mCTUT.dial("+17005554141", ImsCallProfile.CALL_TYPE_VOICE, null);
    } catch (Exception e) {
        Assert.fail();
    }
    // wait for handler to process ImsService connection retry
    // 1 second timeout
    waitForHandlerAction(mCTHander, 1000);
    verify(mImsManager, never()).makeCall(anyInt(), nullable(ImsCallProfile.class), eq(new String[] { "+17005554141" }), nullable(ImsCall.Listener.class));
    // Make sure that open is called in ImsPhoneCallTracker when it was first connected and
    // again after retry.
    verify(mImsManager, times(2)).open(anyInt(), nullable(PendingIntent.class), nullable(ImsConnectionStateListener.class));
}
Also used : ImsConnectionStateListener(com.android.ims.ImsConnectionStateListener) ImsCallProfile(com.android.ims.ImsCallProfile) ImsException(com.android.ims.ImsException) PendingIntent(android.app.PendingIntent) ImsException(com.android.ims.ImsException) CallStateException(com.android.internal.telephony.CallStateException) ImsConnectionStateListener(com.android.ims.ImsConnectionStateListener) TelephonyTest(com.android.internal.telephony.TelephonyTest) SmallTest(android.test.suitebuilder.annotation.SmallTest) FlakyTest(android.support.test.filters.FlakyTest) Test(org.junit.Test) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 10 with ImsException

use of com.android.ims.ImsException in project android_frameworks_opt_telephony by LineageOS.

the class GsmCdmaPhone method dial.

@Override
public Connection dial(String dialString, UUSInfo uusInfo, int videoState, Bundle intentExtras) throws CallStateException {
    if (!isPhoneTypeGsm() && uusInfo != null) {
        throw new CallStateException("Sending UUS information NOT supported in CDMA!");
    }
    boolean isEmergency = PhoneNumberUtils.isEmergencyNumber(getSubId(), dialString);
    Phone imsPhone = mImsPhone;
    CarrierConfigManager configManager = (CarrierConfigManager) mContext.getSystemService(Context.CARRIER_CONFIG_SERVICE);
    boolean alwaysTryImsForEmergencyCarrierConfig = configManager.getConfigForSubId(getSubId()).getBoolean(CarrierConfigManager.KEY_CARRIER_USE_IMS_FIRST_FOR_EMERGENCY_BOOL);
    boolean imsUseEnabled = isImsUseEnabled() && imsPhone != null && (imsPhone.isVolteEnabled() || imsPhone.isWifiCallingEnabled() || (imsPhone.isVideoEnabled() && VideoProfile.isVideo(videoState))) && (imsPhone.getServiceState().getState() == ServiceState.STATE_IN_SERVICE);
    int imsFeatureState = ImsFeature.STATE_NOT_AVAILABLE;
    try {
        if (imsPhone != null) {
            imsFeatureState = ImsManager.getInstance(imsPhone.getContext(), imsPhone.getPhoneId()).getImsServiceStatus();
        }
    } catch (ImsException e) {
        Log.e(LOG_TAG, "Got ImsException for phoneId " + imsPhone.getPhoneId());
    }
    boolean useImsForEmergency = imsPhone != null && (imsFeatureState == ImsFeature.STATE_READY) && isEmergency && alwaysTryImsForEmergencyCarrierConfig && ImsManager.getInstance(mContext, mPhoneId).isNonTtyOrTtyOnVolteEnabledForSlot() && imsPhone.isImsAvailable();
    String dialPart = PhoneNumberUtils.extractNetworkPortionAlt(PhoneNumberUtils.stripSeparators(dialString));
    boolean isUt = (dialPart.startsWith("*") || dialPart.startsWith("#")) && dialPart.endsWith("#");
    boolean useImsForUt = imsPhone != null && imsPhone.isUtEnabled();
    if (DBG) {
        logd("imsUseEnabled=" + imsUseEnabled + ", useImsForEmergency=" + useImsForEmergency + ", useImsForUt=" + useImsForUt + ", isUt=" + isUt + ", imsPhone=" + imsPhone + ", imsPhone.isVolteEnabled()=" + ((imsPhone != null) ? imsPhone.isVolteEnabled() : "N/A") + ", imsPhone.isVowifiEnabled()=" + ((imsPhone != null) ? imsPhone.isWifiCallingEnabled() : "N/A") + ", imsPhone.isVideoEnabled()=" + ((imsPhone != null) ? imsPhone.isVideoEnabled() : "N/A") + ", imsPhone.getServiceState().getState()=" + ((imsPhone != null) ? imsPhone.getServiceState().getState() : "N/A") + ", imsphone feature state = " + imsFeatureState);
    }
    checkWfcWifiOnlyModeBeforeDial();
    if ((imsUseEnabled && (!isUt || useImsForUt)) || useImsForEmergency) {
        try {
            if (DBG)
                logd("Trying IMS PS call");
            return imsPhone.dial(dialString, uusInfo, videoState, intentExtras);
        } catch (CallStateException e) {
            if (DBG)
                logd("IMS PS call exception " + e + "imsUseEnabled =" + imsUseEnabled + ", imsPhone =" + imsPhone);
            // for emergency calls and MMI codes.
            if (Phone.CS_FALLBACK.equals(e.getMessage()) || isEmergency) {
                logi("IMS call failed with Exception: " + e.getMessage() + ". Falling back " + "to CS.");
            } else {
                CallStateException ce = new CallStateException(e.getMessage());
                ce.setStackTrace(e.getStackTrace());
                throw ce;
            }
        }
    }
    if (mSST != null && mSST.mSS.getState() == ServiceState.STATE_OUT_OF_SERVICE && mSST.mSS.getDataRegState() != ServiceState.STATE_IN_SERVICE && !isEmergency) {
        throw new CallStateException("cannot dial in current state");
    }
    // Check non-emergency voice CS call - shouldn't dial when POWER_OFF
    if (mSST != null && mSST.mSS.getState() == ServiceState.STATE_POWER_OFF && /* CS POWER_OFF */
    !VideoProfile.isVideo(videoState) && /* voice call */
    !isEmergency) /* non-emergency call */
    {
        throw new CallStateException(CallStateException.ERROR_POWER_OFF, "cannot dial voice call in airplane mode");
    }
    // Allow dial only if either CS is camped on any RAT (or) PS is in LTE service.
    if (mSST != null && mSST.mSS.getState() == ServiceState.STATE_OUT_OF_SERVICE && /* CS out of service */
    !(mSST.mSS.getDataRegState() == ServiceState.STATE_IN_SERVICE && ServiceState.isLte(mSST.mSS.getRilDataRadioTechnology())) && /* PS not in LTE */
    !VideoProfile.isVideo(videoState) && /* voice call */
    !isEmergency) /* non-emergency call */
    {
        throw new CallStateException(CallStateException.ERROR_OUT_OF_SERVICE, "cannot dial voice call in out of service");
    }
    if (DBG)
        logd("Trying (non-IMS) CS call");
    if (isPhoneTypeGsm()) {
        return dialInternal(dialString, null, VideoProfile.STATE_AUDIO_ONLY, intentExtras);
    } else {
        return dialInternal(dialString, null, videoState, intentExtras);
    }
}
Also used : CarrierConfigManager(android.telephony.CarrierConfigManager) ImsException(com.android.ims.ImsException)

Aggregations

ImsException (com.android.ims.ImsException)37 Message (android.os.Message)9 ImsUtInterface (com.android.ims.ImsUtInterface)8 ImsCall (com.android.ims.ImsCall)7 ImsConfig (com.android.ims.ImsConfig)7 SpannableStringBuilder (android.text.SpannableStringBuilder)6 CallStateException (com.android.internal.telephony.CallStateException)6 ImsCallProfile (com.android.ims.ImsCallProfile)4 Context (android.content.Context)3 PendingIntent (android.app.PendingIntent)2 Bundle (android.os.Bundle)2 FlakyTest (android.support.test.filters.FlakyTest)2 SmallTest (android.test.suitebuilder.annotation.SmallTest)2 ImsConnectionStateListener (com.android.ims.ImsConnectionStateListener)2 ImsSsInfo (com.android.ims.ImsSsInfo)2 CommandException (com.android.internal.telephony.CommandException)2 TelephonyTest (com.android.internal.telephony.TelephonyTest)2 Test (org.junit.Test)2 Intent (android.content.Intent)1 AsyncResult (android.os.AsyncResult)1