Search in sources :

Example 46 with AsyncResult

use of android.os.AsyncResult in project android_frameworks_opt_telephony by LineageOS.

the class GsmCdmaCallTracker method updatePhoneState.

@UnsupportedAppUsage
private void updatePhoneState() {
    PhoneConstants.State oldState = mState;
    if (mRingingCall.isRinging()) {
        mState = PhoneConstants.State.RINGING;
    } else if (mPendingMO != null || !(mForegroundCall.isIdle() && mBackgroundCall.isIdle())) {
        mState = PhoneConstants.State.OFFHOOK;
    } else {
        Phone imsPhone = mPhone.getImsPhone();
        if (mState == PhoneConstants.State.OFFHOOK && (imsPhone != null)) {
            imsPhone.callEndCleanupHandOverCallIfAny();
        }
        mState = PhoneConstants.State.IDLE;
    }
    if (mState == PhoneConstants.State.IDLE && oldState != mState) {
        mVoiceCallEndedRegistrants.notifyRegistrants(new AsyncResult(null, null, null));
    } else if (oldState == PhoneConstants.State.IDLE && oldState != mState) {
        mVoiceCallStartedRegistrants.notifyRegistrants(new AsyncResult(null, null, null));
    }
    if (Phone.DEBUG_PHONE) {
        log("update phone state, old=" + oldState + " new=" + mState);
    }
    if (mState != oldState) {
        mPhone.notifyPhoneStateChanged();
        mMetrics.writePhoneState(mPhone.getPhoneId(), mState);
    }
}
Also used : AsyncResult(android.os.AsyncResult) UnsupportedAppUsage(android.compat.annotation.UnsupportedAppUsage)

Example 47 with AsyncResult

use of android.os.AsyncResult in project android_frameworks_opt_telephony by LineageOS.

the class GsmCdmaCallTracker method handleMessage.

