Carrier provider to hold the IMSI.
Updated certain column types.
BUG: 35606429
Test: Added CarrierProviderTest
Change-Id: I29a16c0b970770745fdf8d0916256392c013f86b
diff --git a/src/com/android/providers/telephony/CarrierDatabaseHelper.java b/src/com/android/providers/telephony/CarrierDatabaseHelper.java
index 5236b89..b654a77 100644
--- a/src/com/android/providers/telephony/CarrierDatabaseHelper.java
+++ b/src/com/android/providers/telephony/CarrierDatabaseHelper.java
@@ -21,6 +21,8 @@
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.text.TextUtils;
+import android.util.Log;
+
import java.util.ArrayList;
import java.util.List;
@@ -30,7 +32,7 @@
private static final String DATABASE_NAME = "CarrierInformation.db";
public static final String CARRIER_KEY_TABLE = "carrier_key";
- private static final int DATABASE_VERSION = 1;
+ private static final int DATABASE_VERSION = 2;
/**
* CarrierDatabaseHelper carrier database helper class.
@@ -40,14 +42,15 @@
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
- static final String KEY_TYPE = "key_type";
- static final String KEY = "key";
- static final String MCC = "mcc";
- static final String MNC = "mnc";
- static final String MVNO_TYPE = "mvno_type";
- static final String MVNO_MATCH_DATA = "mvno_match_data";
- static final String PUBLIC_CERTIFICATE = "public_certificate";
- static final String LAST_MODIFIED = "last_modified";
+ public static final String KEY_TYPE = "key_type";
+ public static final String MCC = "mcc";
+ public static final String MNC = "mnc";
+ public static final String MVNO_TYPE = "mvno_type";
+ public static final String MVNO_MATCH_DATA = "mvno_match_data";
+ public static final String PUBLIC_KEY = "public_key";
+ public static final String KEY_IDENTIFIER = "key_identifier";
+ public static final String EXPIRATION_TIME = "expiration_time";
+ public static final String LAST_MODIFIED = "last_modified";
private static final List<String> CARRIERS_UNIQUE_FIELDS = new ArrayList<String>();
@@ -67,8 +70,9 @@
MVNO_TYPE + " TEXT DEFAULT ''," +
MVNO_MATCH_DATA + " TEXT DEFAULT ''," +
KEY_TYPE + " TEXT DEFAULT ''," +
- KEY + " TEXT DEFAULT ''," +
- PUBLIC_CERTIFICATE + " TEXT DEFAULT ''," +
+ KEY_IDENTIFIER + " TEXT DEFAULT ''," +
+ PUBLIC_KEY + " BLOB DEFAULT ''," +
+ EXPIRATION_TIME + " INTEGER DEFAULT 0," +
LAST_MODIFIED + " INTEGER DEFAULT 0," +
"UNIQUE (" + TextUtils.join(", ", CARRIERS_UNIQUE_FIELDS) + "));";
}
@@ -78,8 +82,20 @@
db.execSQL(getStringForCarrierKeyTableCreation(CARRIER_KEY_TABLE));
}
+ public void createCarrierTable(SQLiteDatabase db) {
+ db.execSQL(getStringForCarrierKeyTableCreation(CARRIER_KEY_TABLE));
+ }
+
+ public void dropCarrierTable(SQLiteDatabase db) {
+ db.execSQL("DROP TABLE IF EXISTS " + CARRIER_KEY_TABLE + ";");
+ }
+
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
- // do nothing
+ Log.d(TAG, "dbh.onUpgrade:+ db=" + db + " oldV=" + oldVersion + " newV=" + newVersion);
+ if (oldVersion < 2) {
+ dropCarrierTable(db);
+ createCarrierTable(db);
+ }
}
}
diff --git a/src/com/android/providers/telephony/CarrierProvider.java b/src/com/android/providers/telephony/CarrierProvider.java
index 1c85806..a13c7e3 100644
--- a/src/com/android/providers/telephony/CarrierProvider.java
+++ b/src/com/android/providers/telephony/CarrierProvider.java
@@ -78,14 +78,14 @@
@Override
public Uri insert(Uri uri, ContentValues values) {
values.put(CarrierDatabaseHelper.LAST_MODIFIED, System.currentTimeMillis());
- long row = getWritableDatabase().insert(CarrierDatabaseHelper.CARRIER_KEY_TABLE,
+ long row = getWritableDatabase().insertOrThrow(CarrierDatabaseHelper.CARRIER_KEY_TABLE,
null, values);
if (row > 0) {
Uri newUri = ContentUris.withAppendedId(CONTENT_URI, row);
getContext().getContentResolver().notifyChange(newUri, null);
return newUri;
}
- throw new SQLException("Fail to add a new record into " + uri);
+ return null;
}
@Override
@@ -95,7 +95,7 @@
@Override
public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
-
+ values.put(CarrierDatabaseHelper.LAST_MODIFIED, System.currentTimeMillis());
if (VDBG) {
Log.d(TAG, "update:"
+ " uri=" + uri
diff --git a/tests/src/com/android/providers/telephony/CarrierProviderTest.java b/tests/src/com/android/providers/telephony/CarrierProviderTest.java
index 6a56343..b0b9b09 100644
--- a/tests/src/com/android/providers/telephony/CarrierProviderTest.java
+++ b/tests/src/com/android/providers/telephony/CarrierProviderTest.java
@@ -54,7 +54,7 @@
private MockContentResolver mContentResolver;
private CarrierProviderTestable mCarrierProviderTestable;
- public static final String dummy_type = "TYPE5";
+ public static final int dummy_type = 1;
public static final String dummy_mnc = "MNC001";
public static final String dummy_mnc2 = "MNC002";
public static final String dummy_mcc = "MCC005";
@@ -62,6 +62,8 @@
public static final String dummy_key2 = "PUBKEY2";
public static final String dummy_mvno_type = "100";
public static final String dummy_mvno_match_data = "101";
+ public static final String dummy_key_identifier_data = "key_identifier1";
+ public static final long dummy_key_expiration = 1496795015L;
/**
@@ -147,7 +149,9 @@
contentValues.put(CarrierDatabaseHelper.MNC, dummy_mnc);
contentValues.put(CarrierDatabaseHelper.MVNO_TYPE, dummy_mvno_type);
contentValues.put(CarrierDatabaseHelper.MVNO_MATCH_DATA, dummy_mvno_match_data);
- contentValues.put(CarrierDatabaseHelper.PUBLIC_CERTIFICATE, dummy_key1);
+ contentValues.put(CarrierDatabaseHelper.KEY_IDENTIFIER, dummy_key_identifier_data);
+ contentValues.put(CarrierDatabaseHelper.PUBLIC_KEY, dummy_key1.getBytes());
+ contentValues.put(CarrierDatabaseHelper.EXPIRATION_TIME, dummy_key_expiration);
try {
mContentResolver.insert(CarrierProvider.CONTENT_URI, contentValues);
@@ -181,7 +185,9 @@
contentValues.put(CarrierDatabaseHelper.MNC, dummy_mnc);
contentValues.put(CarrierDatabaseHelper.MVNO_TYPE, dummy_mvno_type);
contentValues.put(CarrierDatabaseHelper.MVNO_MATCH_DATA, dummy_mvno_match_data);
- contentValues.put(CarrierDatabaseHelper.PUBLIC_CERTIFICATE, dummy_key1);
+ contentValues.put(CarrierDatabaseHelper.KEY_IDENTIFIER, dummy_key_identifier_data);
+ contentValues.put(CarrierDatabaseHelper.PUBLIC_KEY, dummy_key1.getBytes());
+ contentValues.put(CarrierDatabaseHelper.EXPIRATION_TIME, dummy_key_expiration);
try {
mContentResolver.insert(CarrierProvider.CONTENT_URI, contentValues);
@@ -191,18 +197,19 @@
try {
ContentValues updatedValues = new ContentValues();
- updatedValues.put(CarrierDatabaseHelper.PUBLIC_CERTIFICATE, dummy_key2);
+ updatedValues.put(CarrierDatabaseHelper.PUBLIC_KEY, dummy_key2);
mContentResolver.update(CarrierProvider.CONTENT_URI, updatedValues,
- "mcc=? and mnc=? and key_type=?", new String[] { dummy_mcc, dummy_mnc, dummy_type });
+ "mcc=? and mnc=? and key_type=?", new String[] { dummy_mcc, dummy_mnc,
+ String.valueOf(dummy_type) });
} catch (Exception e) {
Log.d(TAG, "Error updating values:" + e);
}
try {
- String[] columns ={CarrierDatabaseHelper.PUBLIC_CERTIFICATE};
+ String[] columns ={CarrierDatabaseHelper.PUBLIC_KEY};
Cursor findEntry = mContentResolver.query(CarrierProvider.CONTENT_URI, columns,
"mcc=? and mnc=? and key_type=?",
- new String[] { dummy_mcc, dummy_mnc, dummy_type }, null);
+ new String[] { dummy_mcc, dummy_mnc, String.valueOf(dummy_type) }, null);
findEntry.moveToFirst();
key = findEntry.getString(0);
} catch (Exception e) {
@@ -224,7 +231,8 @@
contentValues.put(CarrierDatabaseHelper.MNC, dummy_mnc);
contentValues.put(CarrierDatabaseHelper.MVNO_TYPE, dummy_mvno_type);
contentValues.put(CarrierDatabaseHelper.MVNO_MATCH_DATA, dummy_mvno_match_data);
- contentValues.put(CarrierDatabaseHelper.PUBLIC_CERTIFICATE, dummy_key1);
+ contentValues.put(CarrierDatabaseHelper.KEY_IDENTIFIER, dummy_key_identifier_data);
+ contentValues.put(CarrierDatabaseHelper.PUBLIC_KEY, dummy_key1.getBytes());
ContentValues contentValuesNew = new ContentValues();
contentValuesNew.put(CarrierDatabaseHelper.KEY_TYPE, dummy_type);
@@ -232,7 +240,8 @@
contentValuesNew.put(CarrierDatabaseHelper.MNC, dummy_mnc2);
contentValuesNew.put(CarrierDatabaseHelper.MVNO_TYPE, dummy_mvno_type);
contentValuesNew.put(CarrierDatabaseHelper.MVNO_MATCH_DATA, dummy_mvno_match_data);
- contentValuesNew.put(CarrierDatabaseHelper.PUBLIC_CERTIFICATE, dummy_key2);
+ contentValues.put(CarrierDatabaseHelper.KEY_IDENTIFIER, dummy_key_identifier_data);
+ contentValuesNew.put(CarrierDatabaseHelper.PUBLIC_KEY, dummy_key2.getBytes());
try {
mContentResolver.insert(CarrierProvider.CONTENT_URI, contentValues);
@@ -266,7 +275,7 @@
contentValues.put(CarrierDatabaseHelper.MNC, dummy_mnc);
contentValues.put(CarrierDatabaseHelper.MVNO_TYPE, dummy_mvno_type);
contentValues.put(CarrierDatabaseHelper.MVNO_MATCH_DATA, dummy_mvno_match_data);
- contentValues.put(CarrierDatabaseHelper.PUBLIC_CERTIFICATE, dummy_key1);
+ contentValues.put(CarrierDatabaseHelper.PUBLIC_KEY, dummy_key1.getBytes());
try {
mContentResolver.insert(CarrierProvider.CONTENT_URI, contentValues);