Search in sources :

Example 6 with BarringInfo

use of android.telephony.BarringInfo in project android_frameworks_opt_telephony by LineageOS.

the class BarringInfoTest method testBarringService.

/**
 * Test that barring service info is stored properly by the constructor
 */
@Test
public void testBarringService() {
    BarringInfo b = new BarringInfo(null, getBarringServiceInfos());
    // Check that the MO data barring info matches the info provided in getBarringServiceInfos()
    BarringServiceInfo bsi = b.getBarringServiceInfo(BarringInfo.BARRING_SERVICE_TYPE_MO_DATA);
    assertEquals(bsi.getBarringType(), BarringServiceInfo.BARRING_TYPE_UNCONDITIONAL);
    // Check that the MMTEL barring info matches the info provided in getBarringServiceInfos()
    bsi = b.getBarringServiceInfo(BarringInfo.BARRING_SERVICE_TYPE_MMTEL_VIDEO);
    assertEquals(bsi.getBarringType(), BarringServiceInfo.BARRING_TYPE_CONDITIONAL);
    assertFalse(bsi.isConditionallyBarred());
    assertEquals(bsi.getConditionalBarringFactor(), CONDITIONAL_BARRING_FACTOR_PERCENT);
    assertEquals(bsi.getConditionalBarringTimeSeconds(), CONDITIONAL_BARRING_TIME_SECONDS);
    // Because BarringInfo is available, services that aren't reported as barred are
    // automatically reported as unbarred.
    bsi = b.getBarringServiceInfo(BarringInfo.BARRING_SERVICE_TYPE_SMS);
    assertEquals(bsi.getBarringType(), BarringServiceInfo.BARRING_TYPE_NONE);
    assertFalse(bsi.isConditionallyBarred());
    assertEquals(bsi.getConditionalBarringFactor(), 0);
    assertEquals(bsi.getConditionalBarringTimeSeconds(), 0);
}
Also used : BarringServiceInfo(android.telephony.BarringInfo.BarringServiceInfo) BarringInfo(android.telephony.BarringInfo) Test(org.junit.Test)

Example 7 with BarringInfo

use of android.telephony.BarringInfo in project android_frameworks_opt_telephony by LineageOS.

the class BarringInfoTest method testEmptyConstructor.

/**
 * Test that an empty constructor returns valid barring service info that's all not barred
 */
@Test
public void testEmptyConstructor() {
    BarringInfo b = new BarringInfo();
    for (int service : sServices) {
        BarringServiceInfo bsi = b.getBarringServiceInfo(service);
        assertNotNull(bsi);
        assertEquals(bsi.getBarringType(), BarringServiceInfo.BARRING_TYPE_UNKNOWN);
        assertFalse(bsi.isBarred());
    }
}
Also used : BarringServiceInfo(android.telephony.BarringInfo.BarringServiceInfo) BarringInfo(android.telephony.BarringInfo) Test(org.junit.Test)

Example 8 with BarringInfo

use of android.telephony.BarringInfo in project android_frameworks_opt_telephony by LineageOS.

the class GsmCdmaPhone method handleMessage.