// ****** Overridden from Handler
@Override
public void handleMessage(Message msg) {
    AsyncResult ar;
    switch(msg.what) {
        case EVENT_POLL_CALLS_RESULT:
            Rlog.d(LOG_TAG, "Event EVENT_POLL_CALLS_RESULT Received");
            if (msg == mLastRelevantPoll) {
                if (DBG_POLL)
                    log("handle EVENT_POLL_CALL_RESULT: set needsPoll=F");
                mNeedsPoll = false;
                mLastRelevantPoll = null;
                handlePollCalls((AsyncResult) msg.obj);
            }
            break;
        case EVENT_OPERATION_COMPLETE:
            operationComplete();
            break;
        case EVENT_CONFERENCE_RESULT:
            if (isPhoneTypeGsm()) {
                ar = (AsyncResult) msg.obj;
                if (ar.exception != null) {
                    // The conference merge failed, so notify listeners.  Ultimately this
                    // bubbles up to Telecom, which will inform the InCall UI of the failure.
                    Connection connection = mForegroundCall.getLatestConnection();
                    if (connection != null) {
                        connection.onConferenceMergeFailed();
                    }
                }
            }
        // fall through
        case EVENT_SEPARATE_RESULT:
        case EVENT_ECT_RESULT:
        case EVENT_SWITCH_RESULT:
            if (isPhoneTypeGsm()) {
                ar = (AsyncResult) msg.obj;
                if (ar.exception != null) {
                    if (msg.what == EVENT_SWITCH_RESULT) {
                        Connection connection = mForegroundCall.getLatestConnection();
                        if (connection != null) {
                            if (mBackgroundCall.getState() != GsmCdmaCall.State.HOLDING) {
                                connection.onConnectionEvent(android.telecom.Connection.EVENT_CALL_HOLD_FAILED, null);
                            } else {
                                connection.onConnectionEvent(android.telecom.Connection.EVENT_CALL_SWITCH_FAILED, null);
                            }
                        }
                    }
                    mPhone.notifySuppServiceFailed(getFailedService(msg.what));
                }
                operationComplete();
            } else {
                if (msg.what != EVENT_SWITCH_RESULT) {
                    // to do. Other messages however are not expected in CDMA.
                    throw new RuntimeException("unexpected event " + msg.what + " not handled by " + "phone type " + mPhone.getPhoneType());
                }
            }
            break;
        case EVENT_GET_LAST_CALL_FAIL_CAUSE:
            int causeCode;
            String vendorCause = null;
            ar = (AsyncResult) msg.obj;
            operationComplete();
            if (ar.exception != null) {
                if (ar.exception instanceof CommandException) {
                    // If we get a CommandException, there are some modem-reported command
                    // errors which are truly exceptional.  We shouldn't treat these as
                    // NORMAL_CLEARING, so we'll re-map to ERROR_UNSPECIFIED.
                    CommandException commandException = (CommandException) ar.exception;
                    switch(commandException.getCommandError()) {
                        case RADIO_NOT_AVAILABLE:
                        // Intentional fall-through.
                        case NO_MEMORY:
                        // Intentional fall-through.
                        case INTERNAL_ERR:
                        // Intentional fall-through.
                        case NO_RESOURCES:
                            causeCode = CallFailCause.ERROR_UNSPECIFIED;
                            // Report the actual internal command error as the vendor cause;
                            // this will ensure it gets bubbled up into the Telecom logs.
                            vendorCause = commandException.getCommandError().toString();
                            break;
                        default:
                            causeCode = CallFailCause.NORMAL_CLEARING;
                    }
                } else {
                    // An exception occurred...just treat the disconnect
                    // cause as "normal"
                    causeCode = CallFailCause.NORMAL_CLEARING;
                    Rlog.i(LOG_TAG, "Exception during getLastCallFailCause, assuming normal " + "disconnect");
                }
            } else {
                LastCallFailCause failCause = (LastCallFailCause) ar.result;
                causeCode = failCause.causeCode;
                vendorCause = failCause.vendorCause;
            }
            // Log the causeCode if its not normal
            if (causeCode == CallFailCause.NO_CIRCUIT_AVAIL || causeCode == CallFailCause.TEMPORARY_FAILURE || causeCode == CallFailCause.SWITCHING_CONGESTION || causeCode == CallFailCause.CHANNEL_NOT_AVAIL || causeCode == CallFailCause.QOS_NOT_AVAIL || causeCode == CallFailCause.BEARER_NOT_AVAIL || causeCode == CallFailCause.ERROR_UNSPECIFIED) {
                CellLocation loc = mPhone.getCellIdentity().asCellLocation();
                int cid = -1;
                if (loc != null) {
                    if (loc instanceof GsmCellLocation) {
                        cid = ((GsmCellLocation) loc).getCid();
                    } else if (loc instanceof CdmaCellLocation) {
                        cid = ((CdmaCellLocation) loc).getBaseStationId();
                    }
                }
                EventLog.writeEvent(EventLogTags.CALL_DROP, causeCode, cid, TelephonyManager.getDefault().getNetworkType());
            }
            if (isEmcRetryCause(causeCode)) {
                String dialString = "";
                for (Connection conn : mForegroundCall.mConnections) {
                    GsmCdmaConnection gsmCdmaConnection = (GsmCdmaConnection) conn;
                    dialString = gsmCdmaConnection.getOrigDialString();
                    gsmCdmaConnection.getCall().detach(gsmCdmaConnection);
                    mDroppedDuringPoll.remove(gsmCdmaConnection);
                }
                mPhone.notifyVolteSilentRedial(dialString, causeCode);
                updatePhoneState();
                if (mDroppedDuringPoll.isEmpty()) {
                    log("LAST_CALL_FAIL_CAUSE - no Dropped normal Call");
                    return;
                }
            }
            for (int i = 0, s = mDroppedDuringPoll.size(); i < s; i++) {
                GsmCdmaConnection conn = mDroppedDuringPoll.get(i);
                conn.onRemoteDisconnect(causeCode, vendorCause);
            }
            updatePhoneState();
            mPhone.notifyPreciseCallStateChanged();
            mMetrics.writeRilCallList(mPhone.getPhoneId(), mDroppedDuringPoll, getNetworkCountryIso());
            mPhone.getVoiceCallSessionStats().onRilCallListChanged(mDroppedDuringPoll);
            mDroppedDuringPoll.clear();
            break;
        case EVENT_REPOLL_AFTER_DELAY:
        case EVENT_CALL_STATE_CHANGE:
            pollCallsWhenSafe();
            break;
        case EVENT_RADIO_AVAILABLE:
            handleRadioAvailable();
            break;
        case EVENT_RADIO_NOT_AVAILABLE:
            handleRadioNotAvailable();
            break;
        case EVENT_EXIT_ECM_RESPONSE_CDMA:
            if (!isPhoneTypeGsm()) {
                // no matter the result, we still do the same here
                if (mPendingCallInEcm) {
                    mCi.dial(mPendingMO.getAddress(), mPendingMO.isEmergencyCall(), mPendingMO.getEmergencyNumberInfo(), mPendingMO.hasKnownUserIntentEmergency(), mPendingCallClirMode, obtainCompleteMessage());
                    mPendingCallInEcm = false;
                }
                mPhone.unsetOnEcbModeExitResponse(this);
            } else {
                throw new RuntimeException("unexpected event " + msg.what + " not handled by " + "phone type " + mPhone.getPhoneType());
            }
            break;
        case EVENT_CALL_WAITING_INFO_CDMA:
            if (!isPhoneTypeGsm()) {
                ar = (AsyncResult) msg.obj;
                if (ar.exception == null) {
                    handleCallWaitingInfo((CdmaCallWaitingNotification) ar.result);
                    Rlog.d(LOG_TAG, "Event EVENT_CALL_WAITING_INFO_CDMA Received");
                }
            } else {
                throw new RuntimeException("unexpected event " + msg.what + " not handled by " + "phone type " + mPhone.getPhoneType());
            }
            break;
        case EVENT_THREE_WAY_DIAL_L2_RESULT_CDMA:
            if (!isPhoneTypeGsm()) {
                ar = (AsyncResult) msg.obj;
                if (ar.exception == null) {
                    // Assume 3 way call is connected
                    mPendingMO.onConnectedInOrOut();
                    mPendingMO = null;
                }
            } else {
                throw new RuntimeException("unexpected event " + msg.what + " not handled by " + "phone type " + mPhone.getPhoneType());
            }
            break;
        case EVENT_THREE_WAY_DIAL_BLANK_FLASH:
            if (!isPhoneTypeGsm()) {
                ar = (AsyncResult) msg.obj;
                if (ar.exception == null) {
                    postDelayed(new Runnable() {

                        public void run() {
                            if (mPendingMO != null) {
                                mCi.sendCDMAFeatureCode(mPendingMO.getAddress(), obtainMessage(EVENT_THREE_WAY_DIAL_L2_RESULT_CDMA));
                            }
                        }
                    }, m3WayCallFlashDelay);
                } else {
                    mPendingMO = null;
                    Rlog.w(LOG_TAG, "exception happened on Blank Flash for 3-way call");
                }
            } else {
                throw new RuntimeException("unexpected event " + msg.what + " not handled by " + "phone type " + mPhone.getPhoneType());
            }
            break;
        default:
            {
                throw new RuntimeException("unexpected event " + msg.what + " not handled by " + "phone type " + mPhone.getPhoneType());
            }
    }
}
Also used : CdmaCellLocation(android.telephony.cdma.CdmaCellLocation) GsmCellLocation(android.telephony.gsm.GsmCellLocation) CellLocation(android.telephony.CellLocation) CdmaCellLocation(android.telephony.cdma.CdmaCellLocation) GsmCellLocation(android.telephony.gsm.GsmCellLocation) AsyncResult(android.os.AsyncResult)

