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

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

Merge "Fixed the race condition for data unthrottling"

parents 5a83929f f325d7d5
Loading
Loading
Loading
Loading
+12 −12
Original line number Diff line number Diff line
@@ -192,9 +192,18 @@ public class DataThrottler extends Handler {

        List<ThrottleStatus> changedStatuses = new ArrayList<>();
        while (apnTypes != 0) {

            int apnType;
            // Due to an APN error of ApnSetting.TYPE_DEFAULT (which combines default and hipri bit)
            // , we need to do special handling here.
            if ((apnTypes & ApnSetting.TYPE_DEFAULT) == ApnSetting.TYPE_DEFAULT) {
                apnType = ApnSetting.TYPE_DEFAULT;
                apnTypes &= ~ApnSetting.TYPE_DEFAULT;
            } else {
                //Extract the least significant bit.
            int apnType = apnTypes & -apnTypes;
                apnType = apnTypes & -apnTypes;
                //Remove the least significant bit.
                apnTypes &= apnTypes - 1;
            }

            //Update the apn throttle status
            ThrottleStatus newStatus = createStatus(apnType, retryElapsedTime, newRequestType);
@@ -209,9 +218,6 @@ public class DataThrottler extends Handler {
                //Put the new status in the temp space
                mThrottleStatus.put(apnType, newStatus);
            }

            //Remove the least significant bit.
            apnTypes &= apnTypes - 1;
        }

        if (changedStatuses.size() > 0) {
@@ -232,12 +238,6 @@ public class DataThrottler extends Handler {
     */
    @ElapsedRealtimeLong
    public long getRetryTime(@ApnType int apnType) {
        // This is the workaround to handle the mistake that
        // ApnSetting.TYPE_DEFAULT = ApnTypes.DEFAULT | ApnTypes.HIPRI.
        if (apnType == ApnSetting.TYPE_DEFAULT) {
            apnType &= ~(ApnSetting.TYPE_HIPRI);
        }

        ThrottleStatus status = mThrottleStatus.get(apnType);
        if (status != null) {
            if (status.getThrottleType() == ThrottleStatus.THROTTLE_TYPE_NONE) {
+20 −3
Original line number Diff line number Diff line
@@ -94,6 +94,7 @@ import android.telephony.data.ApnSetting;
import android.telephony.data.DataCallResponse;
import android.telephony.data.DataCallResponse.HandoverFailureMode;
import android.telephony.data.DataProfile;
import android.telephony.data.ThrottleStatus;
import android.telephony.gsm.GsmCellLocation;
import android.text.TextUtils;
import android.util.EventLog;
@@ -443,6 +444,19 @@ public class DcTracker extends Handler {
        }
    };

    private class ThrottleStatusChangedCallback implements DataThrottler.Callback {
        @Override
        public void onThrottleStatusChanged(List<ThrottleStatus> throttleStatuses) {
            for (ThrottleStatus status : throttleStatuses) {
                if (status.getThrottleType() == ThrottleStatus.THROTTLE_TYPE_NONE) {
                    setupDataOnConnectableApn(mApnContextsByType.get(status.getApnType()),
                            Phone.REASON_DATA_UNTHROTTLED,
                            RetryFailures.ALWAYS);
                }
            }
        }
    }

    private NetworkPolicyManager mNetworkPolicyManager;
    private final NetworkPolicyManager.SubscriptionCallback mSubscriptionCallback =
            new NetworkPolicyManager.SubscriptionCallback() {
@@ -714,6 +728,8 @@ public class DcTracker extends Handler {

    private final DataThrottler mDataThrottler;

    private final ThrottleStatusChangedCallback mThrottleStatusCallback;

    /**
     * Request network completion message map. Key is the APN type, value is the list of completion
     * messages to be sent. Using a list because there might be multiple network requests for
@@ -789,6 +805,9 @@ public class DcTracker extends Handler {

        mSettingsObserver = new SettingsObserver(mPhone.getContext(), this);
        registerSettingsObserver();

        mThrottleStatusCallback = new ThrottleStatusChangedCallback();
        mDataThrottler.registerForThrottleStatusChanges(mThrottleStatusCallback);
    }

    @VisibleForTesting
@@ -803,6 +822,7 @@ public class DcTracker extends Handler {
        mTransportType = 0;
        mDataServiceManager = null;
        mDataThrottler = null;
        mThrottleStatusCallback = null;
    }

    public void registerServiceStateTrackerEvents() {
@@ -2534,9 +2554,6 @@ public class DcTracker extends Handler {
                @ApnType int apnTypes = apnSetting.getApnTypeBitmask();
                mDataThrottler.setRetryTime(apnTypes, RetryManager.NO_SUGGESTED_RETRY_DELAY,
                        REQUEST_TYPE_NORMAL);
                // After data unthrottled, we should see if it's possible to bring up the data
                // again.
                setupDataOnAllConnectableApns(Phone.REASON_DATA_UNTHROTTLED, RetryFailures.ALWAYS);
            } else {
                loge("EVENT_APN_UNTHROTTLED: Invalid APN passed: " + apn);
            }
+2 −18
Original line number Diff line number Diff line
@@ -60,8 +60,6 @@ public class DataThrottlerTest extends TelephonyTest {
    @Mock
    private DataThrottler.Callback mMockChangedCallback2;

    private static final int DEFAULT_APN_TYPE = ApnSetting.TYPE_DEFAULT & ~(ApnSetting.TYPE_HIPRI);

    @Before
    public void setUp() throws Exception {
        super.setUp(getClass().getSimpleName());
@@ -99,14 +97,7 @@ public class DataThrottlerTest extends TelephonyTest {
                new ThrottleStatus.Builder()
                    .setSlotIndex(0)
                    .setTransportType(AccessNetworkConstants.TRANSPORT_TYPE_WWAN)
                        .setApnType(ApnSetting.TYPE_HIPRI)
                        .setThrottleExpiryTimeMillis(1234567890L)
                        .setRetryType(ThrottleStatus.RETRY_TYPE_NEW_CONNECTION)
                        .build(),
                new ThrottleStatus.Builder()
                    .setSlotIndex(0)
                    .setTransportType(AccessNetworkConstants.TRANSPORT_TYPE_WWAN)
                    .setApnType(DEFAULT_APN_TYPE)
                    .setApnType(ApnSetting.TYPE_DEFAULT)
                    .setThrottleExpiryTimeMillis(1234567890L)
                    .setRetryType(ThrottleStatus.RETRY_TYPE_NEW_CONNECTION)
                    .build())
@@ -121,13 +112,6 @@ public class DataThrottlerTest extends TelephonyTest {

        processAllMessages();
        expectedStatuses.add(List.of(
                new ThrottleStatus.Builder()
                        .setSlotIndex(0)
                        .setTransportType(AccessNetworkConstants.TRANSPORT_TYPE_WWAN)
                        .setApnType(ApnSetting.TYPE_HIPRI)
                        .setThrottleExpiryTimeMillis(13579L)
                        .setRetryType(ThrottleStatus.RETRY_TYPE_HANDOVER)
                        .build(),
                new ThrottleStatus.Builder()
                        .setSlotIndex(0)
                        .setTransportType(AccessNetworkConstants.TRANSPORT_TYPE_WWAN)
@@ -138,7 +122,7 @@ public class DataThrottlerTest extends TelephonyTest {
                new ThrottleStatus.Builder()
                        .setSlotIndex(0)
                        .setTransportType(AccessNetworkConstants.TRANSPORT_TYPE_WWAN)
                        .setApnType(DEFAULT_APN_TYPE)
                        .setApnType(ApnSetting.TYPE_DEFAULT)
                        .setThrottleExpiryTimeMillis(13579L)
                        .setRetryType(ThrottleStatus.RETRY_TYPE_HANDOVER)
                        .build())