summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTreeHugger Robot <treehugger-gerrit@google.com>2017-05-10 09:25:18 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2017-05-10 09:25:19 +0000
commitb7611fe3663a97a4b74d2863c04dde46186562c9 (patch)
tree9d6e27f8901a53c8d56eda4a4dc94a2389fd5f6d /src
parent367ac95a2d64d9478545dc8e9d374a4dc02939c5 (diff)
parentc0b14d78069804ac31f68852341a2ce220a58324 (diff)
downloadandroid_packages_apps_CellBroadcastReceiver-b7611fe3663a97a4b74d2863c04dde46186562c9.tar.gz
android_packages_apps_CellBroadcastReceiver-b7611fe3663a97a4b74d2863c04dde46186562c9.tar.bz2
android_packages_apps_CellBroadcastReceiver-b7611fe3663a97a4b74d2863c04dde46186562c9.zip
Merge "Do not allow messages on additional channels when roaming"
Diffstat (limited to 'src')
-rw-r--r--src/com/android/cellbroadcastreceiver/CellBroadcastAlertService.java66
1 files changed, 52 insertions, 14 deletions
diff --git a/src/com/android/cellbroadcastreceiver/CellBroadcastAlertService.java b/src/com/android/cellbroadcastreceiver/CellBroadcastAlertService.java
index 9dfbc18f..f7efbf00 100644
--- a/src/com/android/cellbroadcastreceiver/CellBroadcastAlertService.java
+++ b/src/com/android/cellbroadcastreceiver/CellBroadcastAlertService.java
@@ -44,6 +44,7 @@ import android.telephony.SmsCbEtwsInfo;
import android.telephony.SmsCbLocation;
import android.telephony.SmsCbMessage;
import android.telephony.SubscriptionManager;
+import android.telephony.TelephonyManager;
import android.util.Log;
import com.android.cellbroadcastreceiver.CellBroadcastAlertAudio.ToneType;
@@ -332,6 +333,24 @@ public class CellBroadcastAlertService extends Service {
}
/**
+ * Check if the device is currently on roaming.
+ *
+ * @param subId Subscription index
+ * @return True if roaming, otherwise not roaming.
+ */
+ private boolean isRoaming(int subId) {
+ Context context = getApplicationContext();
+
+ if (context != null) {
+ TelephonyManager tm =
+ (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
+ return tm.isNetworkRoaming(subId);
+ }
+
+ return false;
+ }
+
+ /**
* Filter out broadcasts on the test channels that the user has not enabled,
* and types of notifications that the user is not interested in receiving.
* This allows us to enable an entire range of message identifiers in the
@@ -368,6 +387,39 @@ public class CellBroadcastAlertService extends Service {
}
+ int channel = message.getServiceCategory();
+
+ if (channel == SmsCbConstants.MESSAGE_ID_GSMA_ALLOCATED_CHANNEL_50) {
+ // save latest area info broadcast for Settings display and send as broadcast
+ CellBroadcastReceiverApp.setLatestAreaInfo(message);
+ Intent intent = new Intent(CB_AREA_INFO_RECEIVED_ACTION);
+ intent.putExtra(EXTRA_MESSAGE, message);
+ // Send broadcast twice, once for apps that have PRIVILEGED permission and once
+ // for those that have the runtime one
+ sendBroadcastAsUser(intent, UserHandle.ALL,
+ android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE);
+ sendBroadcastAsUser(intent, UserHandle.ALL,
+ android.Manifest.permission.READ_PHONE_STATE);
+ return false; // area info broadcasts are displayed in Settings status screen
+ }
+
+ // Check if the messages are on additional channels enabled by the resource config.
+ // If those channels are enabled by the carrier, but the device is actually roaming, we
+ // should not allow the messages.
+ ArrayList<CellBroadcastChannelRange> ranges = CellBroadcastChannelManager
+ .getInstance().getCellBroadcastChannelRanges(getApplicationContext());
+
+ if (ranges != null) {
+ for (CellBroadcastChannelRange range : ranges) {
+ if (range.mStartId <= channel && range.mEndId >= channel) {
+ // We only enable the channels when the device is not roaming.
+ if (isRoaming(message.getSubId())) {
+ return false;
+ }
+ }
+ }
+ }
+
if (message.isCmasMessage()) {
switch (message.getCmasMessageClass()) {
case SmsCbCmasInfo.CMAS_CLASS_EXTREME_THREAT:
@@ -398,20 +450,6 @@ public class CellBroadcastAlertService extends Service {
}
}
- if (message.getServiceCategory() == SmsCbConstants.MESSAGE_ID_GSMA_ALLOCATED_CHANNEL_50) {
- // save latest area info broadcast for Settings display and send as broadcast
- CellBroadcastReceiverApp.setLatestAreaInfo(message);
- Intent intent = new Intent(CB_AREA_INFO_RECEIVED_ACTION);
- intent.putExtra(EXTRA_MESSAGE, message);
- // Send broadcast twice, once for apps that have PRIVILEGED permission and once
- // for those that have the runtime one
- sendBroadcastAsUser(intent, UserHandle.ALL,
- android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE);
- sendBroadcastAsUser(intent, UserHandle.ALL,
- android.Manifest.permission.READ_PHONE_STATE);
- return false; // area info broadcasts are displayed in Settings status screen
- }
-
return true; // other broadcast messages are always enabled
}