Search in sources :

Example 6 with DataConnectionAc

use of com.android.internal.telephony.DataConnectionAc in project XobotOS by xamarin.

the class GsmDataConnectionTracker method onDataSetupComplete.

@Override
protected void onDataSetupComplete(AsyncResult ar) {
    ApnContext apnContext = null;
    if (ar.userObj instanceof ApnContext) {
        apnContext = (ApnContext) ar.userObj;
    } else {
        throw new RuntimeException("onDataSetupComplete: No apnContext");
    }
    if (isDataSetupCompleteOk(ar)) {
        DataConnectionAc dcac = apnContext.getDataConnectionAc();
        if (dcac == null) {
            throw new RuntimeException("onDataSetupCompete: No dcac");
        }
        DataConnection dc = apnContext.getDataConnection();
        if (DBG) {
            log(String.format("onDataSetupComplete: success apn=%s", apnContext.getWaitingApns().get(0).apn));
        }
        ApnSetting apn = apnContext.getApnSetting();
        if (apn.proxy != null && apn.proxy.length() != 0) {
            try {
                String port = apn.port;
                if (TextUtils.isEmpty(port))
                    port = "8080";
                ProxyProperties proxy = new ProxyProperties(apn.proxy, Integer.parseInt(port), null);
                dcac.setLinkPropertiesHttpProxySync(proxy);
            } catch (NumberFormatException e) {
                loge("onDataSetupComplete: NumberFormatException making ProxyProperties (" + apn.port + "): " + e);
            }
        }
        // everything is setup
        if (TextUtils.equals(apnContext.getApnType(), Phone.APN_TYPE_DEFAULT)) {
            SystemProperties.set("gsm.defaultpdpcontext.active", "true");
            if (canSetPreferApn && mPreferredApn == null) {
                if (DBG)
                    log("onDataSetupComplete: PREFERED APN is null");
                mPreferredApn = apnContext.getApnSetting();
                if (mPreferredApn != null) {
                    setPreferredApn(mPreferredApn.id);
                }
            }
        } else {
            SystemProperties.set("gsm.defaultpdpcontext.active", "false");
        }
        notifyDefaultData(apnContext);
    } else {
        String apnString;
        DataConnection.FailCause cause;
        cause = (DataConnection.FailCause) (ar.result);
        if (DBG) {
            try {
                apnString = apnContext.getWaitingApns().get(0).apn;
            } catch (Exception e) {
                apnString = "<unknown>";
            }
            log(String.format("onDataSetupComplete: error apn=%s cause=%s", apnString, cause));
        }
        if (cause.isEventLoggable()) {
            // Log this failure to the Event Logs.
            int cid = getCellLocationId();
            EventLog.writeEvent(EventLogTags.PDP_SETUP_FAIL, cause.ordinal(), cid, TelephonyManager.getDefault().getNetworkType());
        }
        // Count permanent failures and remove the APN we just tried
        if (cause.isPermanentFail())
            apnContext.decWaitingApnsPermFailCount();
        apnContext.removeNextWaitingApn();
        if (DBG) {
            log(String.format("onDataSetupComplete: WaitingApns.size=%d" + " WaitingApnsPermFailureCountDown=%d", apnContext.getWaitingApns().size(), apnContext.getWaitingApnsPermFailCount()));
        }
        // See if there are more APN's to try
        if (apnContext.getWaitingApns().isEmpty()) {
            if (apnContext.getWaitingApnsPermFailCount() == 0) {
                if (DBG) {
                    log("onDataSetupComplete: All APN's had permanent failures, stop retrying");
                }
                apnContext.setState(State.FAILED);
                mPhone.notifyDataConnection(Phone.REASON_APN_FAILED, apnContext.getApnType());
                apnContext.setDataConnection(null);
                apnContext.setDataConnectionAc(null);
                if (DBG) {
                    log("onDataSetupComplete: permanent error apn=%s" + apnString);
                }
            } else {
                if (DBG)
                    log("onDataSetupComplete: Not all permanent failures, retry");
                // check to see if retry should be overridden for this failure.
                int retryOverride = -1;
                if (ar.exception instanceof DataConnection.CallSetupException) {
                    retryOverride = ((DataConnection.CallSetupException) ar.exception).getRetryOverride();
                }
                if (retryOverride == RILConstants.MAX_INT) {
                    if (DBG)
                        log("No retry is suggested.");
                } else {
                    startDelayedRetry(cause, apnContext, retryOverride);
                }
            }
        } else {
            if (DBG)
                log("onDataSetupComplete: Try next APN");
            apnContext.setState(State.SCANNING);
            // Wait a bit before trying the next APN, so that
            // we're not tying up the RIL command channel
            startAlarmForReconnect(APN_DELAY_MILLIS, apnContext);
        }
    }
}
Also used : ProxyProperties(android.net.ProxyProperties) DataConnection(com.android.internal.telephony.DataConnection) ApnContext(com.android.internal.telephony.ApnContext) DataConnectionAc(com.android.internal.telephony.DataConnectionAc) FailCause(com.android.internal.telephony.DataConnection.FailCause) ApnSetting(com.android.internal.telephony.ApnSetting)

