Apply roaming resources for the alert behaviors
Bug: 311384456
Test: Manual
Test: atest CellBroadcastReceiverOemUnitTests
Change-Id: Ic5c9bdb1906a1e6ea256c981e1494b80b1be29ef
diff --git a/src/com/android/cellbroadcastreceiver/CellBroadcastAlertAudio.java b/src/com/android/cellbroadcastreceiver/CellBroadcastAlertAudio.java
index 3c060e9..bc0c019 100644
--- a/src/com/android/cellbroadcastreceiver/CellBroadcastAlertAudio.java
+++ b/src/com/android/cellbroadcastreceiver/CellBroadcastAlertAudio.java
@@ -389,7 +389,8 @@
// retrieve the vibration patterns.
mVibrationPattern = intent.getIntArrayExtra(ALERT_AUDIO_VIBRATION_PATTERN_EXTRA);
- Resources res = CellBroadcastSettings.getResources(getApplicationContext(), mSubId);
+ Resources res = CellBroadcastSettings.getResourcesByOperator(getApplicationContext(),
+ mSubId, CellBroadcastReceiver.getRoamingOperatorSupported(getApplicationContext()));
mEnableLedFlash = res.getBoolean(R.bool.enable_led_flash);
// retrieve the customized alert duration. -1 means play the alert with the tone's duration.
@@ -463,7 +464,8 @@
log("playAlertTone: alertType=" + alertType + ", mEnableVibrate=" + mEnableVibrate
+ ", mEnableAudio=" + mEnableAudio + ", mOverrideDnd=" + mOverrideDnd
+ ", mSubId=" + mSubId);
- Resources res = CellBroadcastSettings.getResources(getApplicationContext(), mSubId);
+ Resources res = CellBroadcastSettings.getResourcesByOperator(getApplicationContext(),
+ mSubId, CellBroadcastReceiver.getRoamingOperatorSupported(getApplicationContext()));
// Vibration duration in milliseconds
long vibrateDuration = 0;
diff --git a/src/com/android/cellbroadcastreceiver/CellBroadcastAlertDialog.java b/src/com/android/cellbroadcastreceiver/CellBroadcastAlertDialog.java
index e78db57..892b7f6 100644
--- a/src/com/android/cellbroadcastreceiver/CellBroadcastAlertDialog.java
+++ b/src/com/android/cellbroadcastreceiver/CellBroadcastAlertDialog.java
@@ -269,8 +269,11 @@
private boolean initDrawableAndImageView(int subId) {
if (mWarningIcon == null) {
try {
- mWarningIcon = CellBroadcastSettings.getResources(getApplicationContext(),
- subId).getDrawable(R.drawable.ic_warning_googred);
+ mWarningIcon = CellBroadcastSettings.getResourcesByOperator(
+ getApplicationContext(), subId,
+ CellBroadcastReceiver
+ .getRoamingOperatorSupported(getApplicationContext()))
+ .getDrawable(R.drawable.ic_warning_googred);
} catch (Resources.NotFoundException e) {
CellBroadcastReceiverMetrics.getInstance().logModuleError(
ERRSRC_CBR, ERRTYPE_ICONRESOURCE);
@@ -578,8 +581,9 @@
updateAlertText(message);
- Resources res = CellBroadcastSettings.getResources(getApplicationContext(),
- message.getSubscriptionId());
+ Resources res = CellBroadcastSettings.getResourcesByOperator(getApplicationContext(),
+ message.getSubscriptionId(),
+ CellBroadcastReceiver.getRoamingOperatorSupported(getApplicationContext()));
if (res.getBoolean(R.bool.enable_text_copy)) {
TextView textView = findViewById(R.id.message);
if (textView != null) {
@@ -732,7 +736,8 @@
* @return The link method
*/
private @LinkMethod int getLinkMethod(int subId) {
- Resources res = CellBroadcastSettings.getResources(getApplicationContext(), subId);
+ Resources res = CellBroadcastSettings.getResourcesByOperator(getApplicationContext(),
+ subId, CellBroadcastReceiver.getRoamingOperatorSupported(getApplicationContext()));
switch (res.getString(R.string.link_method)) {
case LINK_METHOD_NONE_STRING: return LINK_METHOD_NONE;
case LINK_METHOD_LEGACY_LINKIFY_STRING: return LINK_METHOD_LEGACY_LINKIFY;
@@ -1202,8 +1207,10 @@
public boolean onKeyDown(int keyCode, KeyEvent event) {
Log.d(TAG, "onKeyDown: " + event);
SmsCbMessage message = getLatestMessage();
- if (message != null && CellBroadcastSettings.getResources(getApplicationContext(),
- message.getSubscriptionId()).getBoolean(R.bool.mute_by_physical_button)) {
+ if (message != null && CellBroadcastSettings.getResourcesByOperator(getApplicationContext(),
+ message.getSubscriptionId(),
+ CellBroadcastReceiver.getRoamingOperatorSupported(getApplicationContext()))
+ .getBoolean(R.bool.mute_by_physical_button)) {
switch (event.getKeyCode()) {
// Volume keys and camera keys mute the alert sound/vibration (except ETWS).
case KeyEvent.KEYCODE_VOLUME_UP:
@@ -1251,7 +1258,8 @@
* @return true if the device is configured to never show the opt out dialog for the mcc/mnc
*/
private boolean neverShowOptOutDialog(int subId) {
- return CellBroadcastSettings.getResources(getApplicationContext(), subId)
+ return CellBroadcastSettings.getResourcesByOperator(getApplicationContext(), subId,
+ CellBroadcastReceiver.getRoamingOperatorSupported(getApplicationContext()))
.getBoolean(R.bool.disable_opt_out_dialog);
}
@@ -1269,8 +1277,10 @@
cm.setPrimaryClip(ClipData.newPlainText("Alert Message", message.getMessageBody()));
- String msg = CellBroadcastSettings.getResources(context,
- message.getSubscriptionId()).getString(R.string.message_copied);
+ String msg = CellBroadcastSettings.getResourcesByOperator(context,
+ message.getSubscriptionId(),
+ CellBroadcastReceiver.getRoamingOperatorSupported(context))
+ .getString(R.string.message_copied);
Toast.makeText(context, msg, Toast.LENGTH_SHORT).show();
return true;
}
diff --git a/src/com/android/cellbroadcastreceiver/CellBroadcastAlertReminder.java b/src/com/android/cellbroadcastreceiver/CellBroadcastAlertReminder.java
index 0868674..bb2cebe 100644
--- a/src/com/android/cellbroadcastreceiver/CellBroadcastAlertReminder.java
+++ b/src/com/android/cellbroadcastreceiver/CellBroadcastAlertReminder.java
@@ -180,7 +180,8 @@
}
if (firstTime) {
- Resources res = CellBroadcastSettings.getResources(context, subId);
+ Resources res = CellBroadcastSettings.getResourcesByOperator(context, subId,
+ CellBroadcastReceiver.getRoamingOperatorSupported(context));
int interval = res.getInteger(R.integer.first_reminder_interval_in_min);
// If there is first reminder interval configured, use it.
if (interval != 0) {
diff --git a/src/com/android/cellbroadcastreceiver/CellBroadcastAlertService.java b/src/com/android/cellbroadcastreceiver/CellBroadcastAlertService.java
index ae0c058..0f9a5ed 100644
--- a/src/com/android/cellbroadcastreceiver/CellBroadcastAlertService.java
+++ b/src/com/android/cellbroadcastreceiver/CellBroadcastAlertService.java
@@ -251,8 +251,10 @@
TelephonyManager tm = ((TelephonyManager) mContext.getSystemService(
Context.TELEPHONY_SERVICE)).createForSubscriptionId(message.getSubscriptionId());
- if (tm.getEmergencyCallbackMode() && CellBroadcastSettings.getResources(
- mContext, message.getSubscriptionId()).getBoolean(R.bool.ignore_messages_in_ecbm)) {
+ if (tm.getEmergencyCallbackMode() && CellBroadcastSettings.getResourcesByOperator(
+ mContext, message.getSubscriptionId(),
+ CellBroadcastReceiver.getRoamingOperatorSupported(mContext))
+ .getBoolean(R.bool.ignore_messages_in_ecbm)) {
// Ignore the message in ECBM.
// It is for LTE only mode. For 1xRTT, incoming pages should be ignored in the modem.
Log.d(TAG, "ignoring alert of type " + message.getServiceCategory() + " in ECBM");
@@ -456,7 +458,8 @@
}
if (mTelephonyManager.getCallState() != TelephonyManager.CALL_STATE_IDLE
- && CellBroadcastSettings.getResources(mContext, cbm.getSubscriptionId())
+ && CellBroadcastSettings.getResourcesByOperator(mContext, cbm.getSubscriptionId(),
+ CellBroadcastReceiver.getRoamingOperatorSupported(mContext))
.getBoolean(R.bool.enable_alert_handling_during_call)) {
Log.d(TAG, "CMAS received in dialing/during voicecall.");
sRemindAfterCallFinish = true;
@@ -688,7 +691,9 @@
CellBroadcastAlertAudio.ALERT_AUDIO_VIBRATION_PATTERN_EXTRA,
(range != null)
? range.mVibrationPattern
- : CellBroadcastSettings.getResources(mContext, message.getSubscriptionId())
+ : CellBroadcastSettings.getResourcesByOperator(mContext,
+ message.getSubscriptionId(),
+ CellBroadcastReceiver.getRoamingOperatorSupported(mContext))
.getIntArray(R.array.default_vibration_pattern));
// read key_override_dnd only when the toggle is visible.
// range.mOverrideDnd is per channel configuration. override_dnd is the main config
@@ -779,7 +784,9 @@
static void addToNotificationBar(SmsCbMessage message,
ArrayList<SmsCbMessage> messageList, Context context,
boolean fromSaveState, boolean shouldAlert, boolean fromDialog) {
- Resources res = CellBroadcastSettings.getResources(context, message.getSubscriptionId());
+ Resources res = CellBroadcastSettings.getResourcesByOperator(context,
+ message.getSubscriptionId(),
+ CellBroadcastReceiver.getRoamingOperatorSupported(context));
int channelTitleId = CellBroadcastResources.getDialogTitleResource(context, message);
CharSequence channelName = context.getText(channelTitleId);
String messageBody = message.getMessageBody();
diff --git a/src/com/android/cellbroadcastreceiver/CellBroadcastContentProvider.java b/src/com/android/cellbroadcastreceiver/CellBroadcastContentProvider.java
index f5c2322..6b1dadc 100644
--- a/src/com/android/cellbroadcastreceiver/CellBroadcastContentProvider.java
+++ b/src/com/android/cellbroadcastreceiver/CellBroadcastContentProvider.java
@@ -481,7 +481,8 @@
CellBroadcastResources.getSmsSenderAddressResourceEnglishString(context, message));
cv.put(Telephony.Sms.Inbox.THREAD_ID, Telephony.Threads.getOrCreateThreadId(context,
CellBroadcastResources.getSmsSenderAddressResourceEnglishString(context, message)));
- if (CellBroadcastSettings.getResources(context, message.getSubscriptionId())
+ if (CellBroadcastSettings.getResourcesByOperator(context, message.getSubscriptionId(),
+ CellBroadcastReceiver.getRoamingOperatorSupported(context))
.getBoolean(R.bool.always_mark_sms_read)) {
// Always mark SMS message READ. End users expect when they read new CBS messages,
// the unread alert count in the notification should be decreased, as they thought it
diff --git a/tests/unit/src/com/android/cellbroadcastreceiver/unit/CellBroadcastAlertDialogTest.java b/tests/unit/src/com/android/cellbroadcastreceiver/unit/CellBroadcastAlertDialogTest.java
index 63c124c..5f30142 100644
--- a/tests/unit/src/com/android/cellbroadcastreceiver/unit/CellBroadcastAlertDialogTest.java
+++ b/tests/unit/src/com/android/cellbroadcastreceiver/unit/CellBroadcastAlertDialogTest.java
@@ -729,6 +729,7 @@
mContext.injectSharedPreferences(mockSharedPreferences);
Resources mockResources2 = mock(Resources.class);
doReturn(false).when(mockResources2).getBoolean(R.bool.show_alert_title);
+ doReturn("none").when(mockResources2).getString(R.string.link_method);
CellBroadcastSettings.sResourcesCacheByOperator.put("334090", mockResources2);
diff --git a/tests/unit/src/com/android/cellbroadcastreceiver/unit/CellBroadcastReceiverTest.java b/tests/unit/src/com/android/cellbroadcastreceiver/unit/CellBroadcastReceiverTest.java
index 10ae3ad..76088c7 100644
--- a/tests/unit/src/com/android/cellbroadcastreceiver/unit/CellBroadcastReceiverTest.java
+++ b/tests/unit/src/com/android/cellbroadcastreceiver/unit/CellBroadcastReceiverTest.java
@@ -18,6 +18,9 @@
import static com.google.common.truth.Truth.assertThat;
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyInt;
@@ -25,6 +28,7 @@
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
@@ -38,12 +42,14 @@
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
+import android.content.res.Resources;
import android.media.AudioDeviceInfo;
import android.os.RemoteException;
import android.os.UserManager;
import android.provider.Telephony;
import android.telephony.CarrierConfigManager;
import android.telephony.ServiceState;
+import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import android.telephony.cdma.CdmaSmsCbProgramData;
@@ -698,6 +704,54 @@
}
@Test
+ public void testResourceOnRoamingState() throws RemoteException {
+ int subId = SubscriptionManager.DEFAULT_SUBSCRIPTION_ID;
+
+ doReturn(subId).when(mSubService).getDefaultSubId();
+ doReturn(subId).when(mSubService).getDefaultSmsSubId();
+
+ SubscriptionInfo mockSubInfo = mock(SubscriptionInfo.class);
+ doReturn(mockSubInfo).when(mSubscriptionManager).getActiveSubscriptionInfo(anyInt());
+ Context newContext = mock(Context.class);
+ Resources roamingResource = mock(Resources.class);
+ doReturn(newContext).when(mContext).createConfigurationContext(any());
+ doReturn(roamingResource).when(newContext).getResources();
+
+ doReturn(false).when(mResources).getBoolean(R.bool.enable_led_flash);
+ doReturn(true).when(roamingResource).getBoolean(R.bool.enable_led_flash);
+
+ Resources res = CellBroadcastSettings.getResourcesByOperator(mContext, subId, "");
+ assertFalse(res.getBoolean(R.bool.enable_led_flash));
+ res = CellBroadcastSettings.getResourcesByOperator(mContext, subId, "530");
+ assertTrue(res.getBoolean(R.bool.enable_led_flash));
+
+ int[] mexico_vib_pattern = {0, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500,
+ 500, 500, 500, 500, 500};
+ int[] normal_vib_pattern = {0, 2000, 500, 1000, 500, 1000, 500, 2000, 500, 1000, 500, 1000};
+
+ doReturn(normal_vib_pattern).when(mResources)
+ .getIntArray(R.array.default_vibration_pattern);
+ doReturn(mexico_vib_pattern).when(roamingResource)
+ .getIntArray(R.array.default_vibration_pattern);
+
+ res = CellBroadcastSettings.getResourcesByOperator(mContext, subId, "");
+ assertArrayEquals(res.getIntArray(R.array.default_vibration_pattern), normal_vib_pattern);
+ mFakeSharedPreferences.putString("roaming_operator_supported", "334");
+ res = CellBroadcastSettings.getResourcesByOperator(mContext, subId, "334");
+ assertArrayEquals(res.getIntArray(R.array.default_vibration_pattern), mexico_vib_pattern);
+
+ doReturn(false).when(mResources)
+ .getBoolean(R.bool.mute_by_physical_button);
+ doReturn(true).when(roamingResource)
+ .getBoolean(R.bool.mute_by_physical_button);
+
+ res = CellBroadcastSettings.getResourcesByOperator(mContext, subId, "");
+ assertFalse(res.getBoolean(R.bool.mute_by_physical_button));
+ res = CellBroadcastSettings.getResourcesByOperator(mContext, subId, "730");
+ assertTrue(res.getBoolean(R.bool.mute_by_physical_button));
+ }
+
+ @Test
public void testGetMccMap() {
final String[] mccArray = new String[] {
//valid values