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

Commit a5e1b0f3 authored by Jack Yu's avatar Jack Yu Committed by Automerger Merge Worker
Browse files

Merge changes Id354c362,I96d5f7f7 am: 6ffe0b1b

Original change: https://android-review.googlesource.com/c/platform/frameworks/opt/telephony/+/1764009

Change-Id: I350c7ecabde03fe435d68fdc45f686df5ba537a9
parents 0628106c 6ffe0b1b
Loading
Loading
Loading
Loading
+14 −2
Original line number Original line Diff line number Diff line
@@ -16,6 +16,8 @@


package com.android.internal.telephony.dataconnection;
package com.android.internal.telephony.dataconnection;


import com.android.internal.annotations.VisibleForTesting;

import java.util.HashSet;
import java.util.HashSet;


/**
/**
@@ -70,7 +72,14 @@ public class DataConnectionReasons {
        return mDataDisallowedReasonSet.size() == 0;
        return mDataDisallowedReasonSet.size() == 0;
    }
    }


    boolean contains(DataDisallowedReasonType reason) {
    /**
     * Check if it contains a certain disallowed reason.
     *
     * @param reason The disallowed reason to check.
     * @return {@code true} if the provided reason matches one of the disallowed reasons.
     */
    @VisibleForTesting
    public boolean contains(DataDisallowedReasonType reason) {
        return mDataDisallowedReasonSet.contains(reason);
        return mDataDisallowedReasonSet.contains(reason);
    }
    }


@@ -137,7 +146,10 @@ public class DataConnectionReasons {
        DATA_SERVICE_NOT_READY(true),
        DATA_SERVICE_NOT_READY(true),
        // Qualified networks service does not allow certain types of APN brought up on either
        // Qualified networks service does not allow certain types of APN brought up on either
        // cellular or IWLAN.
        // cellular or IWLAN.
        DISABLED_BY_QNS(true);
        DISABLED_BY_QNS(true),
        // Data is throttled. The network explicitly requested device not to establish data
        // connection for a certain period.
        DATA_THROTTLED(true);


        private boolean mIsHardReason;
        private boolean mIsHardReason;


+6 −0
Original line number Original line Diff line number Diff line
@@ -1457,6 +1457,12 @@ public class DcTracker extends Handler {
                    apnContext.getApnTypeBitmask()) && requestType != REQUEST_TYPE_HANDOVER) {
                    apnContext.getApnTypeBitmask()) && requestType != REQUEST_TYPE_HANDOVER) {
                reasons.add(DataDisallowedReasonType.ON_OTHER_TRANSPORT);
                reasons.add(DataDisallowedReasonType.ON_OTHER_TRANSPORT);
            }
            }

            // Check if the device is under data throttling.
            long retryTime = mDataThrottler.getRetryTime(apnContext.getApnTypeBitmask());
            if (retryTime > SystemClock.elapsedRealtime()) {
                reasons.add(DataDisallowedReasonType.DATA_THROTTLED);
            }
        }
        }


        boolean isDataEnabled = apnContext == null ? mDataEnabledSettings.isDataEnabled()
        boolean isDataEnabled = apnContext == null ? mDataEnabledSettings.isDataEnabled()
+32 −21
Original line number Original line Diff line number Diff line
@@ -63,6 +63,7 @@ import android.os.HandlerThread;
import android.os.IBinder;
import android.os.IBinder;
import android.os.Message;
import android.os.Message;
import android.os.PersistableBundle;
import android.os.PersistableBundle;
import android.os.SystemClock;
import android.provider.Settings;
import android.provider.Settings;
import android.provider.Telephony;
import android.provider.Telephony;
import android.telephony.AccessNetworkConstants;
import android.telephony.AccessNetworkConstants;
@@ -97,6 +98,7 @@ import com.android.internal.telephony.ISub;
import com.android.internal.telephony.PhoneConstants;
import com.android.internal.telephony.PhoneConstants;
import com.android.internal.telephony.RetryManager;
import com.android.internal.telephony.RetryManager;
import com.android.internal.telephony.TelephonyTest;
import com.android.internal.telephony.TelephonyTest;
import com.android.internal.telephony.dataconnection.DataConnectionReasons.DataDisallowedReasonType;


