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

Commit dae587b5 authored by Wei Huang's avatar Wei Huang Committed by Jack Yu
Browse files

Fix : Reconnection not triggered when APN changed

When APN is changed, connections whose ApnSetting change will be cleaned
up. However, as ApnSetting#equals doesn't check mmsPort, username and
password, connection will not be cleaned up even if user changes them.
To fix the issue, add logic to check them and also introduced test case
to prevent same failure in the future.

Bug: 30207789
Test: Telephony unit test
Change-Id: I4ac75ebac1755a42c4e88da60b059874ea9f693c
parent 223d561c
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -486,7 +486,10 @@ public class ApnSetting {
                proxy.equals(other.proxy) &&
                mmsc.equals(other.mmsc) &&
                mmsProxy.equals(other.mmsProxy) &&
                TextUtils.equals(mmsPort, other.mmsPort) &&
                port.equals(other.port) &&
                TextUtils.equals(user, other.user) &&
                TextUtils.equals(password, other.password) &&
                authType == other.authType &&
                Arrays.deepEquals(types, other.types) &&
                protocol.equals(other.protocol) &&
+40 −1
Original line number Diff line number Diff line
@@ -28,6 +28,8 @@ import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.List;

@@ -39,6 +41,7 @@ import static com.android.internal.telephony.PhoneConstants.APN_TYPE_MMS;
import static com.android.internal.telephony.PhoneConstants.APN_TYPE_SUPL;
import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertTrue;
import static junit.framework.Assert.fail;
import static org.junit.Assert.assertEquals;


@@ -526,7 +529,6 @@ public class ApnSettingTest extends TelephonyTest {
        assertTrue(createApnSetting(
                new String[]{PhoneConstants.APN_TYPE_IA, PhoneConstants.APN_TYPE_DUN}).
                isMetered(mContext, 4, isRoaming));

    }

    @Test
@@ -588,4 +590,41 @@ public class ApnSettingTest extends TelephonyTest {
                {APN_TYPE_DEFAULT, APN_TYPE_MMS, APN_TYPE_IA}).
                canHandleType(APN_TYPE_IA));
    }

    @Test
    @SmallTest
    public void testEquals() throws Exception {
        final int dummyInt = 1;
        final String dummyString = "dummy";
        final String[] dummyStringArr = new String[] {"dummy"};
        // base apn
        ApnSetting baseApn = createApnSetting(new String[] {"mms", "default"});
        Field[] fields = ApnSetting.class.getDeclaredFields();
        for (Field f : fields) {
            int modifiers = f.getModifiers();
            if (Modifier.isStatic(modifiers) || !Modifier.isFinal(modifiers)) {
                continue;
            }
            f.setAccessible(true);
            ApnSetting testApn = null;
            if (int.class.equals(f.getType())) {
                testApn = new ApnSetting(baseApn);
                f.setInt(testApn, dummyInt + f.getInt(testApn));
            } else if (boolean.class.equals(f.getType())) {
                testApn = new ApnSetting(baseApn);
                f.setBoolean(testApn, !f.getBoolean(testApn));
            } else if (String.class.equals(f.getType())) {
                testApn = new ApnSetting(baseApn);
                f.set(testApn, dummyString);
            } else if (String[].class.equals(f.getType())) {
                testApn = new ApnSetting(baseApn);
                f.set(testApn, dummyStringArr);
            } else {
                fail("Unsupported field:" + f.getName());
            }
            if (testApn != null) {
                assertFalse(f.getName() + " is NOT checked", testApn.equals(baseApn));
            }
        }
    }
}