Example 7 with DataConnectionAc

use of com.android.internal.telephony.DataConnectionAc in project XobotOS by xamarin.

the class GsmDataConnectionTracker method startAlarmForReconnect.

private void startAlarmForReconnect(int delay, ApnContext apnContext) {
    if (DBG) {
        log("Schedule alarm for reconnect: activate failed. Scheduling next attempt for " + (delay / 1000) + "s");
    }
    DataConnectionAc dcac = apnContext.getDataConnectionAc();
    if ((dcac == null) || (dcac.dataConnection == null)) {
        // should not happen, but just in case.
        loge("null dcac or dc.");
        return;
    }
    AlarmManager am = (AlarmManager) mPhone.getContext().getSystemService(Context.ALARM_SERVICE);
    Intent intent = new Intent(INTENT_RECONNECT_ALARM + '.' + dcac.dataConnection.getDataConnectionId());
    intent.putExtra(INTENT_RECONNECT_ALARM_EXTRA_REASON, apnContext.getReason());
    intent.putExtra(INTENT_RECONNECT_ALARM_EXTRA_TYPE, dcac.dataConnection.getDataConnectionId());
    PendingIntent alarmIntent = PendingIntent.getBroadcast(mPhone.getContext(), 0, intent, 0);
    dcac.setReconnectIntentSync(alarmIntent);
    am.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + delay, alarmIntent);
}
Also used : DataConnectionAc(com.android.internal.telephony.DataConnectionAc) AlarmManager(android.app.AlarmManager) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent)

Example 8 with DataConnectionAc

use of com.android.internal.telephony.DataConnectionAc in project XobotOS by xamarin.

the class GsmDataConnectionTracker method onActionIntentReconnectAlarm.

@Override
protected void onActionIntentReconnectAlarm(Intent intent) {
    if (DBG)
        log("GPRS reconnect alarm. Previous state was " + mState);
    String reason = intent.getStringExtra(INTENT_RECONNECT_ALARM_EXTRA_REASON);
    int connectionId = intent.getIntExtra(INTENT_RECONNECT_ALARM_EXTRA_TYPE, -1);
    DataConnectionAc dcac = mDataConnectionAsyncChannels.get(connectionId);
    if (dcac != null) {
        for (ApnContext apnContext : dcac.getApnListSync()) {
            apnContext.setReason(reason);
            if (apnContext.getState() == State.FAILED) {
                apnContext.setState(State.IDLE);
            }
            sendMessage(obtainMessage(EVENT_TRY_SETUP_DATA, apnContext));
        }
        // Alram had expired. Clear pending intent recorded on the DataConnection.
        dcac.setReconnectIntentSync(null);
    }
}
Also used : ApnContext(com.android.internal.telephony.ApnContext) DataConnectionAc(com.android.internal.telephony.DataConnectionAc)

Example 9 with DataConnectionAc

use of com.android.internal.telephony.DataConnectionAc in project XobotOS by xamarin.

the class CdmaDataConnectionTracker method cleanUpConnection.

/**
     * Cleanup the CDMA data connection (only one is supported)
     *
     * @param tearDown true if the underlying DataConnection should be disconnected.
     * @param reason for the clean up.
     */
