summaryrefslogtreecommitdiff
path: root/src/com/android
diff options
context:
space:
mode:
authorChen Xu <fionaxu@google.com>2020-06-24 22:21:59 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2020-06-24 22:21:59 +0000
commit198f29e82b96bd79ad974ddf0ef0200d00a334f9 (patch)
treea511acf1111cfcd00d4b0f44ad99509c3df4187f /src/com/android
parent2a0ac1a43f91a148e66866fe144d211992b8d025 (diff)
parent643973c43986c7771ad18233d20206f7fa60aacb (diff)
downloadCellBroadcastReceiver-198f29e82b96bd79ad974ddf0ef0200d00a334f9.tar.gz
Merge "improve test coverage for cellbroadcastcontentprovider" into rvc-dev
Diffstat (limited to 'src/com/android')
-rw-r--r--src/com/android/cellbroadcastreceiver/CellBroadcastContentProvider.java13
-rw-r--r--src/com/android/cellbroadcastreceiver/CellBroadcastDatabaseHelper.java59
2 files changed, 45 insertions, 27 deletions
diff --git a/src/com/android/cellbroadcastreceiver/CellBroadcastContentProvider.java b/src/com/android/cellbroadcastreceiver/CellBroadcastContentProvider.java
index 4f7572d6b..6c93104af 100644
--- a/src/com/android/cellbroadcastreceiver/CellBroadcastContentProvider.java
+++ b/src/com/android/cellbroadcastreceiver/CellBroadcastContentProvider.java
@@ -34,6 +34,7 @@ import android.telephony.SmsCbLocation;
import android.telephony.SmsCbMessage;
import android.text.TextUtils;
import android.util.Log;
+import com.android.internal.annotations.VisibleForTesting;
/**
* ContentProvider for the database of received cell broadcasts.
@@ -68,7 +69,8 @@ public class CellBroadcastContentProvider extends ContentProvider {
}
/** The database for this content provider. */
- private SQLiteOpenHelper mOpenHelper;
+ @VisibleForTesting
+ public SQLiteOpenHelper mOpenHelper;
/**
* Initialize content provider.
@@ -232,7 +234,8 @@ public class CellBroadcastContentProvider extends ContentProvider {
* @param message the message to insert
* @return true if the broadcast is new, false if it's a duplicate broadcast.
*/
- boolean insertNewBroadcast(SmsCbMessage message) {
+ @VisibleForTesting
+ public boolean insertNewBroadcast(SmsCbMessage message) {
SQLiteDatabase db = mOpenHelper.getWritableDatabase();
ContentValues cv = getContentValues(message);
@@ -257,7 +260,8 @@ public class CellBroadcastContentProvider extends ContentProvider {
* @param rowId the row ID of the broadcast to delete
* @return true if the database was updated, false otherwise
*/
- boolean deleteBroadcast(long rowId) {
+ @VisibleForTesting
+ public boolean deleteBroadcast(long rowId) {
SQLiteDatabase db = mOpenHelper.getWritableDatabase();
int rowCount = db.delete(CellBroadcastDatabaseHelper.TABLE_NAME,
@@ -275,7 +279,8 @@ public class CellBroadcastContentProvider extends ContentProvider {
* Internal method to delete all cell broadcasts and notify observers.
* @return true if the database was updated, false otherwise
*/
- boolean deleteAllBroadcasts() {
+ @VisibleForTesting
+ public boolean deleteAllBroadcasts() {
SQLiteDatabase db = mOpenHelper.getWritableDatabase();
int rowCount = db.delete(CellBroadcastDatabaseHelper.TABLE_NAME, null, null);
diff --git a/src/com/android/cellbroadcastreceiver/CellBroadcastDatabaseHelper.java b/src/com/android/cellbroadcastreceiver/CellBroadcastDatabaseHelper.java
index fd736f330..ff264d3a2 100644
--- a/src/com/android/cellbroadcastreceiver/CellBroadcastDatabaseHelper.java
+++ b/src/com/android/cellbroadcastreceiver/CellBroadcastDatabaseHelper.java
@@ -25,7 +25,9 @@ import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.os.RemoteException;
import android.provider.Telephony;
+import android.provider.Telephony.CellBroadcasts;
import android.util.Log;
+import com.android.internal.annotations.VisibleForTesting;
/**
* Open, create, and upgrade the cell broadcast SQLite database. Previously an inner class of
@@ -38,7 +40,8 @@ public class CellBroadcastDatabaseHelper extends SQLiteOpenHelper {
private static final String TAG = "CellBroadcastDatabaseHelper";
private static final String DATABASE_NAME = "cell_broadcasts.db";
- static final String TABLE_NAME = "broadcasts";
+ @VisibleForTesting
+ public static final String TABLE_NAME = "broadcasts";
/*
* Query columns for instantiating SmsCbMessage.
@@ -68,6 +71,37 @@ public class CellBroadcastDatabaseHelper extends SQLiteOpenHelper {
};
/**
+ * Returns a string used to create the cell broadcast table. This is exposed so the unit test
+ * can construct its own in-memory database to match the cell broadcast db.
+ */
+ @VisibleForTesting
+ public static String getStringForCellBroadcastTableCreation(String tableName) {
+ return "CREATE TABLE " + tableName + " ("
+ + CellBroadcasts._ID + " INTEGER PRIMARY KEY AUTOINCREMENT,"
+ + CellBroadcasts.SLOT_INDEX + " INTEGER DEFAULT 0,"
+ + CellBroadcasts.GEOGRAPHICAL_SCOPE + " INTEGER,"
+ + CellBroadcasts.PLMN + " TEXT,"
+ + CellBroadcasts.LAC + " INTEGER,"
+ + CellBroadcasts.CID + " INTEGER,"
+ + CellBroadcasts.SERIAL_NUMBER + " INTEGER,"
+ + Telephony.CellBroadcasts.SERVICE_CATEGORY + " INTEGER,"
+ + Telephony.CellBroadcasts.LANGUAGE_CODE + " TEXT,"
+ + Telephony.CellBroadcasts.MESSAGE_BODY + " TEXT,"
+ + Telephony.CellBroadcasts.DELIVERY_TIME + " INTEGER,"
+ + Telephony.CellBroadcasts.MESSAGE_READ + " INTEGER,"
+ + Telephony.CellBroadcasts.MESSAGE_FORMAT + " INTEGER,"
+ + Telephony.CellBroadcasts.MESSAGE_PRIORITY + " INTEGER,"
+ + Telephony.CellBroadcasts.ETWS_WARNING_TYPE + " INTEGER,"
+ + Telephony.CellBroadcasts.CMAS_MESSAGE_CLASS + " INTEGER,"
+ + Telephony.CellBroadcasts.CMAS_CATEGORY + " INTEGER,"
+ + Telephony.CellBroadcasts.CMAS_RESPONSE_TYPE + " INTEGER,"
+ + Telephony.CellBroadcasts.CMAS_SEVERITY + " INTEGER,"
+ + Telephony.CellBroadcasts.CMAS_URGENCY + " INTEGER,"
+ + Telephony.CellBroadcasts.CMAS_CERTAINTY + " INTEGER);";
+ }
+
+
+ /**
* Database version 1: initial version (support removed)
* Database version 2-9: (reserved for OEM database customization) (support removed)
* Database version 10: adds ETWS and CMAS columns and CDMA support (support removed)
@@ -87,28 +121,7 @@ public class CellBroadcastDatabaseHelper extends SQLiteOpenHelper {
@Override
public void onCreate(SQLiteDatabase db) {
- db.execSQL("CREATE TABLE " + TABLE_NAME + " ("
- + Telephony.CellBroadcasts._ID + " INTEGER PRIMARY KEY AUTOINCREMENT,"
- + Telephony.CellBroadcasts.SLOT_INDEX + " INTEGER DEFAULT 0,"
- + Telephony.CellBroadcasts.GEOGRAPHICAL_SCOPE + " INTEGER,"
- + Telephony.CellBroadcasts.PLMN + " TEXT,"
- + Telephony.CellBroadcasts.LAC + " INTEGER,"
- + Telephony.CellBroadcasts.CID + " INTEGER,"
- + Telephony.CellBroadcasts.SERIAL_NUMBER + " INTEGER,"
- + Telephony.CellBroadcasts.SERVICE_CATEGORY + " INTEGER,"
- + Telephony.CellBroadcasts.LANGUAGE_CODE + " TEXT,"
- + Telephony.CellBroadcasts.MESSAGE_BODY + " TEXT,"
- + Telephony.CellBroadcasts.DELIVERY_TIME + " INTEGER,"
- + Telephony.CellBroadcasts.MESSAGE_READ + " INTEGER,"
- + Telephony.CellBroadcasts.MESSAGE_FORMAT + " INTEGER,"
- + Telephony.CellBroadcasts.MESSAGE_PRIORITY + " INTEGER,"
- + Telephony.CellBroadcasts.ETWS_WARNING_TYPE + " INTEGER,"
- + Telephony.CellBroadcasts.CMAS_MESSAGE_CLASS + " INTEGER,"
- + Telephony.CellBroadcasts.CMAS_CATEGORY + " INTEGER,"
- + Telephony.CellBroadcasts.CMAS_RESPONSE_TYPE + " INTEGER,"
- + Telephony.CellBroadcasts.CMAS_SEVERITY + " INTEGER,"
- + Telephony.CellBroadcasts.CMAS_URGENCY + " INTEGER,"
- + Telephony.CellBroadcasts.CMAS_CERTAINTY + " INTEGER);");
+ db.execSQL(getStringForCellBroadcastTableCreation(TABLE_NAME));
db.execSQL("CREATE INDEX IF NOT EXISTS deliveryTimeIndex ON " + TABLE_NAME
+ " (" + Telephony.CellBroadcasts.DELIVERY_TIME + ");");