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

Commit 224485b5 authored by Daniel Bright's avatar Daniel Bright Committed by Gerrit Code Review
Browse files

Merge "Changed ApnThrottleStatus to ThrottleStatus"

parents e534e108 9e97a579
Loading
Loading
Loading
Loading
+13 −13
Original line number Diff line number Diff line
@@ -36,10 +36,10 @@ import android.telephony.Annotation.ApnType;
import android.telephony.AnomalyReporter;
import android.telephony.CarrierConfigManager;
import android.telephony.data.ApnSetting;
import android.telephony.data.ApnThrottleStatus;
import android.telephony.data.IQualifiedNetworksService;
import android.telephony.data.IQualifiedNetworksServiceCallback;
import android.telephony.data.QualifiedNetworksService;
import android.telephony.data.ThrottleStatus;
import android.text.TextUtils;
import android.util.SparseArray;

@@ -173,10 +173,10 @@ public class AccessNetworksManager extends Handler {
         * the same life cycle.
         */
        @NonNull
        private final ApnThrottleStatusChangedCallback mThrottleStatusCallback;
        private final ThrottleStatusChangedCallback mThrottleStatusCallback;

        QualifiedNetworksServiceConnection() {
            mThrottleStatusCallback = new ApnThrottleStatusChangedCallback();
            mThrottleStatusCallback = new ThrottleStatusChangedCallback();
        }

        @Override
@@ -212,41 +212,41 @@ public class AccessNetworksManager extends Handler {
        private void registerDataThrottlersFirstTime() {
            post(() -> {
                for (DataThrottler dataThrottler : mDataThrottlers) {
                    dataThrottler.registerForApnThrottleStatusChanges(mThrottleStatusCallback);
                    dataThrottler.registerForThrottleStatusChanges(mThrottleStatusCallback);
                }
            });
        }

        private void registerDataThrottler(DataThrottler dataThrottler) {
            post(() -> {
                dataThrottler.registerForApnThrottleStatusChanges(mThrottleStatusCallback);
                dataThrottler.registerForThrottleStatusChanges(mThrottleStatusCallback);
            });
        }

        private void unregisterForThrottleCallbacks() {
            post(() -> {
                for (DataThrottler dataThrottler : mDataThrottlers) {
                    dataThrottler.unregisterForApnThrottleStatusChanges(mThrottleStatusCallback);
                    dataThrottler.unregisterForThrottleStatusChanges(mThrottleStatusCallback);
                }
            });
        }
    }

    private class ApnThrottleStatusChangedCallback implements DataThrottler.Callback {
    private class ThrottleStatusChangedCallback implements DataThrottler.Callback {
        @Override
        public void onApnThrottleStatusChanged(List<ApnThrottleStatus> apnThrottleStatuses) {
        public void onThrottleStatusChanged(List<ThrottleStatus> throttleStatuses) {
            post(() -> {
                try {
                    List<ApnThrottleStatus> apnThrottleStatusesBySlot =
                            apnThrottleStatuses
                    List<ThrottleStatus> throttleStatusesBySlot =
                            throttleStatuses
                                    .stream()
                                    .filter(x -> x.getSlotIndex() == mPhone.getPhoneId())
                                    .collect(Collectors.toList());

                    mIQualifiedNetworksService.reportApnThrottleStatusChanged(mPhone.getPhoneId(),
                            apnThrottleStatusesBySlot);
                    mIQualifiedNetworksService.reportThrottleStatusChanged(mPhone.getPhoneId(),
                            throttleStatusesBySlot);
                } catch (Exception ex) {
                    loge("onApnThrottleStatusChanged", ex);
                    loge("onThrottleStatusChanged", ex);
                }
            });
        }
+24 −24
Original line number Diff line number Diff line
@@ -21,7 +21,7 @@ import android.telephony.AccessNetworkConstants;
import android.telephony.Annotation;
import android.telephony.Annotation.ApnType;
import android.telephony.data.ApnSetting;
import android.telephony.data.ApnThrottleStatus;
import android.telephony.data.ThrottleStatus;

import com.android.internal.telephony.RetryManager;
import com.android.telephony.Rlog;
@@ -50,7 +50,7 @@ public class DataThrottler {
     * Keeps track of detailed information of the throttle status that is meant to be
     * reported to other components.
     */
    private final Map<Integer, ApnThrottleStatus> mApnThrottleStatus = new ConcurrentHashMap<>();
    private final Map<Integer, ThrottleStatus> mThrottleStatus = new ConcurrentHashMap<>();

    public DataThrottler(int slotIndex, int transportType) {
        mSlotIndex = slotIndex;
@@ -71,16 +71,16 @@ public class DataThrottler {
            retryElapsedTime = RetryManager.NO_SUGGESTED_RETRY_DELAY;
        }

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

            //Extract the least significant bit.
            int apnType = apnTypes & -apnTypes;

            //Update the apn throttle status
            ApnThrottleStatus newStatus = createStatus(apnType, retryElapsedTime, newRequestType);
            ThrottleStatus newStatus = createStatus(apnType, retryElapsedTime, newRequestType);

            ApnThrottleStatus oldStatus = mApnThrottleStatus.get(apnType);
            ThrottleStatus oldStatus = mThrottleStatus.get(apnType);

            //Check to see if there is a change that needs to be applied
            if (!newStatus.equals(oldStatus)) {
@@ -88,7 +88,7 @@ public class DataThrottler {
                changedStatuses.add(newStatus);

                //Put the new status in the temp space
                mApnThrottleStatus.put(apnType, newStatus);
                mThrottleStatus.put(apnType, newStatus);
            }

            //Remove the least significant bit.
@@ -96,7 +96,7 @@ public class DataThrottler {
        }

        if (changedStatuses.size() > 0) {
            sendApnThrottleStatusChanged(changedStatuses);
            sendThrottleStatusChanged(changedStatuses);
        }
    }

@@ -116,9 +116,9 @@ public class DataThrottler {
            apnType &= ~(ApnSetting.TYPE_HIPRI);
        }

        ApnThrottleStatus status = mApnThrottleStatus.get(apnType);
        ThrottleStatus status = mThrottleStatus.get(apnType);
        if (status != null) {
            if (status.getThrottleType() == ApnThrottleStatus.THROTTLE_TYPE_NONE) {
            if (status.getThrottleType() == ThrottleStatus.THROTTLE_TYPE_NONE) {
                return RetryManager.NO_SUGGESTED_RETRY_DELAY;
            } else {
                return status.getThrottleExpiryTimeMillis();
@@ -127,9 +127,9 @@ public class DataThrottler {
        return RetryManager.NO_SUGGESTED_RETRY_DELAY;
    }

    private ApnThrottleStatus createStatus(@Annotation.ApnType int apnType, long retryElapsedTime,
    private ThrottleStatus createStatus(@Annotation.ApnType int apnType, long retryElapsedTime,
            @DcTracker.RequestNetworkType int newRequestType) {
        ApnThrottleStatus.Builder builder = new ApnThrottleStatus.Builder();
        ThrottleStatus.Builder builder = new ThrottleStatus.Builder();

        if (retryElapsedTime == RetryManager.NO_SUGGESTED_RETRY_DELAY) {
            builder
@@ -138,7 +138,7 @@ public class DataThrottler {
        } else if (retryElapsedTime == RetryManager.NO_RETRY) {
            builder
                    .setThrottleExpiryTimeMillis(RetryManager.NO_RETRY)
                    .setRetryType(ApnThrottleStatus.RETRY_TYPE_NONE);
                    .setRetryType(ThrottleStatus.RETRY_TYPE_NONE);
        } else {
            builder
                    .setThrottleExpiryTimeMillis(retryElapsedTime)
@@ -153,21 +153,21 @@ public class DataThrottler {

    private static int getRetryType(@DcTracker.RequestNetworkType int newRequestType) {
        if (newRequestType == DcTracker.REQUEST_TYPE_NORMAL) {
            return ApnThrottleStatus.RETRY_TYPE_NEW_CONNECTION;
            return ThrottleStatus.RETRY_TYPE_NEW_CONNECTION;
        }

        if (newRequestType == DcTracker.REQUEST_TYPE_HANDOVER) {
            return  ApnThrottleStatus.RETRY_TYPE_HANDOVER;
            return  ThrottleStatus.RETRY_TYPE_HANDOVER;
        }

        loge("createStatus: Unknown requestType=" + newRequestType);
        return ApnThrottleStatus.RETRY_TYPE_NEW_CONNECTION;
        return ThrottleStatus.RETRY_TYPE_NEW_CONNECTION;
    }

    private void sendApnThrottleStatusChanged(List<ApnThrottleStatus> statuses) {
    private void sendThrottleStatusChanged(List<ThrottleStatus> statuses) {
        synchronized (mCallbacks) {
            for (int i = 0; i < mCallbacks.size(); i++) {
                mCallbacks.get(i).onApnThrottleStatusChanged(statuses);
                mCallbacks.get(i).onThrottleStatusChanged(statuses);
            }
        }
    }
@@ -183,14 +183,14 @@ public class DataThrottler {
     *
     * @param callback status changes callback
     */
    public void registerForApnThrottleStatusChanges(DataThrottler.Callback callback) {
    public void registerForThrottleStatusChanges(DataThrottler.Callback callback) {
        synchronized (mCallbacks) {
            //Only add if it's not there already
            if (!mCallbacks.contains(callback)) {
                //Report everything the first time
                List<ApnThrottleStatus> apnThrottleStatuses =
                        new ArrayList<>(mApnThrottleStatus.values());
                callback.onApnThrottleStatusChanged(apnThrottleStatuses);
                List<ThrottleStatus> throttleStatuses =
                        new ArrayList<>(mThrottleStatus.values());
                callback.onThrottleStatusChanged(throttleStatuses);
                mCallbacks.add(callback);
            }
        }
@@ -200,7 +200,7 @@ public class DataThrottler {
     * Unregister the callback
     * @param callback the callback to unregister
     */
    public void unregisterForApnThrottleStatusChanges(DataThrottler.Callback callback) {
    public void unregisterForThrottleStatusChanges(DataThrottler.Callback callback) {
        synchronized (mCallbacks) {
            mCallbacks.remove(callback);
        }
@@ -215,8 +215,8 @@ public class DataThrottler {
         *
         * Note: Called with all statuses when first registered.
         *
         * @param apnThrottleStatuses the status changes
         * @param throttleStatuses the status changes
         */
        void onApnThrottleStatusChanged(List<ApnThrottleStatus> apnThrottleStatuses);
        void onThrottleStatusChanged(List<ThrottleStatus> throttleStatuses);
    }
}
+27 −27
Original line number Diff line number Diff line
@@ -25,7 +25,7 @@ import static org.mockito.Mockito.verify;

import android.telephony.AccessNetworkConstants;
import android.telephony.data.ApnSetting;
import android.telephony.data.ApnThrottleStatus;
import android.telephony.data.ThrottleStatus;
import android.test.suitebuilder.annotation.SmallTest;
import android.testing.AndroidTestingRunner;
import android.testing.TestableLooper;
@@ -66,7 +66,7 @@ public class DataThrottlerTest extends TelephonyTest {
    public void setUp() throws Exception {
        super.setUp(getClass().getSimpleName());
        mDataThrottler = new DataThrottler(1, AccessNetworkConstants.TRANSPORT_TYPE_WWAN);
        mDataThrottler.registerForApnThrottleStatusChanges(mMockChangedCallback1);
        mDataThrottler.registerForThrottleStatusChanges(mMockChangedCallback1);
    }

    @After
@@ -80,10 +80,10 @@ public class DataThrottlerTest extends TelephonyTest {
    @Test
    @SmallTest
    public void testSetRetryTime() throws Exception {
        final ArgumentCaptor<List<ApnThrottleStatus>> statusCaptor =
        final ArgumentCaptor<List<ThrottleStatus>> statusCaptor =
                ArgumentCaptor.forClass((Class) List.class);

        List<List<ApnThrottleStatus>> expectedStatuses = new ArrayList<>();
        List<List<ThrottleStatus>> expectedStatuses = new ArrayList<>();
        processAllMessages();
        expectedStatuses.add(List.of());

@@ -96,19 +96,19 @@ public class DataThrottlerTest extends TelephonyTest {

        processAllMessages();
        expectedStatuses.add(List.of(
                new ApnThrottleStatus.Builder()
                new ThrottleStatus.Builder()
                        .setSlotIndex(1)
                        .setTransportType(AccessNetworkConstants.TRANSPORT_TYPE_WWAN)
                        .setApnType(ApnSetting.TYPE_HIPRI)
                        .setThrottleExpiryTimeMillis(1234567890L)
                        .setRetryType(ApnThrottleStatus.RETRY_TYPE_NEW_CONNECTION)
                        .setRetryType(ThrottleStatus.RETRY_TYPE_NEW_CONNECTION)
                        .build(),
                new ApnThrottleStatus.Builder()
                new ThrottleStatus.Builder()
                    .setSlotIndex(1)
                    .setTransportType(AccessNetworkConstants.TRANSPORT_TYPE_WWAN)
                    .setApnType(DEFAULT_APN_TYPE)
                    .setThrottleExpiryTimeMillis(1234567890L)
                    .setRetryType(ApnThrottleStatus.RETRY_TYPE_NEW_CONNECTION)
                    .setRetryType(ThrottleStatus.RETRY_TYPE_NEW_CONNECTION)
                    .build())
        );

@@ -120,26 +120,26 @@ public class DataThrottlerTest extends TelephonyTest {

        processAllMessages();
        expectedStatuses.add(List.of(
                new ApnThrottleStatus.Builder()
                new ThrottleStatus.Builder()
                        .setSlotIndex(1)
                        .setTransportType(AccessNetworkConstants.TRANSPORT_TYPE_WWAN)
                        .setApnType(ApnSetting.TYPE_HIPRI)
                        .setThrottleExpiryTimeMillis(13579L)
                        .setRetryType(ApnThrottleStatus.RETRY_TYPE_HANDOVER)
                        .setRetryType(ThrottleStatus.RETRY_TYPE_HANDOVER)
                        .build(),
                new ApnThrottleStatus.Builder()
                new ThrottleStatus.Builder()
                        .setSlotIndex(1)
                        .setTransportType(AccessNetworkConstants.TRANSPORT_TYPE_WWAN)
                        .setApnType(ApnSetting.TYPE_DUN)
                        .setThrottleExpiryTimeMillis(13579L)
                        .setRetryType(ApnThrottleStatus.RETRY_TYPE_HANDOVER)
                        .setRetryType(ThrottleStatus.RETRY_TYPE_HANDOVER)
                        .build(),
                new ApnThrottleStatus.Builder()
                new ThrottleStatus.Builder()
                        .setSlotIndex(1)
                        .setTransportType(AccessNetworkConstants.TRANSPORT_TYPE_WWAN)
                        .setApnType(DEFAULT_APN_TYPE)
                        .setThrottleExpiryTimeMillis(13579L)
                        .setRetryType(ApnThrottleStatus.RETRY_TYPE_HANDOVER)
                        .setRetryType(ThrottleStatus.RETRY_TYPE_HANDOVER)
                        .build())
        );

@@ -150,12 +150,12 @@ public class DataThrottlerTest extends TelephonyTest {
                mDataThrottler.getRetryTime(ApnSetting.TYPE_MMS));
        processAllMessages();
        expectedStatuses.add(List.of(
                new ApnThrottleStatus.Builder()
                new ThrottleStatus.Builder()
                        .setSlotIndex(1)
                        .setTransportType(AccessNetworkConstants.TRANSPORT_TYPE_WWAN)
                        .setNoThrottle()
                        .setApnType(ApnSetting.TYPE_MMS)
                        .setRetryType(ApnThrottleStatus.RETRY_TYPE_NEW_CONNECTION)
                        .setRetryType(ThrottleStatus.RETRY_TYPE_NEW_CONNECTION)
                        .build()
        ));

@@ -164,19 +164,19 @@ public class DataThrottlerTest extends TelephonyTest {

        processAllMessages();
        expectedStatuses.add(List.of(
                new ApnThrottleStatus.Builder()
                new ThrottleStatus.Builder()
                        .setSlotIndex(1)
                        .setTransportType(AccessNetworkConstants.TRANSPORT_TYPE_WWAN)
                        .setApnType(ApnSetting.TYPE_EMERGENCY)
                        .setThrottleExpiryTimeMillis(RetryManager.NO_RETRY)
                        .setRetryType(ApnThrottleStatus.RETRY_TYPE_NONE)
                        .setRetryType(ThrottleStatus.RETRY_TYPE_NONE)
                        .build(),
                new ApnThrottleStatus.Builder()
                new ThrottleStatus.Builder()
                        .setSlotIndex(1)
                        .setTransportType(AccessNetworkConstants.TRANSPORT_TYPE_WWAN)
                        .setApnType(ApnSetting.TYPE_FOTA)
                        .setThrottleExpiryTimeMillis(RetryManager.NO_RETRY)
                        .setRetryType(ApnThrottleStatus.RETRY_TYPE_NONE)
                        .setRetryType(ThrottleStatus.RETRY_TYPE_NONE)
                        .build()
        ));

@@ -186,11 +186,11 @@ public class DataThrottlerTest extends TelephonyTest {

        // Loop through statuses and test everything
        verify(mMockChangedCallback1, times(expectedStatuses.size()))
                .onApnThrottleStatusChanged(statusCaptor.capture());
                .onThrottleStatusChanged(statusCaptor.capture());

        // Check actual statuses
        List<List<ApnThrottleStatus>> actualStatuses =
                (List<List<ApnThrottleStatus>>) statusCaptor.getAllValues();
        List<List<ThrottleStatus>> actualStatuses =
                (List<List<ThrottleStatus>>) statusCaptor.getAllValues();
        assertEquals(expectedStatuses.size(), actualStatuses.size());

        if (DBG) {
@@ -198,12 +198,12 @@ public class DataThrottlerTest extends TelephonyTest {
            logd("actualStatuses.size() = " + actualStatuses.size());
        }

        Comparator<ApnThrottleStatus> comparator = (o1, o2) ->
        Comparator<ThrottleStatus> comparator = (o1, o2) ->
                Integer.compare(o1.getApnType(), o2.getApnType());

        for (int i = 0; i < expectedStatuses.size(); i++) {
            List<ApnThrottleStatus> atsExpected = new ArrayList<>(expectedStatuses.get(i));
            List<ApnThrottleStatus> atsActual = new ArrayList<>(actualStatuses.get(i));
            List<ThrottleStatus> atsExpected = new ArrayList<>(expectedStatuses.get(i));
            List<ThrottleStatus> atsActual = new ArrayList<>(actualStatuses.get(i));

            atsExpected.sort(comparator);
            atsActual.sort(comparator);
@@ -211,6 +211,6 @@ public class DataThrottlerTest extends TelephonyTest {
                    atsExpected, atsActual);
        }

        this.mDataThrottler.registerForApnThrottleStatusChanges(mMockChangedCallback2);
        this.mDataThrottler.registerForThrottleStatusChanges(mMockChangedCallback2);
    }
}