Merge "Get carrier_id attribute in apns-full-conf.xml"
diff --git a/src/com/android/providers/telephony/CarrierIdProvider.java b/src/com/android/providers/telephony/CarrierIdProvider.java
index 6dfa07b..472f0e1 100644
--- a/src/com/android/providers/telephony/CarrierIdProvider.java
+++ b/src/com/android/providers/telephony/CarrierIdProvider.java
@@ -645,8 +645,6 @@
row.add(mCurrentSubscriptionMap.get(subId).get(CarrierId.CARRIER_ID));
} else if (CarrierId.CARRIER_NAME.equals(columnName)) {
row.add(mCurrentSubscriptionMap.get(subId).get(CarrierId.CARRIER_NAME));
- } else if (CarrierId.MNO_CARRIER_ID.equals(columnName)) {
- row.add(mCurrentSubscriptionMap.get(subId).get(CarrierId.MNO_CARRIER_ID));
} else {
throw new IllegalArgumentException("Invalid column " + projectionIn[i]);
}
diff --git a/src/com/android/providers/telephony/TelephonyBackupAgent.java b/src/com/android/providers/telephony/TelephonyBackupAgent.java
index 5f6eb10..3db1088 100644
--- a/src/com/android/providers/telephony/TelephonyBackupAgent.java
+++ b/src/com/android/providers/telephony/TelephonyBackupAgent.java
@@ -1155,8 +1155,12 @@
values.put(Telephony.Mms.Part.NAME, srcName);
values.put(Telephony.Mms.Part.CONTENT_ID, "<"+srcName+">");
values.put(Telephony.Mms.Part.CONTENT_LOCATION, srcName);
- values.put(Telephony.Mms.Part.CHARSET, mms.body.charSet);
- values.put(Telephony.Mms.Part.TEXT, mms.body.text);
+
+ values.put(
+ Telephony.Mms.Part.CHARSET,
+ mms.body == null ? CharacterSets.DEFAULT_CHARSET : mms.body.charSet);
+ values.put(Telephony.Mms.Part.TEXT, mms.body == null ? "" : mms.body.text);
+
if (mContentResolver.insert(partUri, values) == null) {
if (DEBUG) {
Log.e(TAG, "Could not insert body part");
diff --git a/src/com/android/providers/telephony/TelephonyProvider.java b/src/com/android/providers/telephony/TelephonyProvider.java
index 8b22bf1..93f513d 100644
--- a/src/com/android/providers/telephony/TelephonyProvider.java
+++ b/src/com/android/providers/telephony/TelephonyProvider.java
@@ -143,7 +143,7 @@
private static final boolean DBG = true;
private static final boolean VDBG = false; // STOPSHIP if true
- private static final int DATABASE_VERSION = 32 << 16;
+ private static final int DATABASE_VERSION = 33 << 16;
private static final int URL_UNKNOWN = 0;
private static final int URL_TELEPHONY = 1;
private static final int URL_CURRENT = 2;
@@ -170,6 +170,8 @@
private static final int URL_SIM_APN_LIST = 23;
private static final int URL_SIM_APN_LIST_ID = 24;
private static final int URL_FILTERED_USING_SUBID = 25;
+ private static final int URL_SIM_APN_LIST_FILTERED = 26;
+ private static final int URL_SIM_APN_LIST_FILTERED_ID = 27;
private static final String TAG = "TelephonyProvider";
private static final String CARRIERS_TABLE = "carriers";
@@ -383,7 +385,8 @@
+ SubscriptionManager.IS_OPPORTUNISTIC + " INTEGER DEFAULT 0,"
+ SubscriptionManager.GROUP_UUID + " TEXT,"
+ SubscriptionManager.IS_METERED + " INTEGER DEFAULT 1,"
- + SubscriptionManager.ISO_COUNTRY_CODE + " TEXT"
+ + SubscriptionManager.ISO_COUNTRY_CODE + " TEXT,"
+ + SubscriptionManager.CARRIER_ID + " INTEGER DEFAULT -1"
+ ");";
}
@@ -428,6 +431,10 @@
s_urlMatcher.addURI("telephony", "carriers/enforce_managed", URL_ENFORCE_MANAGED);
s_urlMatcher.addURI("telephony", "carriers/sim_apn_list", URL_SIM_APN_LIST);
s_urlMatcher.addURI("telephony", "carriers/sim_apn_list/#", URL_SIM_APN_LIST_ID);
+ s_urlMatcher.addURI("telephony", "carriers/sim_apn_list/filtered",
+ URL_SIM_APN_LIST_FILTERED);
+ s_urlMatcher.addURI("telephony", "carriers/sim_apn_list/filtered/subId/*",
+ URL_SIM_APN_LIST_FILTERED_ID);
s_currentNullMap = new ContentValues(1);
s_currentNullMap.put(CURRENT, "0");
@@ -1192,6 +1199,20 @@
oldVersion = 32 << 16 | 6;
}
+ if (oldVersion < (33 << 16 | 6)) {
+ try {
+ // Try to update the siminfo table. It might not be there.
+ db.execSQL("ALTER TABLE " + SIMINFO_TABLE + " ADD COLUMN "
+ + SubscriptionManager.CARRIER_ID + " INTEGER DEFAULT -1;");
+ } catch (SQLiteException e) {
+ if (DBG) {
+ log("onUpgrade skipping " + SIMINFO_TABLE + " upgrade. " +
+ "The table will get created in onOpen.");
+ }
+ }
+ oldVersion = 33 << 16 | 6;
+ }
+
if (DBG) {
log("dbh.onUpgrade:- db=" + db + " oldV=" + oldVersion + " newV=" + newVersion);
}
@@ -2709,10 +2730,12 @@
case URL_FILTERED_USING_SUBID: {
String idString = url.getLastPathSegment();
if (match == URL_FILTERED_ID) {
- qb.appendWhere("_id = " + idString);
+ constraints.add("_id = " + idString);
} else {
try {
subId = Integer.parseInt(idString);
+ // TODO b/74213956 turn this back on once insertion includes correct sub id
+ // constraints.add(SUBSCRIPTION_ID + "=" + subIdString);
} catch (NumberFormatException e) {
loge("NumberFormatException" + e);
return null;
@@ -2723,13 +2746,12 @@
case URL_FILTERED: {
if (isManagedApnEnforced()) {
// If enforced, return DPC records only.
- qb.appendWhereStandalone(IS_OWNED_BY_DPC);
+ constraints.add(IS_OWNED_BY_DPC);
} else {
// Otherwise return non-DPC records only.
- qb.appendWhereStandalone(IS_NOT_OWNED_BY_DPC);
+ constraints.add(IS_NOT_OWNED_BY_DPC);
}
- return getSubscriptionMatchingAPNList(qb, projectionIn, selection, selectionArgs,
- sort, subId);
+ break;
}
case URL_ENFORCE_MANAGED: {
@@ -2760,6 +2782,28 @@
sort, subId);
}
+ case URL_SIM_APN_LIST_FILTERED_ID: {
+ subIdString = url.getLastPathSegment();
+ try {
+ subId = Integer.parseInt(subIdString);
+ } catch (NumberFormatException e) {
+ loge("NumberFormatException" + e);
+ return null;
+ }
+ }
+ //intentional fall through from above case
+ case URL_SIM_APN_LIST_FILTERED: {
+ if (isManagedApnEnforced()) {
+ // If enforced, return DPC records only.
+ qb.appendWhereStandalone(IS_OWNED_BY_DPC);
+ } else {
+ // Otherwise return non-DPC records only.
+ qb.appendWhereStandalone(IS_NOT_OWNED_BY_DPC);
+ }
+ return getSubscriptionMatchingAPNList(qb, projectionIn, selection, selectionArgs,
+ sort, subId);
+ }
+
default: {
return null;
}
@@ -2859,7 +2903,12 @@
int mvnoIndex = ret.getColumnIndex(MVNO_TYPE);
int mvnoDataIndex = ret.getColumnIndex(MVNO_MATCH_DATA);
- IccRecords iccRecords = getIccRecords(subId);
+ IccRecords iccRecords = UiccController.getInstance().getIccRecords(
+ SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
+ if (iccRecords == null) {
+ loge("iccRecords is null");
+ return null;
+ }
//Separate the result into MatrixCursor
while (ret.moveToNext()) {
diff --git a/tests/src/com/android/providers/telephony/TelephonyBackupAgentTest.java b/tests/src/com/android/providers/telephony/TelephonyBackupAgentTest.java
index 49106ee..37cf6e3 100644
--- a/tests/src/com/android/providers/telephony/TelephonyBackupAgentTest.java
+++ b/tests/src/com/android/providers/telephony/TelephonyBackupAgentTest.java
@@ -40,6 +40,8 @@
import android.util.Log;
import android.util.SparseArray;
+import com.google.android.mms.pdu.CharacterSets;
+
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
@@ -74,6 +76,8 @@
private final List<ContentValues> mMmsTable = new ArrayList<>();
/* Table contains parts, addresses of mms */
private final List<ContentValues> mMmsAllContentValues = new ArrayList<>();
+ /* Table contains parts, addresses of mms for null body test case */
+ private final List<ContentValues> mMmsNullBodyContentValues = new ArrayList<>();
/* Cursors being used to access sms, mms tables */
private FakeCursor mSmsCursor, mMmsCursor;
/* Test data with sms and mms */
@@ -81,7 +85,7 @@
/* Json representation for the test data */
private String[] mSmsJson, mMmsJson, mMmsAttachmentJson;
/* sms, mms json concatenated as json array */
- private String mAllSmsJson, mAllMmsJson, mMmsAllAttachmentJson;
+ private String mAllSmsJson, mAllMmsJson, mMmsAllAttachmentJson, mMmsAllNullBodyJson;
private StringWriter mStringWriter;
@@ -169,7 +173,7 @@
new String[]{"+111 (111) 11111111", "+11121212", "example@example.com",
"+999999999"} /*addresses*/,
3 /*threadId*/, false /*read*/, null /*smil*/, null /*attachmentTypes*/,
- null /*attachmentFilenames*/);
+ null /*attachmentFilenames*/, mMmsAllContentValues);
mMmsJson[0] = "{\"self_phone\":\"+111111111111111\",\"sub\":\"Subject 1\"," +
"\"date\":\"111111\",\"date_sent\":\"111112\",\"m_type\":\"3\",\"v\":\"17\"," +
@@ -191,7 +195,7 @@
121 /*body charset*/,
new String[]{"+7 (333) ", "example@example.com", "+999999999"} /*addresses*/,
4 /*threadId*/, true /*read*/, null /*smil*/, null /*attachmentTypes*/,
- null /*attachmentFilenames*/);
+ null /*attachmentFilenames*/, mMmsAllContentValues);
mMmsJson[1] = "{\"date\":\"111122\",\"date_sent\":\"1111112\",\"m_type\":\"4\"," +
"\"v\":\"18\",\"msg_box\":\"222\",\"ct_l\":\"location 2\"," +
"\"recipients\":[\"example@example.com\",\"+999999999\"]," +
@@ -210,7 +214,7 @@
131 /*body charset*/,
new String[]{"333 333333333333", "+1232132214124"} /*addresses*/,
1 /*threadId*/, false /*read*/, null /*smil*/, null /*attachmentTypes*/,
- null /*attachmentFilenames*/);
+ null /*attachmentFilenames*/, mMmsAllContentValues);
mMmsJson[2] = "{\"self_phone\":\"+333333333333333\",\"sub\":\"Subject 10\"," +
"\"date\":\"111133\",\"date_sent\":\"1111132\",\"m_type\":\"5\",\"v\":\"19\"," +
@@ -239,7 +243,7 @@
+ " width='100%'/></layout></head><body><par dur='5000ms'>"
+ "<img src='image000000.jpg' region='Image' /></par></body></smil>",
new String[] {"image/jpg"} /*attachmentTypes*/,
- new String[] {"GreatPict.jpg"} /*attachmentFilenames*/);
+ new String[] {"GreatPict.jpg"} /*attachmentFilenames*/, mMmsAllContentValues);
mMmsAttachmentJson[0] = "{\"self_phone\":\"+111111111111111\",\"sub\":\"Subject 1\"," +
"\"date\":\"111111\",\"date_sent\":\"111112\",\"m_type\":\"3\",\"v\":\"17\"," +
@@ -255,6 +259,20 @@
mMmsAllAttachmentJson = makeJsonArray(mMmsAttachmentJson);
+ createMmsRow(10 /*id*/, 1 /*subid*/, "Subject 1" /*subject*/,
+ 100 /*subcharset*/, 111111 /*date*/, 111112 /*datesent*/, 3 /*type*/,
+ 17 /*version*/, 0 /*textonly*/,
+ 11 /*msgBox*/, "location 1" /*contentLocation*/, "" /*body*/,
+ CharacterSets.DEFAULT_CHARSET /*body charset*/, new String[] {} /*addresses*/,
+ 3 /*threadId*/, false /*read*/, null /*smil*/, null /*attachmentTypes*/,
+ null /*attachmentFilenames*/, mMmsNullBodyContentValues);
+
+ mMmsAllNullBodyJson = makeJsonArray(new String[] {"{\"self_phone\":\"+111111111111111\"," +
+ "\"sub\":\"Subject 1\",\"date\":\"111111\",\"date_sent\":\"111112\",\"m_type\":" +
+ "\"3\",\"v\":\"17\",\"msg_box\":\"11\",\"ct_l\":\"location 1\"," +
+ "\"recipients\":[\"+11121212\",\"example@example.com\",\"+999999999\"]," +
+ "\"read\":\"0\", \"mms_addresses\":[],\"mms_charset\":111,\"sub_cs\":\"100\"}"});
+
ContentProvider contentProvider = new MockContentProvider() {
@Override
@@ -341,7 +359,8 @@
String contentLocation, String body,
int bodyCharset, String[] addresses, long threadId,
boolean read, String smil, String[] attachmentTypes,
- String[] attachmentFilenames) {
+ String[] attachmentFilenames,
+ List<ContentValues> rowsContainer) {
ContentValues mmsRow = new ContentValues();
mmsRow.put(Telephony.Mms._ID, id);
mmsRow.put(Telephony.Mms.SUBSCRIPTION_ID, subId);
@@ -364,8 +383,8 @@
final Uri partUri = Telephony.Mms.CONTENT_URI.buildUpon().appendPath(String.valueOf(id)).
appendPath("part").build();
mCursors.put(partUri, createBodyCursor(body, bodyCharset, smil, attachmentTypes,
- attachmentFilenames));
- mMmsAllContentValues.add(mmsRow);
+ attachmentFilenames, rowsContainer));
+ rowsContainer.add(mmsRow);
final Uri addrUri = Telephony.Mms.CONTENT_URI.buildUpon().appendPath(String.valueOf(id)).
appendPath("addr").build();
@@ -380,7 +399,8 @@
// Cursor with parts of Mms.
private FakeCursor createBodyCursor(String body, int charset, String existingSmil,
- String[] attachmentTypes, String[] attachmentFilenames) {
+ String[] attachmentTypes, String[] attachmentFilenames,
+ List<ContentValues> rowsContainer) {
List<ContentValues> table = new ArrayList<>();
final String srcName = String.format("text.%06d.txt", 0);
final String smilBody = TextUtils.isEmpty(existingSmil) ?
@@ -395,7 +415,7 @@
smilPart.put(Telephony.Mms.Part.CONTENT_ID, "<smil>");
smilPart.put(Telephony.Mms.Part.CONTENT_LOCATION, "smil.xml");
smilPart.put(Telephony.Mms.Part.TEXT, smil);
- mMmsAllContentValues.add(smilPart);
+ rowsContainer.add(smilPart);
// Text part
final ContentValues bodyPart = new ContentValues();
@@ -407,7 +427,7 @@
bodyPart.put(Telephony.Mms.Part.CHARSET, charset);
bodyPart.put(Telephony.Mms.Part.TEXT, body);
table.add(bodyPart);
- mMmsAllContentValues.add(bodyPart);
+ rowsContainer.add(bodyPart);
// Attachments
if (attachmentTypes != null) {
@@ -421,7 +441,7 @@
attachmentPart.put(Telephony.Mms.Part.CONTENT_ID, "<"+attachmentFilename+">");
attachmentPart.put(Telephony.Mms.Part.CONTENT_LOCATION, attachmentFilename);
table.add(attachmentPart);
- mMmsAllContentValues.add(attachmentPart);
+ rowsContainer.add(attachmentPart);
}
}
@@ -622,6 +642,17 @@
assertEquals(7, mmsProvider.getRowsAdded());
}
+ public void testRestoreMmsWithNullBody() throws Exception {
+ JsonReader jsonReader = new JsonReader
+ (new StringReader(addRandomDataToJson(mMmsAllNullBodyJson)));
+ FakeMmsProvider mmsProvider = new FakeMmsProvider(mMmsNullBodyContentValues);
+ mMockContentResolver.addProvider("mms", mmsProvider);
+
+ mTelephonyBackupAgent.putMmsMessagesToProvider(jsonReader);
+
+ assertEquals(3, mmsProvider.getRowsAdded());
+ }
+
/**
* Test with quota exceeded. Checking size of the backup before it hits quota and after.
* It still backs up more than a quota since there is meta-info which matters with small amounts
diff --git a/tests/src/com/android/providers/telephony/TelephonyProviderTest.java b/tests/src/com/android/providers/telephony/TelephonyProviderTest.java
index b77e5cf..2ca823a 100644
--- a/tests/src/com/android/providers/telephony/TelephonyProviderTest.java
+++ b/tests/src/com/android/providers/telephony/TelephonyProviderTest.java
@@ -42,15 +42,21 @@
import android.test.suitebuilder.annotation.SmallTest;
import android.util.Log;
+import com.android.internal.telephony.uicc.IccRecords;
+import com.android.internal.telephony.uicc.UiccController;
+
import junit.framework.TestCase;
import org.junit.Test;
+import org.mockito.ArgumentMatchers;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.List;
import java.util.stream.IntStream;
-
/**
* Tests for testing CRUD operations of TelephonyProvider.
* Uses a MockContentResolver to get permission WRITE_APN_SETTINGS in order to test insert/delete
@@ -70,6 +76,12 @@
private MockContentResolver mContentResolver;
private TelephonyProviderTestable mTelephonyProviderTestable;
+ @Mock
+ private UiccController mUiccController;
+
+ @Mock
+ private IccRecords mIcRecords;
+
private int notifyChangeCount;
private int notifyChangeRestoreCount;
private int notifyWfcCount;
@@ -79,6 +91,7 @@
private static final String TEST_OPERATOR = "123456";
private static final String TEST_MCC = "123";
private static final String TEST_MNC = "456";
+ private static final String TEST_SPN = TelephonyProviderTestable.TEST_SPN;
// Used to test the path for URL_TELEPHONY_USING_SUBID with subid 1
private static final Uri CONTENT_URI_WITH_SUBID = Uri.parse(
@@ -138,6 +151,9 @@
doReturn(mTelephonyManager).when(mTelephonyManager).createForSubscriptionId(anyInt());
doReturn(TEST_OPERATOR).when(mTelephonyManager).getSimOperator();
+ doReturn(mIcRecords).when(mUiccController).getIccRecords(anyInt(),
+ ArgumentMatchers.eq(UiccController.APP_FAM_3GPP));
+ doReturn(TEST_SPN).when(mIcRecords).getServiceProviderName();
// Add authority="telephony" to given telephonyProvider
ProviderInfo providerInfo = new ProviderInfo();
@@ -199,9 +215,11 @@
@Override
protected void setUp() throws Exception {
super.setUp();
+ MockitoAnnotations.initMocks(this);
mTelephonyProviderTestable = new TelephonyProviderTestable();
mContext = new MockContextWithProvider(mTelephonyProviderTestable);
mContentResolver = (MockContentResolver) mContext.getContentResolver();
+ replaceInstance(UiccController.class, "mInstance", null, mUiccController);
notifyChangeCount = 0;
notifyChangeRestoreCount = 0;
}
@@ -724,7 +742,7 @@
mTelephonyProviderTestable.fakeCallingUid(Process.SYSTEM_UID);
final int current = 1;
- final String numeric = "123456789";
+ final String numeric = TEST_OPERATOR;
final String selection = Carriers.NUMERIC + "=?";
final String[] selectionArgs = { numeric };
@@ -802,7 +820,7 @@
mTelephonyProviderTestable.fakeCallingUid(Process.SYSTEM_UID);
final int current = 1;
- final String numeric = "123456789";
+ final String numeric = TEST_OPERATOR;
// Insert DPC record.
final String dpcRecordApn = "exampleApnNameDPC";
@@ -893,7 +911,7 @@
mTelephonyProviderTestable.fakeCallingUid(Process.SYSTEM_UID);
final int current = 1;
- final String numeric = "123456789";
+ final String numeric = TEST_OPERATOR;
// Insert DPC record 1.
final String dpcRecordApn1 = "exampleApnNameDPC";
@@ -1445,22 +1463,23 @@
assertEquals(0, notifyWfcCountWithTestSubId);
}
+ protected void replaceInstance(final Class c, final String instanceName,
+ final Object obj, final Object newValue)
+ throws Exception {
+ Field field = c.getDeclaredField(instanceName);
+ field.setAccessible(true);
+ field.set(obj, newValue);
+ }
+
@Test
@SmallTest
public void testSIMAPNLIST_APNMatchTheMCCMNCAndMVNO() {
// Test on getCurrentAPNList() step 1
- TelephonyManager telephonyManager =
- ((TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE));
- doReturn(telephonyManager).when(telephonyManager).createForSubscriptionId(anyInt());
-
final String apnName = "apnName";
final String carrierName = "name";
final String numeric = TEST_OPERATOR;
final String mvnoType = "spn";
- final String mvnoData = TelephonyProviderTestable.TEST_SPN;
- final int carrierId = 100;
- doReturn(carrierId).when(telephonyManager).getSimCarrierId();
- doReturn(numeric).when(telephonyManager).getSimOperator();
+ final String mvnoData = TEST_SPN;
// Insert the APN and DB only have the MCC/MNC and MVNO APN
ContentValues contentValues = new ContentValues();
@@ -1473,12 +1492,12 @@
// Query DB
final String[] testProjection =
- {
- Carriers.APN,
- Carriers.NAME,
- Carriers.NUMERIC,
- Carriers.MVNO_MATCH_DATA
- };
+ {
+ Carriers.APN,
+ Carriers.NAME,
+ Carriers.NUMERIC,
+ Carriers.MVNO_MATCH_DATA
+ };
Cursor cursor = mContentResolver.query(URL_SIM_APN_LIST,
testProjection, null, null, null);
@@ -1493,21 +1512,9 @@
@SmallTest
public void testSIMAPNLIST_APNMatchTheParentMCCMNC() {
// Test on getCurrentAPNList() step 2
- TelephonyManager telephonyManager =
- ((TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE));
- doReturn(telephonyManager).when(telephonyManager).createForSubscriptionId(anyInt());
-
final String apnName = "apnName";
final String carrierName = "name";
final String numeric = TEST_OPERATOR;
- final String mvnoData = TelephonyProviderTestable.TEST_SPN;
- final int carrierId = 100;
- final int mnoCarrierId = 101;
-
- doReturn(carrierId).when(telephonyManager).getSimCarrierId();
- doReturn(numeric).when(telephonyManager).getSimOperator();
- doReturn(mvnoData).when(telephonyManager).getSimOperatorName();
- doReturn(mnoCarrierId).when(telephonyManager).getSimMNOCarrierId();
// Insert the APN and DB only have the MNO APN
ContentValues contentValues = new ContentValues();
@@ -1518,11 +1525,11 @@
// Query DB
final String[] testProjection =
- {
- Carriers.APN,
- Carriers.NAME,
- Carriers.NUMERIC,
- };
+ {
+ Carriers.APN,
+ Carriers.NAME,
+ Carriers.NUMERIC,
+ };
Cursor cursor = mContentResolver.query(URL_SIM_APN_LIST,
testProjection, null, null, null);