Example 48 with AsyncResult

use of android.os.AsyncResult in project android_frameworks_opt_telephony by LineageOS.

the class GsmCdmaConnection method processNextPostDialChar.

private void processNextPostDialChar() {
    char c = 0;
    Registrant postDialHandler;
    if (mPostDialState == PostDialState.CANCELLED) {
        releaseWakeLock();
        return;
    }
    if (mPostDialString == null || mPostDialString.length() <= mNextPostDialChar) {
        setPostDialState(PostDialState.COMPLETE);
        // We were holding a wake lock until pause-dial was complete, so give it up now
        releaseWakeLock();
        // notifyMessage.arg1 is 0 on complete
        c = 0;
    } else {
        boolean isValid;
        setPostDialState(PostDialState.STARTED);
        c = mPostDialString.charAt(mNextPostDialChar++);
        isValid = processPostDialChar(c);
        if (!isValid) {
            // Will call processNextPostDialChar
            mHandler.obtainMessage(EVENT_NEXT_POST_DIAL).sendToTarget();
            // Don't notify application
            Rlog.e(LOG_TAG, "processNextPostDialChar: c=" + c + " isn't valid!");
            return;
        }
    }
    notifyPostDialListenersNextChar(c);
    // TODO: remove the following code since the handler no longer executes anything.
    postDialHandler = mOwner.getPhone().getPostDialHandler();
    Message notifyMessage;
    if (postDialHandler != null && (notifyMessage = postDialHandler.messageForRegistrant()) != null) {
        // The AsyncResult.result is the Connection object
        PostDialState state = mPostDialState;
        AsyncResult ar = AsyncResult.forMessage(notifyMessage);
        ar.result = this;
        ar.userObj = state;
        // arg1 is the character that was/is being processed
        notifyMessage.arg1 = c;
        // Rlog.v("GsmCdma", "##### processNextPostDialChar: send msg to postDialHandler, arg1=" + c);
        notifyMessage.sendToTarget();
    }
}
Also used : Message(android.os.Message) Registrant(android.os.Registrant) AsyncResult(android.os.AsyncResult)