import org.junit.After;
import org.junit.After;
import org.junit.Before;
import org.junit.Before;
@@ -800,18 +802,6 @@ public class DcTrackerTest extends TelephonyTest {
        assertEquals(FAKE_GATEWAY, linkProperties.getRoutes().get(0).getGateway().getHostAddress());
        assertEquals(FAKE_GATEWAY, linkProperties.getRoutes().get(0).getGateway().getHostAddress());
    }
    }


    private boolean isDataAllowed(DataConnectionReasons dataConnectionReasons) {
        try {
            Method method = DcTracker.class.getDeclaredMethod("isDataAllowed",
                    DataConnectionReasons.class);
            method.setAccessible(true);
            return (boolean) method.invoke(mDct, dataConnectionReasons);
        } catch (Exception e) {
            fail(e.toString());
            return false;
        }
    }

    private boolean isHandoverPending(int apnType) {
    private boolean isHandoverPending(int apnType) {
        try {
        try {
            Method method = DcTracker.class.getDeclaredMethod("isHandoverPending",
            Method method = DcTracker.class.getDeclaredMethod("isHandoverPending",
@@ -881,7 +871,7 @@ public class DcTrackerTest extends TelephonyTest {
    @MediumTest
    @MediumTest
    public void testDataSetup() throws Exception {
    public void testDataSetup() throws Exception {
        DataConnectionReasons dataConnectionReasons = new DataConnectionReasons();
        DataConnectionReasons dataConnectionReasons = new DataConnectionReasons();
        boolean allowed = isDataAllowed(dataConnectionReasons);
        boolean allowed = mDct.isDataAllowed(dataConnectionReasons);
        assertFalse(dataConnectionReasons.toString(), allowed);
        assertFalse(dataConnectionReasons.toString(), allowed);


        logd("Sending EVENT_ENABLE_APN");
        logd("Sending EVENT_ENABLE_APN");
@@ -892,7 +882,7 @@ public class DcTrackerTest extends TelephonyTest {
        sendInitializationEvents();
        sendInitializationEvents();


        dataConnectionReasons = new DataConnectionReasons();
        dataConnectionReasons = new DataConnectionReasons();
        allowed = isDataAllowed(dataConnectionReasons);
        allowed = mDct.isDataAllowed(dataConnectionReasons);
        assertTrue(dataConnectionReasons.toString(), allowed);
        assertTrue(dataConnectionReasons.toString(), allowed);


        ArgumentCaptor<DataProfile> dpCaptor = ArgumentCaptor.forClass(DataProfile.class);
        ArgumentCaptor<DataProfile> dpCaptor = ArgumentCaptor.forClass(DataProfile.class);
@@ -923,7 +913,7 @@ public class DcTrackerTest extends TelephonyTest {
        mSimulatedCommands.setDataCallResult(true, result);
        mSimulatedCommands.setDataCallResult(true, result);


        DataConnectionReasons dataConnectionReasons = new DataConnectionReasons();
        DataConnectionReasons dataConnectionReasons = new DataConnectionReasons();
        boolean allowed = isDataAllowed(dataConnectionReasons);
        boolean allowed = mDct.isDataAllowed(dataConnectionReasons);
        assertFalse(dataConnectionReasons.toString(), allowed);
        assertFalse(dataConnectionReasons.toString(), allowed);


        logd("Sending EVENT_ENABLE_APN");
        logd("Sending EVENT_ENABLE_APN");
@@ -934,7 +924,7 @@ public class DcTrackerTest extends TelephonyTest {
        sendInitializationEvents();
        sendInitializationEvents();


        dataConnectionReasons = new DataConnectionReasons();
        dataConnectionReasons = new DataConnectionReasons();
        allowed = isDataAllowed(dataConnectionReasons);
        allowed = mDct.isDataAllowed(dataConnectionReasons);
        assertTrue(dataConnectionReasons.toString(), allowed);
        assertTrue(dataConnectionReasons.toString(), allowed);


        ArgumentCaptor<DataProfile> dpCaptor = ArgumentCaptor.forClass(DataProfile.class);
        ArgumentCaptor<DataProfile> dpCaptor = ArgumentCaptor.forClass(DataProfile.class);
@@ -2734,7 +2724,7 @@ public class DcTrackerTest extends TelephonyTest {
    @Test
    @Test
    public void testRatChanged() throws Exception {
    public void testRatChanged() throws Exception {
        DataConnectionReasons dataConnectionReasons = new DataConnectionReasons();
        DataConnectionReasons dataConnectionReasons = new DataConnectionReasons();
        boolean allowed = isDataAllowed(dataConnectionReasons);
        boolean allowed = mDct.isDataAllowed(dataConnectionReasons);
        assertFalse(dataConnectionReasons.toString(), allowed);
        assertFalse(dataConnectionReasons.toString(), allowed);


        logd("Sending EVENT_ENABLE_APN");
        logd("Sending EVENT_ENABLE_APN");
@@ -2744,7 +2734,7 @@ public class DcTrackerTest extends TelephonyTest {
        sendInitializationEvents();
        sendInitializationEvents();


        dataConnectionReasons = new DataConnectionReasons();
        dataConnectionReasons = new DataConnectionReasons();
        allowed = isDataAllowed(dataConnectionReasons);
        allowed = mDct.isDataAllowed(dataConnectionReasons);
        assertTrue(dataConnectionReasons.toString(), allowed);
        assertTrue(dataConnectionReasons.toString(), allowed);


        ArgumentCaptor<DataProfile> dpCaptor = ArgumentCaptor.forClass(DataProfile.class);
        ArgumentCaptor<DataProfile> dpCaptor = ArgumentCaptor.forClass(DataProfile.class);
@@ -2872,15 +2862,15 @@ public class DcTrackerTest extends TelephonyTest {


    @Test
    @Test
    public void testDataUnthrottled() throws Exception {
    public void testDataUnthrottled() throws Exception {
        DataThrottler mockedDataThrottler = Mockito.mock(DataThrottler.class);
        initApns(ApnSetting.TYPE_IMS_STRING, new String[]{ApnSetting.TYPE_IMS_STRING});
        replaceInstance(DcTracker.class, "mDataThrottler", mDct, mockedDataThrottler);
        replaceInstance(DcTracker.class, "mDataThrottler", mDct, mDataThrottler);
        mDct.enableApn(ApnSetting.TYPE_IMS, DcTracker.REQUEST_TYPE_NORMAL, null);
        mDct.enableApn(ApnSetting.TYPE_IMS, DcTracker.REQUEST_TYPE_NORMAL, null);
        sendInitializationEvents();
        sendInitializationEvents();
        mDct.sendMessage(mDct.obtainMessage(DctConstants.EVENT_APN_UNTHROTTLED,
        mDct.sendMessage(mDct.obtainMessage(DctConstants.EVENT_APN_UNTHROTTLED,
                new AsyncResult(null, FAKE_APN3, null)));
                new AsyncResult(null, FAKE_APN3, null)));
        waitForLastHandlerAction(mDcTrackerTestHandler.getThreadHandler());
        waitForLastHandlerAction(mDcTrackerTestHandler.getThreadHandler());


        verify(mockedDataThrottler).setRetryTime(
        verify(mDataThrottler).setRetryTime(
                eq(ApnSetting.TYPE_IMS),
                eq(ApnSetting.TYPE_IMS),
                eq(RetryManager.NO_SUGGESTED_RETRY_DELAY),
                eq(RetryManager.NO_SUGGESTED_RETRY_DELAY),
                eq(DcTracker.REQUEST_TYPE_NORMAL));
                eq(DcTracker.REQUEST_TYPE_NORMAL));
@@ -2911,6 +2901,27 @@ public class DcTrackerTest extends TelephonyTest {
        assertTrue(msgs.get(ApnSetting.TYPE_IMS).contains(msg));
        assertTrue(msgs.get(ApnSetting.TYPE_IMS).contains(msg));
    }
    }


    @Test
    public void testDataThrottledNotAllowData() throws Exception {
        initApns(ApnSetting.TYPE_IMS_STRING, new String[]{ApnSetting.TYPE_IMS_STRING});
        replaceInstance(DcTracker.class, "mDataThrottler", mDct, mDataThrottler);
        doReturn(SystemClock.elapsedRealtime() + 100000).when(mDataThrottler)
                .getRetryTime(ApnSetting.TYPE_IMS);
        mDct.enableApn(ApnSetting.TYPE_IMS, DcTracker.REQUEST_TYPE_NORMAL, null);
        sendInitializationEvents();

        DataConnectionReasons dataConnectionReasons = new DataConnectionReasons();
        boolean allowed = mDct.isDataAllowed(mApnContext, DcTracker.REQUEST_TYPE_NORMAL,
                dataConnectionReasons);
        assertFalse(dataConnectionReasons.toString(), allowed);
        assertTrue(dataConnectionReasons.contains(DataDisallowedReasonType.DATA_THROTTLED));

        // Makre sure no data setup request
        verify(mSimulatedCommandsVerifier, never()).setupDataCall(
                anyInt(), any(DataProfile.class), anyBoolean(), anyBoolean(), anyInt(), any(),
                anyInt(), any(), any(), anyBoolean(), any(Message.class));
    }

    @Test
    @Test
    public void testNotifyDataDisconnected() {
    public void testNotifyDataDisconnected() {
        // Verify notify data disconnected on DCT constructor, initialized in setUp()
        // Verify notify data disconnected on DCT constructor, initialized in setUp()