private void cleanUpConnection(boolean tearDown, String reason) {
    if (DBG)
        log("cleanUpConnection: reason: " + reason);
    // Clear the reconnect alarm, if set.
    if (mReconnectIntent != null) {
        AlarmManager am = (AlarmManager) mPhone.getContext().getSystemService(Context.ALARM_SERVICE);
        am.cancel(mReconnectIntent);
        mReconnectIntent = null;
    }
    setState(State.DISCONNECTING);
    notifyOffApnsOfAvailability(reason);
    boolean notificationDeferred = false;
    for (DataConnection conn : mDataConnections.values()) {
        if (conn != null) {
            DataConnectionAc dcac = mDataConnectionAsyncChannels.get(conn.getDataConnectionId());
            if (tearDown) {
                if (DBG)
                    log("cleanUpConnection: teardown, call conn.disconnect");
                conn.tearDown(reason, obtainMessage(EVENT_DISCONNECT_DONE, conn.getDataConnectionId(), 0, reason));
                notificationDeferred = true;
            } else {
                if (DBG)
                    log("cleanUpConnection: !tearDown, call conn.resetSynchronously");
                if (dcac != null) {
                    dcac.resetSync();
                }
                notificationDeferred = false;
            }
        }
    }
    stopNetStatPoll();
    if (!notificationDeferred) {
        if (DBG)
            log("cleanupConnection: !notificationDeferred");
        gotoIdleAndNotifyDataConnection(reason);
    }
}
Also used : DataConnection(com.android.internal.telephony.DataConnection) DataConnectionAc(com.android.internal.telephony.DataConnectionAc) AlarmManager(android.app.AlarmManager)

Example 10 with DataConnectionAc

use of com.android.internal.telephony.DataConnectionAc in project XobotOS by xamarin.

the class CdmaDataConnectionTracker method createAllDataConnectionList.

private void createAllDataConnectionList() {
    CdmaDataConnection dataConn;
    String retryConfig = SystemProperties.get("ro.cdma.data_retry_config");
    for (int i = 0; i < DATA_CONNECTION_POOL_SIZE; i++) {
        RetryManager rm = new RetryManager();
        if (!rm.configure(retryConfig)) {
            if (!rm.configure(DEFAULT_DATA_RETRY_CONFIG)) {
                // Should never happen, log an error and default to a simple linear sequence.
                log("Could not configure using DEFAULT_DATA_RETRY_CONFIG=" + DEFAULT_DATA_RETRY_CONFIG);
                rm.configure(20, 2000, 1000);
            }
        }
        int id = mUniqueIdGenerator.getAndIncrement();
        dataConn = CdmaDataConnection.makeDataConnection(mCdmaPhone, id, rm);
        mDataConnections.put(id, dataConn);
        DataConnectionAc dcac = new DataConnectionAc(dataConn, LOG_TAG);
        int status = dcac.fullyConnectSync(mPhone.getContext(), this, dataConn.getHandler());
        if (status == AsyncChannel.STATUS_SUCCESSFUL) {
            log("Fully connected");
            mDataConnectionAsyncChannels.put(dcac.dataConnection.getDataConnectionId(), dcac);
        } else {
            log("Could not connect to dcac.dataConnection=" + dcac.dataConnection + " status=" + status);
        }
    }
}
Also used : RetryManager(com.android.internal.telephony.RetryManager) DataConnectionAc(com.android.internal.telephony.DataConnectionAc)

Aggregations

DataConnectionAc (com.android.internal.telephony.DataConnectionAc)10 ApnContext (com.android.internal.telephony.ApnContext)5 AlarmManager (android.app.AlarmManager)2 Message (android.os.Message)2 ApnSetting (com.android.internal.telephony.ApnSetting)2 DataConnection (com.android.internal.telephony.DataConnection)2 RetryManager (com.android.internal.telephony.RetryManager)2 PendingIntent (android.app.PendingIntent)1 Intent (android.content.Intent)1 IntentFilter (android.content.IntentFilter)1 LinkAddress (android.net.LinkAddress)1 ProxyProperties (android.net.ProxyProperties)1 DataCallState (com.android.internal.telephony.DataCallState)1 FailCause (com.android.internal.telephony.DataConnection.FailCause)1 UpdateLinkPropertyResult (com.android.internal.telephony.DataConnection.UpdateLinkPropertyResult)1 ArrayList (java.util.ArrayList)1