Example 49 with AsyncResult

use of android.os.AsyncResult in project android_frameworks_opt_telephony by LineageOS.

the class IccCard method sendMessageWithCardAbsentException.

private void sendMessageWithCardAbsentException(Message onComplete) {
    AsyncResult ret = AsyncResult.forMessage(onComplete);
    ret.exception = new RuntimeException("No valid IccCard");
    onComplete.sendToTarget();
}
Also used : AsyncResult(android.os.AsyncResult)

Example 50 with AsyncResult

use of android.os.AsyncResult in project android_frameworks_opt_telephony by LineageOS.

the class CarrierActionAgent method registerForCarrierAction.

/**
 * Register with CAA for a specific event.
 * @param action which carrier action registrant is interested in
 * @param notifyNow if carrier action has once set, notify registrant right after
 *                  registering, so that registrants will get the latest carrier action.
 */
public void registerForCarrierAction(int action, Handler h, int what, Object obj, boolean notifyNow) {
    Boolean carrierAction = getCarrierActionEnabled(action);
    if (carrierAction == null) {
        throw new IllegalArgumentException("invalid carrier action: " + action);
    }
    RegistrantList list = getRegistrantsFromAction(action);
    Registrant r = new Registrant(h, what, obj);
    list.add(r);
    if (notifyNow) {
        r.notifyRegistrant(new AsyncResult(null, carrierAction, null));
    }
}
Also used : RegistrantList(android.os.RegistrantList) Registrant(android.os.Registrant) AsyncResult(android.os.AsyncResult)

Aggregations

AsyncResult (android.os.AsyncResult)267 Test (org.junit.Test)60 Message (android.os.Message)57 TelephonyTest (com.android.internal.telephony.TelephonyTest)45 SmallTest (android.test.suitebuilder.annotation.SmallTest)26 ArrayList (java.util.ArrayList)21 Registrant (android.os.Registrant)19 FlakyTest (androidx.test.filters.FlakyTest)17 Intent (android.content.Intent)13 CellInfo (android.telephony.CellInfo)12 MediumTest (android.test.suitebuilder.annotation.MediumTest)12 SmallTest (androidx.test.filters.SmallTest)11 NetworkRegistrationInfo (android.telephony.NetworkRegistrationInfo)9 List (java.util.List)7 Mockito.anyString (org.mockito.Mockito.anyString)6 InvocationOnMock (org.mockito.invocation.InvocationOnMock)6 FlakyTest (android.support.test.filters.FlakyTest)5 MediumTest (android.support.test.filters.MediumTest)5 LteVopsSupportInfo (android.telephony.LteVopsSupportInfo)5 SmsMessage (android.telephony.SmsMessage)5