Merge "move column defs to Telephony.CarrierIdentification"
am: 8ab184ca94
Change-Id: I229c015a1f5fc0b04c62150462d90389a3bc9cc9
diff --git a/src/com/android/providers/telephony/CarrierIdProvider.java b/src/com/android/providers/telephony/CarrierIdProvider.java
index 9331cb2..08bb608 100644
--- a/src/com/android/providers/telephony/CarrierIdProvider.java
+++ b/src/com/android/providers/telephony/CarrierIdProvider.java
@@ -25,6 +25,7 @@
import android.database.sqlite.SQLiteOpenHelper;
import android.database.sqlite.SQLiteQueryBuilder;
import android.net.Uri;
+import android.provider.Telephony.CarrierIdentification;
import android.text.TextUtils;
import android.util.Log;
@@ -55,31 +56,23 @@
private static final String TAG = CarrierIdProvider.class.getSimpleName();
private static final String DATABASE_NAME = "carrierIdentification.db";
- private static final int DATABASE_VERSION = 1;
+ private static final int DATABASE_VERSION = 2;
/**
* The authority string for the CarrierIdProvider
*/
@VisibleForTesting
public static final String AUTHORITY = "carrier_identification";
- /**
- * The {@code content://} style URL for the CarrierIdProvider
- */
- public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY);
public static final String CARRIER_ID_TABLE = "carrier_id";
- public static final String MCCMNC = "mccmnc";
- public static final String GID1 = "gid1";
- public static final String GID2 = "gid2";
- public static final String PLMN = "plmn";
- public static final String IMSI_PREFIX = "imsi_prefix";
- public static final String SPN = "spn";
- public static final String APN = "apn";
- public static final String NAME = "carrier_name";
- public static final String CID = "carrier_id";
-
- private static final List<String> CARRIERS_ID_UNIQUE_FIELDS = new ArrayList<>(
- Arrays.asList(MCCMNC, GID1, GID2, PLMN, IMSI_PREFIX, SPN, APN));
+ private static final List<String> CARRIERS_ID_UNIQUE_FIELDS = new ArrayList<>(Arrays.asList(
+ CarrierIdentification.MCCMNC,
+ CarrierIdentification.GID1,
+ CarrierIdentification.GID2,
+ CarrierIdentification.PLMN,
+ CarrierIdentification.IMSI_PREFIX_XPATTERN,
+ CarrierIdentification.SPN,
+ CarrierIdentification.APN));
private CarrierIdDatabaseHelper mDbHelper;
@@ -87,21 +80,22 @@
public static String getStringForCarrierIdTableCreation(String tableName) {
return "CREATE TABLE " + tableName
+ "(_id INTEGER PRIMARY KEY,"
- + MCCMNC + " TEXT NOT NULL,"
- + GID1 + " TEXT,"
- + GID2 + " TEXT,"
- + PLMN + " TEXT,"
- + IMSI_PREFIX + " TEXT,"
- + SPN + " TEXT,"
- + APN + " TEXT,"
- + NAME + " TEXT,"
- + CID + " INTEGER DEFAULT -1,"
+ + CarrierIdentification.MCCMNC + " TEXT NOT NULL,"
+ + CarrierIdentification.GID1 + " TEXT,"
+ + CarrierIdentification.GID2 + " TEXT,"
+ + CarrierIdentification.PLMN + " TEXT,"
+ + CarrierIdentification.IMSI_PREFIX_XPATTERN + " TEXT,"
+ + CarrierIdentification.SPN + " TEXT,"
+ + CarrierIdentification.APN + " TEXT,"
+ + CarrierIdentification.NAME + " TEXT,"
+ + CarrierIdentification.CID + " INTEGER DEFAULT -1,"
+ "UNIQUE (" + TextUtils.join(", ", CARRIERS_ID_UNIQUE_FIELDS) + "));";
}
@VisibleForTesting
public static String getStringForIndexCreation(String tableName) {
- return "CREATE INDEX IF NOT EXISTS mccmncIndex ON " + tableName + " (" + MCCMNC + ");";
+ return "CREATE INDEX IF NOT EXISTS mccmncIndex ON " + tableName + " ("
+ + CarrierIdentification.MCCMNC + ");";
}
@Override
@@ -139,7 +133,7 @@
public Uri insert(Uri uri, ContentValues values) {
final long row = getWritableDatabase().insertOrThrow(CARRIER_ID_TABLE, null, values);
if (row > 0) {
- final Uri newUri = ContentUris.withAppendedId(CONTENT_URI, row);
+ final Uri newUri = ContentUris.withAppendedId(CarrierIdentification.CONTENT_URI, row);
getContext().getContentResolver().notifyChange(newUri, null);
return newUri;
}
@@ -158,7 +152,7 @@
final int count = getWritableDatabase().delete(CARRIER_ID_TABLE, selection, selectionArgs);
Log.d(TAG, " delete.count=" + count);
if (count > 0) {
- getContext().getContentResolver().notifyChange(CONTENT_URI, null);
+ getContext().getContentResolver().notifyChange(CarrierIdentification.CONTENT_URI, null);
}
return count;
}
@@ -176,7 +170,7 @@
selectionArgs);
Log.d(TAG, " update.count=" + count);
if (count > 0) {
- getContext().getContentResolver().notifyChange(CONTENT_URI, null);
+ getContext().getContentResolver().notifyChange(CarrierIdentification.CONTENT_URI, null);
}
return count;
}
diff --git a/tests/src/com/android/providers/telephony/CarrierIdProviderTest.java b/tests/src/com/android/providers/telephony/CarrierIdProviderTest.java
index e784d8d..443247a 100644
--- a/tests/src/com/android/providers/telephony/CarrierIdProviderTest.java
+++ b/tests/src/com/android/providers/telephony/CarrierIdProviderTest.java
@@ -24,6 +24,7 @@
import android.database.SQLException;
import android.net.Uri;
import android.os.Handler;
+import android.provider.Telephony.CarrierIdentification;
import android.test.mock.MockContentResolver;
import android.test.mock.MockContext;
import android.util.Log;
@@ -145,8 +146,9 @@
@Test
public void testInsertCarrierInfo() {
try {
- mContentResolver.insert(CarrierIdProvider.CONTENT_URI, createCarrierInfoInternal());
- Cursor countCursor = mContentResolver.query(CarrierIdProvider.CONTENT_URI,
+ mContentResolver.insert(CarrierIdentification.CONTENT_URI,
+ createCarrierInfoInternal());
+ Cursor countCursor = mContentResolver.query(CarrierIdentification.CONTENT_URI,
new String[]{"count(*) AS count"},
null,
null,
@@ -167,8 +169,8 @@
try {
//insert same row twice to break uniqueness constraint
ContentValues contentValues = createCarrierInfoInternal();
- mContentResolver.insert(CarrierIdProvider.CONTENT_URI, contentValues);
- mContentResolver.insert(CarrierIdProvider.CONTENT_URI, contentValues);
+ mContentResolver.insert(CarrierIdentification.CONTENT_URI, contentValues);
+ mContentResolver.insert(CarrierIdentification.CONTENT_URI, contentValues);
Assert.fail("should throw an exception for duplicate carrier info");
} catch (Exception e) {
Log.d(TAG, "Error inserting carrier info:" + e);
@@ -183,8 +185,8 @@
try {
//insert a row with null mnccmnc to break not null constraint
ContentValues contentValues = new ContentValues();
- contentValues.put(CarrierIdProvider.GID1, dummy_gid1);
- mContentResolver.insert(CarrierIdProvider.CONTENT_URI, contentValues);
+ contentValues.put(CarrierIdentification.GID1, dummy_gid1);
+ mContentResolver.insert(CarrierIdentification.CONTENT_URI, contentValues);
Assert.fail("should throw an exception for null mccmnc");
} catch (Exception e) {
Log.d(TAG, "Error inserting carrier info:" + e);
@@ -199,15 +201,15 @@
@Test
public void testDeleteCarrierInfo() {
try {
- mContentResolver.insert(CarrierIdProvider.CONTENT_URI, createCarrierInfoInternal());
+ mContentResolver.insert(CarrierIdentification.CONTENT_URI, createCarrierInfoInternal());
} catch (Exception e) {
Log.d(TAG, "Error inserting carrier info:" + e);
}
int numRowsDeleted = -1;
try {
- String whereClause = CarrierIdProvider.MCCMNC + "=?";
+ String whereClause = CarrierIdentification.MCCMNC + "=?";
String[] whereArgs = new String[] { dummy_mccmnc };
- numRowsDeleted = mContentResolver.delete(CarrierIdProvider.CONTENT_URI, whereClause,
+ numRowsDeleted = mContentResolver.delete(CarrierIdentification.CONTENT_URI, whereClause,
whereArgs);
} catch (Exception e) {
Log.d(TAG, "Error deleting values:" + e);
@@ -225,23 +227,24 @@
ContentValues contentValues = createCarrierInfoInternal();
try {
- mContentResolver.insert(CarrierIdProvider.CONTENT_URI, contentValues);
+ mContentResolver.insert(CarrierIdentification.CONTENT_URI, contentValues);
} catch (Exception e) {
Log.d(TAG, "Error inserting carrierInfo:" + e);
}
try {
- contentValues.put(CarrierIdProvider.CID, 1);
- mContentResolver.update(CarrierIdProvider.CONTENT_URI, contentValues,
- CarrierIdProvider.MCCMNC + "=?", new String[] { dummy_mccmnc });
+ contentValues.put(CarrierIdentification.CID, 1);
+ mContentResolver.update(CarrierIdentification.CONTENT_URI, contentValues,
+ CarrierIdentification.MCCMNC + "=?", new String[] { dummy_mccmnc });
} catch (Exception e) {
Log.d(TAG, "Error updating values:" + e);
}
try {
- Cursor findEntry = mContentResolver.query(CarrierIdProvider.CONTENT_URI,
- new String[] { CarrierIdProvider.CID },
- CarrierIdProvider.MCCMNC + "=?", new String[] { dummy_mccmnc }, null);
+ Cursor findEntry = mContentResolver.query(CarrierIdentification.CONTENT_URI,
+ new String[] { CarrierIdentification.CID },
+ CarrierIdentification.MCCMNC + "=?", new String[] { dummy_mccmnc },
+ null);
findEntry.moveToFirst();
cid = findEntry.getInt(0);
} catch (Exception e) {
@@ -257,21 +260,22 @@
try {
// insert a MVNO
- mContentResolver.insert(CarrierIdProvider.CONTENT_URI, contentValues);
+ mContentResolver.insert(CarrierIdentification.CONTENT_URI, contentValues);
// insert its MNO
contentValues = new ContentValues();
- contentValues.put(CarrierIdProvider.MCCMNC, dummy_mccmnc);
- contentValues.put(CarrierIdProvider.CID, 1);
- mContentResolver.insert(CarrierIdProvider.CONTENT_URI, contentValues);
+ contentValues.put(CarrierIdentification.MCCMNC, dummy_mccmnc);
+ contentValues.put(CarrierIdentification.CID, 1);
+ mContentResolver.insert(CarrierIdentification.CONTENT_URI, contentValues);
} catch (Exception e) {
Log.d(TAG, "Error inserting carrierInfo:" + e);
}
Cursor findEntry = null;
- String[] columns ={CarrierIdProvider.CID};
+ String[] columns = {CarrierIdentification.CID};
try {
- findEntry = mContentResolver.query(CarrierIdProvider.CONTENT_URI, columns,
- CarrierIdProvider.MCCMNC + "=?", new String[] { dummy_mccmnc }, null);
+ findEntry = mContentResolver.query(CarrierIdentification.CONTENT_URI, columns,
+ CarrierIdentification.MCCMNC + "=?", new String[] { dummy_mccmnc },
+ null);
} catch (Exception e) {
Log.d(TAG, "Query failed:" + e);
}
@@ -279,8 +283,8 @@
try {
// query based on mccmnc & gid1
- findEntry = mContentResolver.query(CarrierIdProvider.CONTENT_URI, columns,
- CarrierIdProvider.MCCMNC + "=? and " + CarrierIdProvider.GID1 + "=?",
+ findEntry = mContentResolver.query(CarrierIdentification.CONTENT_URI, columns,
+ CarrierIdentification.MCCMNC + "=? and " + CarrierIdentification.GID1 + "=?",
new String[] { dummy_mccmnc, dummy_gid1 }, null);
} catch (Exception e) {
Log.d(TAG, "Query failed:" + e);
@@ -292,15 +296,15 @@
private static ContentValues createCarrierInfoInternal() {
ContentValues contentValues = new ContentValues();
- contentValues.put(CarrierIdProvider.MCCMNC, dummy_mccmnc);
- contentValues.put(CarrierIdProvider.GID1, dummy_gid1);
- contentValues.put(CarrierIdProvider.GID2, dummy_gid2);
- contentValues.put(CarrierIdProvider.PLMN, dummy_plmn);
- contentValues.put(CarrierIdProvider.IMSI_PREFIX, dummy_imsi_prefix);
- contentValues.put(CarrierIdProvider.SPN, dummy_spn);
- contentValues.put(CarrierIdProvider.APN, dummy_apn);
- contentValues.put(CarrierIdProvider.NAME, dummy_name);
- contentValues.put(CarrierIdProvider.CID, dummy_cid);
+ contentValues.put(CarrierIdentification.MCCMNC, dummy_mccmnc);
+ contentValues.put(CarrierIdentification.GID1, dummy_gid1);
+ contentValues.put(CarrierIdentification.GID2, dummy_gid2);
+ contentValues.put(CarrierIdentification.PLMN, dummy_plmn);
+ contentValues.put(CarrierIdentification.IMSI_PREFIX_XPATTERN, dummy_imsi_prefix);
+ contentValues.put(CarrierIdentification.SPN, dummy_spn);
+ contentValues.put(CarrierIdentification.APN, dummy_apn);
+ contentValues.put(CarrierIdentification.NAME, dummy_name);
+ contentValues.put(CarrierIdentification.CID, dummy_cid);
return contentValues;
}
}