Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 12b94a5c authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Modify data-Retry mechanism with message method"

parents 63d503d4 984c72f2
Loading
Loading
Loading
Loading
+0 −19
Original line number Diff line number Diff line
@@ -16,7 +16,6 @@

package com.android.internal.telephony.dataconnection;

import android.app.PendingIntent;
import android.net.ConnectivityManager;
import android.net.NetworkCapabilities;
import android.net.NetworkConfig;
@@ -68,8 +67,6 @@ public class ApnContext {

    String mReason;

    PendingIntent mReconnectAlarmIntent;

    /**
     * user/app requested connection on this APN
     */
@@ -169,22 +166,6 @@ public class ApnContext {
        setState(DctConstants.State.IDLE);
    }

    /**
     * Get the reconnect intent.
     * @return The reconnect intent
     */
    public synchronized PendingIntent getReconnectIntent() {
        return mReconnectAlarmIntent;
    }

    /**
     * Save the reconnect intent which can be used for cancelling later.
     * @param intent The reconnect intent
     */
    public synchronized void setReconnectIntent(PendingIntent intent) {
        mReconnectAlarmIntent = intent;
    }

    /**
     * Get the current APN setting.
     * @return APN setting
+31 −82
Original line number Diff line number Diff line
@@ -66,8 +66,8 @@ import android.provider.Settings.SettingNotFoundException;
import android.provider.Telephony;
import android.telephony.AccessNetworkConstants;
import android.telephony.AccessNetworkConstants.TransportType;
import android.telephony.Annotation.DataFailureCause;
import android.telephony.Annotation.ApnType;
import android.telephony.Annotation.DataFailureCause;
import android.telephony.Annotation.NetworkType;
import android.telephony.Annotation.RilRadioTechnology;
import android.telephony.CarrierConfigManager;
@@ -254,14 +254,6 @@ public class DcTracker extends Handler {
    private static final boolean DATA_STALL_SUSPECTED = true;
    private static final boolean DATA_STALL_NOT_SUSPECTED = false;

    private static final String INTENT_RECONNECT_ALARM =
            "com.android.internal.telephony.data-reconnect";
    private static final String INTENT_RECONNECT_ALARM_EXTRA_TYPE = "reconnect_alarm_extra_type";
    private static final String INTENT_RECONNECT_ALARM_EXTRA_REASON =
            "reconnect_alarm_extra_reason";
    private static final String INTENT_RECONNECT_ALARM_EXTRA_TRANSPORT_TYPE =
            "reconnect_alarm_extra_transport_type";

    private static final String INTENT_DATA_STALL_ALARM =
            "com.android.internal.telephony.data-stall";
    // Tag for tracking stale alarms
@@ -358,8 +350,6 @@ public class DcTracker extends Handler {
                stopNetStatPoll();
                startNetStatPoll();
                restartDataStallAlarm();
            } else if (action.startsWith(INTENT_RECONNECT_ALARM)) {
                onActionIntentReconnectAlarm(intent);
            } else if (action.equals(INTENT_DATA_STALL_ALARM)) {
                onActionIntentDataStallAlarm(intent);
            } else if (action.equals(INTENT_PROVISIONING_APN_ALARM)) {
@@ -491,28 +481,13 @@ public class DcTracker extends Handler {
        }
    }

    private void onActionIntentReconnectAlarm(Intent intent) {
        Message msg = obtainMessage(DctConstants.EVENT_DATA_RECONNECT);
        msg.setData(intent.getExtras());
        sendMessage(msg);
    }

    private void onDataReconnect(Bundle bundle) {
        String reason = bundle.getString(INTENT_RECONNECT_ALARM_EXTRA_REASON);
        String apnType = bundle.getString(INTENT_RECONNECT_ALARM_EXTRA_TYPE);

    private void onDataReconnect(ApnContext apnContextforRetry, int subId) {
        int phoneSubId = mPhone.getSubId();
        int currSubId = bundle.getInt(PhoneConstants.SUBSCRIPTION_KEY,
                SubscriptionManager.INVALID_SUBSCRIPTION_ID);
        String apnType = apnContextforRetry.getApnType();
        String reason =  apnContextforRetry.getReason();

        // Stop reconnect if not current subId is not correct.
        // FIXME STOPSHIP - phoneSubId is coming up as -1 way after boot and failing this?
        if (!SubscriptionManager.isValidSubscriptionId(currSubId) || (currSubId != phoneSubId)) {
            return;
        }

        int transportType = bundle.getInt(INTENT_RECONNECT_ALARM_EXTRA_TRANSPORT_TYPE, 0);
        if (transportType != mTransportType) {
        if (!SubscriptionManager.isValidSubscriptionId(subId) || (subId != phoneSubId)) {
            log("onDataReconnect: invalid subId");
            return;
        }

@@ -540,8 +515,6 @@ public class DcTracker extends Handler {
            }
            // TODO: IF already associated should we send the EVENT_TRY_SETUP_DATA???
            sendMessage(obtainMessage(DctConstants.EVENT_TRY_SETUP_DATA, apnContext));

            apnContext.setReconnectIntent(null);
        }
    }

@@ -749,13 +722,6 @@ public class DcTracker extends Handler {

        initApnContexts();

        for (ApnContext apnContext : mApnContexts.values()) {
            // Register the reconnect and restart actions.
            filter = new IntentFilter();
            filter.addAction(INTENT_RECONNECT_ALARM + '.' + apnContext.getApnType());
            mPhone.getContext().registerReceiver(mIntentReceiver, filter, null, mPhone);
        }

        initEmergencyApnSetting();
        addEmergencyApnSetting();

@@ -1753,7 +1719,7 @@ public class DcTracker extends Handler {
        // Make sure reconnection alarm is cleaned up if there is no ApnContext
        // associated to the connection.
        if (dataConnection != null) {
            cancelReconnectAlarm(apnContext);
            cancelReconnect(apnContext);
        }
        str = "cleanUpConnectionInternal: X detach=" + detach + " reason="
                + apnContext.getReason();
@@ -1856,24 +1822,6 @@ public class DcTracker extends Handler {
        return null;
    }

    /**
     * Cancels the alarm associated with apnContext.
     *
     * @param apnContext on which the alarm should be stopped.
     */
    private void cancelReconnectAlarm(ApnContext apnContext) {
        if (apnContext == null) return;

        PendingIntent intent = apnContext.getReconnectIntent();

        if (intent != null) {
                AlarmManager am =
                    (AlarmManager) mPhone.getContext().getSystemService(Context.ALARM_SERVICE);
                am.cancel(intent);
                apnContext.setReconnectIntent(null);
        }
    }

    boolean isPermanentFailure(@DataFailureCause int dcFailCause) {
        return (DataFailCause.isPermanentFailure(mPhone.getContext(), dcFailCause,
                mPhone.getSubId())
@@ -2198,31 +2146,31 @@ public class DcTracker extends Handler {
        return retry;
    }

    private void startAlarmForReconnect(long delay, ApnContext apnContext) {
        String apnType = apnContext.getApnType();

        Intent intent = new Intent(INTENT_RECONNECT_ALARM + "." + apnType);
        intent.putExtra(INTENT_RECONNECT_ALARM_EXTRA_REASON, apnContext.getReason());
        intent.putExtra(INTENT_RECONNECT_ALARM_EXTRA_TYPE, apnType);
        intent.putExtra(INTENT_RECONNECT_ALARM_EXTRA_TRANSPORT_TYPE, mTransportType);
        SubscriptionManager.putPhoneIdAndSubIdExtra(intent, mPhone.getPhoneId());
        intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
    private void startReconnect(long delay, ApnContext apnContext) {
        Message msg = obtainMessage(DctConstants.EVENT_DATA_RECONNECT,
                       mPhone.getSubId(), mTransportType, apnContext);
        cancelReconnect(apnContext);
        sendMessageDelayed(msg, delay);

        if (DBG) {
            log("startAlarmForReconnect: delay=" + delay + " action=" + intent.getAction()
                    + " apn=" + apnContext);
            log("startReconnect: delay=" + delay + " apn="
                    + apnContext + "reason: " + apnContext.getReason()
                    + " subId: " + mPhone.getSubId());
        }
    }

        PendingIntent alarmIntent = PendingIntent.getBroadcast(mPhone.getContext(), 0,
                                        intent, PendingIntent.FLAG_UPDATE_CURRENT);
        apnContext.setReconnectIntent(alarmIntent);
    /**
     * Cancels the alarm associated with apnContext.
     *
     * @param apnContext on which the alarm should be stopped.
     */
    private void cancelReconnect(ApnContext apnContext) {
        if (apnContext == null) return;

        // Use the exact timer instead of the inexact one to provide better user experience.
        // In some extreme cases, we saw the retry was delayed for few minutes.
        // Note that if the stated trigger time is in the past, the alarm will be triggered
        // immediately.
        mAlarmManager.setExact(AlarmManager.ELAPSED_REALTIME_WAKEUP,
                SystemClock.elapsedRealtime() + delay, alarmIntent);
        if (DBG) {
            log("cancelReconnect: apn=" + apnContext);
        }
        removeMessages(DctConstants.EVENT_DATA_RECONNECT, apnContext);
    }

    private void notifyNoData(@DataFailureCause int lastFailCauseCode,
@@ -2903,7 +2851,7 @@ public class DcTracker extends Handler {
            // Wait a bit before trying the next APN, so that
            // we're not tying up the RIL command channel

            startAlarmForReconnect(delay, apnContext);
            startReconnect(delay, apnContext);
        } else {
            // If we are not going to retry any APN, set this APN context to failed state.
            // This would be the final state of a data connection.
@@ -2996,7 +2944,7 @@ public class DcTracker extends Handler {
            if (delay > 0) {
                // Data connection is in IDLE state, so when we reconnect later, we'll rebuild
                // the waiting APN list, which will also reset/reconfigure the retry manager.
                startAlarmForReconnect(delay, apnContext);
                startReconnect(delay, apnContext);
            }
        } else {
            boolean restartRadioAfterProvisioning = mPhone.getContext().getResources().getBoolean(
@@ -3775,7 +3723,8 @@ public class DcTracker extends Handler {
                break;
            }
            case DctConstants.EVENT_DATA_RECONNECT:
                onDataReconnect(msg.getData());
                if (DBG) log("EVENT_DATA_RECONNECT: subId=" + msg.arg1);
                onDataReconnect((ApnContext) msg.obj, msg.arg1);
                break;
            case DctConstants.EVENT_DATA_SERVICE_BINDING_CHANGED:
                onDataServiceBindingChanged((Boolean) ((AsyncResult) msg.obj).result);
+10 −20
Original line number Diff line number Diff line
@@ -720,21 +720,14 @@ public class DcTrackerTest extends TelephonyTest {
                any(Message.class));
        verifyDataProfile(dpCaptor.getValue(), FAKE_APN1, 0, 21, 1, NETWORK_TYPE_LTE_BITMASK);

        // Verify the retry manger schedule another data call setup.
        verify(mAlarmManager, times(1)).setExact(eq(AlarmManager.ELAPSED_REALTIME_WAKEUP),
                anyLong(), any(PendingIntent.class));

        // This time we'll let RIL command succeed.
        mSimulatedCommands.setDataCallResult(true, createSetupDataCallResult());

        // Simulate the timer expires.
        Intent intent = new Intent("com.android.internal.telephony.data-reconnect.default");
        intent.putExtra("reconnect_alarm_extra_type", PhoneConstants.APN_TYPE_DEFAULT);
        intent.putExtra("reconnect_alarm_extra_transport_type",
                AccessNetworkConstants.TRANSPORT_TYPE_WWAN);
        intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, 0);
        intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
        mContext.sendBroadcast(intent);
        //Send event for reconnecting data
        initApns(PhoneConstants.APN_TYPE_DEFAULT, new String[]{PhoneConstants.APN_TYPE_ALL});
        mDct.sendMessage(mDct.obtainMessage(DctConstants.EVENT_DATA_RECONNECT,
                        mPhone.getPhoneId(), AccessNetworkConstants.TRANSPORT_TYPE_WWAN,
                        mApnContext));
        waitForMs(200);

        dpCaptor = ArgumentCaptor.forClass(DataProfile.class);
@@ -1361,14 +1354,11 @@ public class DcTrackerTest extends TelephonyTest {
        verify(mAlarmManager, times(1)).setExact(eq(AlarmManager.ELAPSED_REALTIME_WAKEUP),
                anyLong(), any(PendingIntent.class));

        // Simulate the timer expires.
        Intent intent = new Intent("com.android.internal.telephony.data-reconnect.default");
        intent.putExtra("reconnect_alarm_extra_type", PhoneConstants.APN_TYPE_DEFAULT);
        intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, 0);
        intent.putExtra("reconnect_alarm_extra_transport_type",
                AccessNetworkConstants.TRANSPORT_TYPE_WWAN);
        intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
        mContext.sendBroadcast(intent);
        //Send event for reconnecting data
        initApns(PhoneConstants.APN_TYPE_DEFAULT, new String[]{PhoneConstants.APN_TYPE_ALL});
        mDct.sendMessage(mDct.obtainMessage(DctConstants.EVENT_DATA_RECONNECT,
                        mPhone.getPhoneId(), AccessNetworkConstants.TRANSPORT_TYPE_WWAN,
                        mApnContext));
        waitForMs(200);

        // Verify if RIL command was sent properly.