Added sub id to SmsCbMessage am: 0bd7e43bca
am: 96b5ece9ed
Change-Id: I1520d75673a0ea6ac2aae3a7a9b790a19c6df967
diff --git a/src/com/android/cellbroadcastservice/CellBroadcastProvider.java b/src/com/android/cellbroadcastservice/CellBroadcastProvider.java
index c32f764..e45daca 100644
--- a/src/com/android/cellbroadcastservice/CellBroadcastProvider.java
+++ b/src/com/android/cellbroadcastservice/CellBroadcastProvider.java
@@ -99,40 +99,34 @@
public static final Uri CONTENT_URI = Uri.parse("content://cellbroadcasts");
/**
- * Local definition of the subId column name.
- * The value should match CellBroadcasts.SUB_ID, but we don't use it here because it's hidden
- * and deprecated, and slot_index should be enough in the future.
- */
- private static final String SUB_ID = "sub_id";
-
- /**
* Local definition of the query columns for instantiating
* {@link android.telephony.SmsCbMessage} objects.
*/
public static final String[] QUERY_COLUMNS = {
- CellBroadcasts._ID,
- CellBroadcasts.SLOT_INDEX,
- CellBroadcasts.GEOGRAPHICAL_SCOPE,
- CellBroadcasts.PLMN,
- CellBroadcasts.LAC,
- CellBroadcasts.CID,
- CellBroadcasts.SERIAL_NUMBER,
- CellBroadcasts.SERVICE_CATEGORY,
- CellBroadcasts.LANGUAGE_CODE,
- CellBroadcasts.MESSAGE_BODY,
- CellBroadcasts.MESSAGE_FORMAT,
- CellBroadcasts.MESSAGE_PRIORITY,
- CellBroadcasts.ETWS_WARNING_TYPE,
- CellBroadcasts.CMAS_MESSAGE_CLASS,
- CellBroadcasts.CMAS_CATEGORY,
- CellBroadcasts.CMAS_RESPONSE_TYPE,
- CellBroadcasts.CMAS_SEVERITY,
- CellBroadcasts.CMAS_URGENCY,
- CellBroadcasts.CMAS_CERTAINTY,
- CellBroadcasts.RECEIVED_TIME,
- CellBroadcasts.MESSAGE_BROADCASTED,
- CellBroadcasts.GEOMETRIES,
- CellBroadcasts.MAXIMUM_WAIT_TIME
+ CellBroadcasts._ID,
+ CellBroadcasts.SLOT_INDEX,
+ CellBroadcasts.SUB_ID,
+ CellBroadcasts.GEOGRAPHICAL_SCOPE,
+ CellBroadcasts.PLMN,
+ CellBroadcasts.LAC,
+ CellBroadcasts.CID,
+ CellBroadcasts.SERIAL_NUMBER,
+ CellBroadcasts.SERVICE_CATEGORY,
+ CellBroadcasts.LANGUAGE_CODE,
+ CellBroadcasts.MESSAGE_BODY,
+ CellBroadcasts.MESSAGE_FORMAT,
+ CellBroadcasts.MESSAGE_PRIORITY,
+ CellBroadcasts.ETWS_WARNING_TYPE,
+ CellBroadcasts.CMAS_MESSAGE_CLASS,
+ CellBroadcasts.CMAS_CATEGORY,
+ CellBroadcasts.CMAS_RESPONSE_TYPE,
+ CellBroadcasts.CMAS_SEVERITY,
+ CellBroadcasts.CMAS_URGENCY,
+ CellBroadcasts.CMAS_CERTAINTY,
+ CellBroadcasts.RECEIVED_TIME,
+ CellBroadcasts.MESSAGE_BROADCASTED,
+ CellBroadcasts.GEOMETRIES,
+ CellBroadcasts.MAXIMUM_WAIT_TIME
};
@VisibleForTesting
@@ -307,7 +301,7 @@
public static String getStringForCellBroadcastTableCreation(String tableName) {
return "CREATE TABLE " + tableName + " ("
+ CellBroadcasts._ID + " INTEGER PRIMARY KEY AUTOINCREMENT,"
- + SUB_ID + " INTEGER,"
+ + CellBroadcasts.SUB_ID + " INTEGER,"
+ CellBroadcasts.SLOT_INDEX + " INTEGER DEFAULT 0,"
+ CellBroadcasts.GEOGRAPHICAL_SCOPE + " INTEGER,"
+ CellBroadcasts.PLMN + " TEXT,"
@@ -384,7 +378,7 @@
if (DBG) {
Log.d(TAG, "onUpgrade: oldV=" + oldVersion + " newV=" + newVersion);
}
- if (newVersion == 2) {
+ if (oldVersion < 2) {
db.execSQL("ALTER TABLE " + CELL_BROADCASTS_TABLE_NAME + " ADD COLUMN "
+ CellBroadcasts.SLOT_INDEX + " INTEGER DEFAULT 0;");
Log.d(TAG, "add slotIndex column");
diff --git a/src/com/android/cellbroadcastservice/DefaultCellBroadcastService.java b/src/com/android/cellbroadcastservice/DefaultCellBroadcastService.java
index 15e550b..42e1e5c 100644
--- a/src/com/android/cellbroadcastservice/DefaultCellBroadcastService.java
+++ b/src/com/android/cellbroadcastservice/DefaultCellBroadcastService.java
@@ -113,10 +113,18 @@
Log.d(TAG, "MT raw BearerData = " + toHexString(bearerData, 0, bearerData.length));
SmsCbLocation location = new SmsCbLocation(plmn);
+ SubscriptionManager sm = (SubscriptionManager) context.getSystemService(
+ Context.TELEPHONY_SUBSCRIPTION_SERVICE);
+ int subId = SubscriptionManager.DEFAULT_SUBSCRIPTION_ID;
+ int[] subIds = sm.getSubscriptionIds(slotIndex);
+ if (subIds != null && subIds.length > 0) {
+ subId = subIds[0];
+ }
+
return new SmsCbMessage(SmsCbMessage.MESSAGE_FORMAT_3GPP2,
SmsCbMessage.GEOGRAPHICAL_SCOPE_PLMN_WIDE, bData.messageId, location,
serviceCategory, bData.getLanguage(), bData.userData.payloadStr,
- bData.priority, null, bData.cmasWarningInfo, slotIndex);
+ bData.priority, null, bData.cmasWarningInfo, slotIndex, subId);
}
private static String toHexString(byte[] array, int offset, int length) {
diff --git a/src/com/android/cellbroadcastservice/GsmSmsCbMessage.java b/src/com/android/cellbroadcastservice/GsmSmsCbMessage.java
index 6a0c7cc..d498e25 100644
--- a/src/com/android/cellbroadcastservice/GsmSmsCbMessage.java
+++ b/src/com/android/cellbroadcastservice/GsmSmsCbMessage.java
@@ -30,6 +30,7 @@
import android.telephony.SmsCbLocation;
import android.telephony.SmsCbMessage;
import android.telephony.SmsMessage;
+import android.telephony.SubscriptionManager;
import android.util.Pair;
import android.util.Slog;
@@ -93,6 +94,14 @@
public static SmsCbMessage createSmsCbMessage(Context context, SmsCbHeader header,
SmsCbLocation location, byte[][] pdus, int slotIndex)
throws IllegalArgumentException {
+ SubscriptionManager sm = (SubscriptionManager) context.getSystemService(
+ Context.TELEPHONY_SUBSCRIPTION_SERVICE);
+ int subId = SubscriptionManager.DEFAULT_SUBSCRIPTION_ID;
+ int[] subIds = sm.getSubscriptionIds(slotIndex);
+ if (subIds != null && subIds.length > 0) {
+ subId = subIds[0];
+ }
+
long receivedTimeMillis = System.currentTimeMillis();
if (header.isEtwsPrimaryNotification()) {
// ETSI TS 23.041 ETWS Primary Notification message
@@ -103,7 +112,7 @@
header.getSerialNumber(), location, header.getServiceCategory(), null,
getEtwsPrimaryMessage(context, header.getEtwsInfo().getWarningType()),
SmsCbMessage.MESSAGE_PRIORITY_EMERGENCY, header.getEtwsInfo(),
- header.getCmasInfo(), slotIndex);
+ header.getCmasInfo(), slotIndex, subId);
} else if (header.isUmtsFormat()) {
// UMTS format has only 1 PDU
byte[] pdu = pdus[0];
@@ -137,7 +146,7 @@
header.getGeographicalScope(), header.getSerialNumber(), location,
header.getServiceCategory(), language, body, priority,
header.getEtwsInfo(), header.getCmasInfo(), maximumWaitingTimeSec, geometries,
- receivedTimeMillis, slotIndex);
+ receivedTimeMillis, slotIndex, subId);
} else {
String language = null;
StringBuilder sb = new StringBuilder();
@@ -152,7 +161,7 @@
return new SmsCbMessage(SmsCbMessage.MESSAGE_FORMAT_3GPP,
header.getGeographicalScope(), header.getSerialNumber(), location,
header.getServiceCategory(), language, sb.toString(), priority,
- header.getEtwsInfo(), header.getCmasInfo(), slotIndex);
+ header.getEtwsInfo(), header.getCmasInfo(), slotIndex, subId);
}
}
diff --git a/tests/src/com/android/cellbroadcastservice/CellBroadcastHandlerTest.java b/tests/src/com/android/cellbroadcastservice/CellBroadcastHandlerTest.java
index 22c76b5..a9658cd 100644
--- a/tests/src/com/android/cellbroadcastservice/CellBroadcastHandlerTest.java
+++ b/tests/src/com/android/cellbroadcastservice/CellBroadcastHandlerTest.java
@@ -65,6 +65,7 @@
mc.addRow(new Object[]{
1, // _ID
0, // SLOT_INDEX
+ 1, // SUB_ID
0, // GEOGRAPHICAL_SCOPE
"311480", // PLMN
0, // LAC
@@ -128,7 +129,7 @@
return new SmsCbMessage(SmsCbMessage.MESSAGE_FORMAT_3GPP,
0, serialNumber, new SmsCbLocation(),
serviceCategory, "en", messageBody, 3,
- null, null, 0);
+ null, null, 0, 1);
}
@Test
diff --git a/tests/src/com/android/cellbroadcastservice/GsmCellBroadcastHandlerTest.java b/tests/src/com/android/cellbroadcastservice/GsmCellBroadcastHandlerTest.java
index a37772f..5df26f2 100644
--- a/tests/src/com/android/cellbroadcastservice/GsmCellBroadcastHandlerTest.java
+++ b/tests/src/com/android/cellbroadcastservice/GsmCellBroadcastHandlerTest.java
@@ -33,7 +33,6 @@
import android.provider.Settings;
import android.provider.Telephony;
import android.telephony.SmsCbCmasInfo;
-import android.telephony.SmsCbLocation;
import android.telephony.SmsCbMessage;
import android.test.mock.MockContentProvider;
import android.test.mock.MockContentResolver;
@@ -77,6 +76,7 @@
mc.addRow(new Object[]{
1, // _ID
0, // SLOT_INDEX
+ 1, // SUB_ID
0, // GEOGRAPHICAL_SCOPE
"311480", // PLMN
0, // LAC
@@ -159,14 +159,6 @@
super.tearDown();
}
- private SmsCbMessage createSmsCbMessage(int serialNumber, int serviceCategory,
- String messageBody) {
- return new SmsCbMessage(SmsCbMessage.MESSAGE_FORMAT_3GPP,
- 0, serialNumber, new SmsCbLocation(),
- serviceCategory, "en", messageBody, 3,
- null, null, 0);
- }
-
@Test
@SmallTest
public void testTriggerMessage() throws Exception {