@Override
public void handleMessage(Message msg) {
    AsyncResult ar;
    Message onComplete;
    switch(msg.what) {
        case EVENT_RADIO_AVAILABLE:
            {
                handleRadioAvailable();
            }
            break;
        case EVENT_GET_DEVICE_IDENTITY_DONE:
            {
                ar = (AsyncResult) msg.obj;
                if (ar.exception != null) {
                    break;
                }
                String[] respId = (String[]) ar.result;
                mImei = respId[0];
                mImeiSv = respId[1];
                mEsn = respId[2];
                mMeid = respId[3];
            }
            break;
        case EVENT_EMERGENCY_CALLBACK_MODE_ENTER:
            {
                handleEnterEmergencyCallbackMode(msg);
            }
            break;
        case EVENT_EXIT_EMERGENCY_CALLBACK_RESPONSE:
            {
                handleExitEmergencyCallbackMode(msg);
            }
            break;
        case EVENT_MODEM_RESET:
            {
                logd("Event EVENT_MODEM_RESET Received" + " isInEcm = " + isInEcm() + " isPhoneTypeGsm = " + isPhoneTypeGsm() + " mImsPhone = " + mImsPhone);
                if (isInEcm()) {
                    if (isPhoneTypeGsm()) {
                        if (mImsPhone != null) {
                            mImsPhone.handleExitEmergencyCallbackMode();
                        }
                    } else {
                        handleExitEmergencyCallbackMode(msg);
                    }
                }
            }
            break;
        case EVENT_RUIM_RECORDS_LOADED:
            logd("Event EVENT_RUIM_RECORDS_LOADED Received");
            updateCurrentCarrierInProvider();
            break;
        case EVENT_RADIO_ON:
            logd("Event EVENT_RADIO_ON Received");
            handleRadioOn();
            break;
        case EVENT_RIL_CONNECTED:
            ar = (AsyncResult) msg.obj;
            if (ar.exception == null && ar.result != null) {
                mRilVersion = (Integer) ar.result;
            } else {
                logd("Unexpected exception on EVENT_RIL_CONNECTED");
                mRilVersion = -1;
            }
            break;
        case EVENT_VOICE_RADIO_TECH_CHANGED:
        case EVENT_REQUEST_VOICE_RADIO_TECH_DONE:
            String what = (msg.what == EVENT_VOICE_RADIO_TECH_CHANGED) ? "EVENT_VOICE_RADIO_TECH_CHANGED" : "EVENT_REQUEST_VOICE_RADIO_TECH_DONE";
            ar = (AsyncResult) msg.obj;
            if (ar.exception == null) {
                if ((ar.result != null) && (((int[]) ar.result).length != 0)) {
                    int newVoiceTech = ((int[]) ar.result)[0];
                    logd(what + ": newVoiceTech=" + newVoiceTech);
                    phoneObjectUpdater(newVoiceTech);
                } else {
                    loge(what + ": has no tech!");
                }
            } else {
                loge(what + ": exception=" + ar.exception);
            }
            break;
        case EVENT_UPDATE_PHONE_OBJECT:
            phoneObjectUpdater(msg.arg1);
            break;
        case EVENT_CARRIER_CONFIG_CHANGED:
            // Obtain new radio capabilities from the modem, since some are SIM-dependent
            mCi.getRadioCapability(obtainMessage(EVENT_GET_RADIO_CAPABILITY));
            // registration changes.
            if (!mContext.getResources().getBoolean(com.android.internal.R.bool.config_switch_phone_on_voice_reg_state_change)) {
                mCi.getVoiceRadioTechnology(obtainMessage(EVENT_REQUEST_VOICE_RADIO_TECH_DONE));
            }
            // Force update IMS service if it is available, if it isn't the config will be
            // updated when ImsPhoneCallTracker opens a connection.
            ImsManager imsManager = ImsManager.getInstance(mContext, mPhoneId);
            if (imsManager.isServiceAvailable()) {
                imsManager.updateImsServiceConfig(true);
            } else {
                logd("ImsManager is not available to update CarrierConfig.");
            }
            // Update broadcastEmergencyCallStateChanges
            CarrierConfigManager configMgr = (CarrierConfigManager) getContext().getSystemService(Context.CARRIER_CONFIG_SERVICE);
            PersistableBundle b = configMgr.getConfigForSubId(getSubId());
            if (b != null) {
                boolean broadcastEmergencyCallStateChanges = b.getBoolean(CarrierConfigManager.KEY_BROADCAST_EMERGENCY_CALL_STATE_CHANGES_BOOL);
                logd("broadcastEmergencyCallStateChanges = " + broadcastEmergencyCallStateChanges);
                setBroadcastEmergencyCallStateChanges(broadcastEmergencyCallStateChanges);
            } else {
                loge("didn't get broadcastEmergencyCallStateChanges from carrier config");
            }
            // Changing the cdma roaming settings based carrier config.
            if (b != null) {
                int config_cdma_roaming_mode = b.getInt(CarrierConfigManager.KEY_CDMA_ROAMING_MODE_INT);
                int current_cdma_roaming_mode = Settings.Global.getInt(getContext().getContentResolver(), Settings.Global.CDMA_ROAMING_MODE, TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT);
                switch(config_cdma_roaming_mode) {
                    // when carrier's setting is turn off.
                    case TelephonyManager.CDMA_ROAMING_MODE_HOME:
                    case TelephonyManager.CDMA_ROAMING_MODE_AFFILIATED:
                    case TelephonyManager.CDMA_ROAMING_MODE_ANY:
                        logd("cdma_roaming_mode is going to changed to " + config_cdma_roaming_mode);
                        setCdmaRoamingPreference(config_cdma_roaming_mode, obtainMessage(EVENT_SET_ROAMING_PREFERENCE_DONE));
                        break;
                    // previous user's setting
                    case TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT:
                        if (current_cdma_roaming_mode != config_cdma_roaming_mode) {
                            logd("cdma_roaming_mode is going to changed to " + current_cdma_roaming_mode);
                            setCdmaRoamingPreference(current_cdma_roaming_mode, obtainMessage(EVENT_SET_ROAMING_PREFERENCE_DONE));
                        }
                    default:
                        loge("Invalid cdma_roaming_mode settings: " + config_cdma_roaming_mode);
                }
            } else {
                loge("didn't get the cdma_roaming_mode changes from the carrier config.");
            }
            break;
        case EVENT_SET_ROAMING_PREFERENCE_DONE:
            logd("cdma_roaming_mode change is done");
            break;
        case EVENT_CDMA_SUBSCRIPTION_SOURCE_CHANGED:
            logd("EVENT_CDMA_SUBSCRIPTION_SOURCE_CHANGED");
            mCdmaSubscriptionSource = mCdmaSSM.getCdmaSubscriptionSource();
            break;
        case EVENT_REGISTERED_TO_NETWORK:
            logd("Event EVENT_REGISTERED_TO_NETWORK Received");
            if (isPhoneTypeGsm()) {
                syncClirSetting();
            }
            break;
        case EVENT_SIM_RECORDS_LOADED:
            updateCurrentCarrierInProvider();
            // Check if this is a different SIM than the previous one. If so unset the
            // voice mail number.
            String imsi = getVmSimImsi();
            String imsiFromSIM = getSubscriberId();
            if ((!isPhoneTypeGsm() || imsi != null) && imsiFromSIM != null && !imsiFromSIM.equals(imsi)) {
                storeVoiceMailNumber(null);
                setVmSimImsi(null);
            }
            updateVoiceMail();
            mSimRecordsLoadedRegistrants.notifyRegistrants();
            break;
        case EVENT_GET_BASEBAND_VERSION_DONE:
            ar = (AsyncResult) msg.obj;
            if (ar.exception != null) {
                break;
            }
            if (DBG)
                logd("Baseband version: " + ar.result);
            /* Android property value is limited to 91 characters, but low layer
                 could pass a larger version string. To avoid runtime exception,
                 truncate the string baseband version string to 45 characters at most
                 for this per sub property. Since the latter part of the version string
                 is meaningful, truncated the version string from the beginning and
                 keep the end of the version.
                */
            String version = (String) ar.result;
            if (version != null) {
                int length = version.length();
                final int MAX_VERSION_LEN = SystemProperties.PROP_VALUE_MAX / 2;
                TelephonyManager.from(mContext).setBasebandVersionForPhone(getPhoneId(), length <= MAX_VERSION_LEN ? version : version.substring(length - MAX_VERSION_LEN, length));
            }
            break;
        case EVENT_GET_IMEI_DONE:
            ar = (AsyncResult) msg.obj;
            if (ar.exception != null) {
                break;
            }
            mImei = (String) ar.result;
            break;
        case EVENT_GET_IMEISV_DONE:
            ar = (AsyncResult) msg.obj;
            if (ar.exception != null) {
                break;
            }
            mImeiSv = (String) ar.result;
            break;
        case EVENT_USSD:
            ar = (AsyncResult) msg.obj;
            String[] ussdResult = (String[]) ar.result;
            if (ussdResult.length > 1) {
                try {
                    onIncomingUSSD(Integer.parseInt(ussdResult[0]), ussdResult[1]);
                } catch (NumberFormatException e) {
                    Rlog.w(LOG_TAG, "error parsing USSD");
                }
            }
            break;
        case EVENT_RADIO_OFF_OR_NOT_AVAILABLE:
            {
                logd("Event EVENT_RADIO_OFF_OR_NOT_AVAILABLE Received");
                handleRadioOffOrNotAvailable();
                break;
            }
        case EVENT_RADIO_STATE_CHANGED:
            {
                logd("EVENT EVENT_RADIO_STATE_CHANGED");
                handleRadioPowerStateChange();
                break;
            }
        case EVENT_SSN:
            logd("Event EVENT_SSN Received");
            if (isPhoneTypeGsm()) {
                ar = (AsyncResult) msg.obj;
                SuppServiceNotification not = (SuppServiceNotification) ar.result;
                mSsnRegistrants.notifyRegistrants(ar);
            }
            break;
        case EVENT_REGISTRATION_FAILED:
            logd("Event RegistrationFailed Received");
            ar = (AsyncResult) msg.obj;
            RegistrationFailedEvent rfe = (RegistrationFailedEvent) ar.result;
            mNotifier.notifyRegistrationFailed(this, rfe.cellIdentity, rfe.chosenPlmn, rfe.domain, rfe.causeCode, rfe.additionalCauseCode);
            break;
        case EVENT_BARRING_INFO_CHANGED:
            logd("Event BarringInfoChanged Received");
            ar = (AsyncResult) msg.obj;
            BarringInfo barringInfo = (BarringInfo) ar.result;
            mNotifier.notifyBarringInfoChanged(this, barringInfo);
            break;
        case EVENT_SET_CALL_FORWARD_DONE:
            ar = (AsyncResult) msg.obj;
            Cfu cfu = (Cfu) ar.userObj;
            if (ar.exception == null) {
                setVoiceCallForwardingFlag(1, msg.arg1 == 1, cfu.mSetCfNumber);
            }
            if (cfu.mOnComplete != null) {
                AsyncResult.forMessage(cfu.mOnComplete, ar.result, ar.exception);
                cfu.mOnComplete.sendToTarget();
            }
            break;
        case EVENT_SET_VM_NUMBER_DONE:
            ar = (AsyncResult) msg.obj;
            if (((isPhoneTypeGsm() || mSimRecords != null) && IccVmNotSupportedException.class.isInstance(ar.exception)) || (!isPhoneTypeGsm() && mSimRecords == null && IccException.class.isInstance(ar.exception))) {
                storeVoiceMailNumber(mVmNumber);
                ar.exception = null;
            }
            onComplete = (Message) ar.userObj;
            if (onComplete != null) {
                AsyncResult.forMessage(onComplete, ar.result, ar.exception);
                onComplete.sendToTarget();
            }
            break;
        case EVENT_GET_CALL_FORWARD_DONE:
            ar = (AsyncResult) msg.obj;
            if (ar.exception == null) {
                handleCfuQueryResult((CallForwardInfo[]) ar.result);
            }
            onComplete = (Message) ar.userObj;
            if (onComplete != null) {
                AsyncResult.forMessage(onComplete, ar.result, ar.exception);
                onComplete.sendToTarget();
            }
            break;
        case EVENT_SET_NETWORK_AUTOMATIC:
            // Automatic network selection from EF_CSP SIM record
            ar = (AsyncResult) msg.obj;
            if (mSST.mSS.getIsManualSelection()) {
                setNetworkSelectionModeAutomatic((Message) ar.result);
                logd("SET_NETWORK_SELECTION_AUTOMATIC: set to automatic");
            } else {
                // prevent duplicate request which will push current PLMN to low priority
                logd("SET_NETWORK_SELECTION_AUTOMATIC: already automatic, ignore");
            }
            break;
        case EVENT_ICC_RECORD_EVENTS:
            ar = (AsyncResult) msg.obj;
            processIccRecordEvents((Integer) ar.result);
            break;
        case EVENT_SET_CLIR_COMPLETE:
            ar = (AsyncResult) msg.obj;
            if (ar.exception == null) {
                saveClirSetting(msg.arg1);
            }
            onComplete = (Message) ar.userObj;
            if (onComplete != null) {
                AsyncResult.forMessage(onComplete, ar.result, ar.exception);
                onComplete.sendToTarget();
            }
            break;
        case EVENT_SS:
            ar = (AsyncResult) msg.obj;
            logd("Event EVENT_SS received");
            if (isPhoneTypeGsm()) {
                // SS data is already being handled through MMI codes.
                // So, this result if processed as MMI response would help
                // in re-using the existing functionality.
                GsmMmiCode mmi = new GsmMmiCode(this, mUiccApplication.get());
                mmi.processSsData(ar);
            }
            break;
        case EVENT_GET_RADIO_CAPABILITY:
            ar = (AsyncResult) msg.obj;
            RadioCapability rc = (RadioCapability) ar.result;
            if (ar.exception != null) {
                Rlog.d(LOG_TAG, "get phone radio capability fail, no need to change " + "mRadioCapability");
            } else {
                radioCapabilityUpdated(rc);
            }
            Rlog.d(LOG_TAG, "EVENT_GET_RADIO_CAPABILITY: phone rc: " + rc);
            break;
        case EVENT_VRS_OR_RAT_CHANGED:
            ar = (AsyncResult) msg.obj;
            Pair<Integer, Integer> vrsRatPair = (Pair<Integer, Integer>) ar.result;
            onVoiceRegStateOrRatChanged(vrsRatPair.first, vrsRatPair.second);
            break;
        case EVENT_SET_CARRIER_DATA_ENABLED:
            ar = (AsyncResult) msg.obj;
            boolean enabled = (boolean) ar.result;
            mDataEnabledSettings.setCarrierDataEnabled(enabled);
            break;
        case EVENT_DEVICE_PROVISIONED_CHANGE:
            mDataEnabledSettings.updateProvisionedChanged();
            break;
        case EVENT_DEVICE_PROVISIONING_DATA_SETTING_CHANGE:
            mDataEnabledSettings.updateProvisioningDataEnabled();
            break;
        case EVENT_GET_AVAILABLE_NETWORKS_DONE:
            ar = (AsyncResult) msg.obj;
            if (ar.exception == null && ar.result != null && mSST != null) {
                List<OperatorInfo> operatorInfoList = (List<OperatorInfo>) ar.result;
                List<OperatorInfo> filteredInfoList = new ArrayList<>();
                for (OperatorInfo operatorInfo : operatorInfoList) {
                    if (OperatorInfo.State.CURRENT == operatorInfo.getState()) {
                        filteredInfoList.add(new OperatorInfo(mSST.filterOperatorNameByPattern(operatorInfo.getOperatorAlphaLong()), mSST.filterOperatorNameByPattern(operatorInfo.getOperatorAlphaShort()), operatorInfo.getOperatorNumeric(), operatorInfo.getState()));
                    } else {
                        filteredInfoList.add(operatorInfo);
                    }
                }
                ar.result = filteredInfoList;
            }
            onComplete = (Message) ar.userObj;
            if (onComplete != null) {
                AsyncResult.forMessage(onComplete, ar.result, ar.exception);
                onComplete.sendToTarget();
            }
            break;
        case EVENT_GET_UICC_APPS_ENABLEMENT_DONE:
        case EVENT_UICC_APPS_ENABLEMENT_STATUS_CHANGED:
            ar = (AsyncResult) msg.obj;
            if (ar == null)
                return;
            if (ar.exception != null) {
                logd("Received exception on event" + msg.what + " : " + ar.exception);
                return;
            }
            mUiccApplicationsEnabled = (Boolean) ar.result;
        // Intentional falling through.
        case EVENT_UICC_APPS_ENABLEMENT_SETTING_CHANGED:
            reapplyUiccAppsEnablementIfNeeded(ENABLE_UICC_APPS_MAX_RETRIES);
            break;
        case EVENT_REAPPLY_UICC_APPS_ENABLEMENT_DONE:
            {
                ar = (AsyncResult) msg.obj;
                if (ar == null || ar.exception == null)
                    return;
                Pair<Boolean, Integer> userObject = (Pair) ar.userObj;
                if (userObject == null)
                    return;
                boolean expectedValue = userObject.first;
                int retries = userObject.second;
                CommandException.Error error = ((CommandException) ar.exception).getCommandError();
                loge("Error received when re-applying uicc application" + " setting to " + expectedValue + " on phone " + mPhoneId + " Error code: " + error + " retry count left: " + retries);
                if (retries > 0 && (error == GENERIC_FAILURE || error == SIM_BUSY)) {
                    // Retry for certain errors, but not for others like RADIO_NOT_AVAILABLE or
                    // SIM_ABSENT, as they will trigger it whey they become available.
                    postDelayed(() -> reapplyUiccAppsEnablementIfNeeded(retries - 1), REAPPLY_UICC_APPS_SETTING_RETRY_TIME_GAP_IN_MS);
                }
                break;
            }
        default:
            super.handleMessage(msg);
    }
}
Also used : ImsManager(com.android.ims.ImsManager) Message(android.os.Message) ArrayList(java.util.ArrayList) SuppServiceNotification(com.android.internal.telephony.gsm.SuppServiceNotification) BarringInfo(android.telephony.BarringInfo) GsmMmiCode(com.android.internal.telephony.gsm.GsmMmiCode) IccVmNotSupportedException(com.android.internal.telephony.uicc.IccVmNotSupportedException) RegistrantList(android.os.RegistrantList) ArrayList(java.util.ArrayList) List(java.util.List) Pair(android.util.Pair) CarrierConfigManager(android.telephony.CarrierConfigManager) IccException(com.android.internal.telephony.uicc.IccException) PersistableBundle(android.os.PersistableBundle) AsyncResult(android.os.AsyncResult)

Aggregations

BarringInfo (android.telephony.BarringInfo)8 Test (org.junit.Test)5 AsyncResult (android.os.AsyncResult)3 BarringServiceInfo (android.telephony.BarringInfo.BarringServiceInfo)2 Message (android.os.Message)1 Parcel (android.os.Parcel)1 PersistableBundle (android.os.PersistableBundle)1 RegistrantList (android.os.RegistrantList)1 CarrierConfigManager (android.telephony.CarrierConfigManager)1 CellIdentity (android.telephony.CellIdentity)1 Pair (android.util.Pair)1 ImsManager (com.android.ims.ImsManager)1 GsmMmiCode (com.android.internal.telephony.gsm.GsmMmiCode)1 SuppServiceNotification (com.android.internal.telephony.gsm.SuppServiceNotification)1 IccException (com.android.internal.telephony.uicc.IccException)1 IccVmNotSupportedException (com.android.internal.telephony.uicc.IccVmNotSupportedException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1