From 3c4e929cfdfe5573e1be3ee0331fc6029e45c382 Mon Sep 17 00:00:00 2001 From: Lorenzo Colitti Date: Wed, 29 Dec 2010 09:55:29 -0800 Subject: Add a protocol property to the APNs and use it. 1. Database changes: - Add a protocol and a roaming_protocol column to the carriers table in the telephony provider database. - Set the protocol and roaming_protocol fields when creating APN objects from the database. 2. ApnSetting class changes: - Add protocol and roamingProtocol fields to the ApnSetting class that encapsulates APN settings within the framework. - Add the fields to ApnSetting.toString and support a new syntax containing the fields in ApnSetting.fromString. - Add a unit test for ApnSetting. 3. Telephony changes: - Specify the APN protocol when setting up a data call, using protocol when not roaming and roaming_protocol when roaming. This change depends on #86896 in the telephony provider, which adds the new column to the database schema on upgrades. Bug: 3333633 Change-Id: If3d9ed4c851d0192849df0d64581db03b066e052 --- .../internal/telephony/gsm/ApnSettingTest.java | 108 +++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 telephony/tests/telephonytests/src/com/android/internal/telephony/gsm/ApnSettingTest.java (limited to 'telephony/tests') diff --git a/telephony/tests/telephonytests/src/com/android/internal/telephony/gsm/ApnSettingTest.java b/telephony/tests/telephonytests/src/com/android/internal/telephony/gsm/ApnSettingTest.java new file mode 100644 index 0000000..15cb3b8 --- /dev/null +++ b/telephony/tests/telephonytests/src/com/android/internal/telephony/gsm/ApnSettingTest.java @@ -0,0 +1,108 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.internal.telephony.gsm; + +import junit.framework.TestCase; + +import android.test.suitebuilder.annotation.SmallTest; + +public class ApnSettingTest extends TestCase { + + public static final String[] TYPES = {"default", "*"}; + + public static void assertApnSettingEqual(ApnSetting a1, ApnSetting a2) { + assertEquals(a1.carrier, a2.carrier); + assertEquals(a1.apn, a2.apn); + assertEquals(a1.proxy, a2.proxy); + assertEquals(a1.port, a2.port); + assertEquals(a1.mmsc, a2.mmsc); + assertEquals(a1.mmsProxy, a2.mmsProxy); + assertEquals(a1.mmsPort, a2.mmsPort); + assertEquals(a1.user, a2.user); + assertEquals(a1.password, a2.password); + assertEquals(a1.authType, a2.authType); + assertEquals(a1.id, a2.id); + assertEquals(a1.numeric, a2.numeric); + assertEquals(a1.protocol, a2.protocol); + assertEquals(a1.roamingProtocol, a2.roamingProtocol); + assertEquals(a1.types.length, a2.types.length); + int i; + for (i = 0; i < a1.types.length; i++) { + assertEquals(a1.types[i], a2.types[i]); + } + } + + @SmallTest + public void testFromString() throws Exception { + String[] dunTypes = {"DUN"}; + String[] mmsTypes = {"mms", "*"}; + + ApnSetting expected_apn; + String testString; + + // A real-world v1 example string. + testString = "Vodafone IT,web.omnitel.it,,,,,,,,,222,10,,DUN"; + expected_apn = new ApnSetting( + -1, "22210", "Vodafone IT", "web.omnitel.it", "", "", + "", "", "", "", "", 0, dunTypes, "IP", "IP"); + assertApnSettingEqual(expected_apn, ApnSetting.fromString(testString)); + + // A v2 string. + testString = "[ApnSettingV2] Name,apn,,,,,,,,,123,45,,mms|*,IPV6,IP"; + expected_apn = new ApnSetting( + -1, "12345", "Name", "apn", "", "", + "", "", "", "", "", 0, mmsTypes, "IPV6", "IP"); + assertApnSettingEqual(expected_apn, ApnSetting.fromString(testString)); + + // A v2 string with spaces. + testString = "[ApnSettingV2] Name,apn, ,,,,,,,,123,45,,mms|*,IPV4V6, IP"; + expected_apn = new ApnSetting( + -1, "12345", "Name", "apn", "", "", + "", "", "", "", "", 0, mmsTypes, "IPV4V6", "IP"); + assertApnSettingEqual(expected_apn, ApnSetting.fromString(testString)); + + // Return null if insufficient fields given. + testString = "[ApnSettingV2] Name,apn,,,,,,,,,123, 45,,mms|*"; + assertEquals(null, ApnSetting.fromString(testString)); + + testString = "Name,apn,,,,,,,,,123, 45,"; + assertEquals(null, ApnSetting.fromString(testString)); + + // Parse (incorrect) V2 format without the tag as V1. + testString = "Name,apn,,,,,,,,,123, 45,,mms|*,IPV6"; + String[] incorrectTypes = {"mms|*", "IPV6"}; + expected_apn = new ApnSetting( + -1, "12345", "Name", "apn", "", "", + "", "", "", "", "", 0, incorrectTypes, "IP", "IP"); + assertApnSettingEqual(expected_apn, ApnSetting.fromString(testString)); + } + + + @SmallTest + public void testToString() throws Exception { + String[] types = {"default", "*"}; + ApnSetting apn = new ApnSetting( + 99, "12345", "Name", "apn", "proxy", "port", + "mmsc", "mmsproxy", "mmsport", "user", "password", 0, + types, "IPV4V6", "IP"); + String expected = "[ApnSettingV2] Name, 99, 12345, apn, proxy, " + + "mmsc, mmsproxy, mmsport, port, 0, default | *, " + + "IPV4V6, IP"; + assertEquals(expected, apn.toString()); + } +} + -- cgit v1.1