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

Commit b2ce2c5b 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 tests
Merged-In: I4ac75ebac1755a42c4e88da60b059874ea9f693c
Change-Id: I4ac75ebac1755a42c4e88da60b059874ea9f693c
parent d13c5261
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -505,7 +505,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) &&
+41 −1
Original line number Diff line number Diff line
@@ -28,11 +28,14 @@ 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;

import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertTrue;
import static junit.framework.Assert.fail;
import static org.junit.Assert.assertEquals;

public class ApnSettingTest extends TelephonyTest {
@@ -495,4 +498,41 @@ public class ApnSettingTest extends TelephonyTest {
                isMetered(mContext, 4, isRoaming));

    }

    @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));
            }
        }
    }
}