diff options
14 files changed, 149 insertions, 14 deletions
diff --git a/res/values-mcc424/config.xml b/res/values-mcc424/config.xml index 6bc24815c..899b6d409 100644 --- a/res/values-mcc424/config.xml +++ b/res/values-mcc424/config.xml @@ -30,4 +30,7 @@ </string-array> <string-array name="cmas_amber_alerts_channels_range_strings" translatable="false"> </string-array> + <!-- Whether to always receive exercise alerts regardless of test alerts toggle state --> + <!-- By default it's true for United Arab Emirates users --> + <bool name="always_enable_exercise_alert">true</bool> </resources> diff --git a/res/values-mcc440-mnc00/config.xml b/res/values-mcc440-mnc00/config.xml new file mode 100644 index 000000000..73f57de7f --- /dev/null +++ b/res/values-mcc440-mnc00/config.xml @@ -0,0 +1,20 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2019 The Android Open Source Project + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> + +<resources> + <!-- Whether to show test settings --> + <bool name="show_test_settings">false</bool> +</resources>
\ No newline at end of file diff --git a/res/values-mcc440-mnc20/config.xml b/res/values-mcc440-mnc20/config.xml index 901d61743..9b055a267 100644 --- a/res/values-mcc440-mnc20/config.xml +++ b/res/values-mcc440-mnc20/config.xml @@ -22,4 +22,6 @@ <item>0xA802:type=test, emergency=true, scope=carrier</item> <item>0xA804:type=test, emergency=true, scope=carrier</item> </string-array> + <!-- Whether to show test settings --> + <bool name="show_test_settings">false</bool> </resources> diff --git a/res/values-mcc441-mnc00/config.xml b/res/values-mcc441-mnc00/config.xml new file mode 100644 index 000000000..73f57de7f --- /dev/null +++ b/res/values-mcc441-mnc00/config.xml @@ -0,0 +1,20 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2019 The Android Open Source Project + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> + +<resources> + <!-- Whether to show test settings --> + <bool name="show_test_settings">false</bool> +</resources>
\ No newline at end of file diff --git a/res/values-mcc441-mnc20/config.xml b/res/values-mcc441-mnc20/config.xml new file mode 100644 index 000000000..73f57de7f --- /dev/null +++ b/res/values-mcc441-mnc20/config.xml @@ -0,0 +1,20 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2019 The Android Open Source Project + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> + +<resources> + <!-- Whether to show test settings --> + <bool name="show_test_settings">false</bool> +</resources>
\ No newline at end of file diff --git a/res/values/config.xml b/res/values/config.xml index b6314d14b..d4cd94b57 100644 --- a/res/values/config.xml +++ b/res/values/config.xml @@ -19,6 +19,8 @@ <bool name="use_full_volume">false</bool> <!-- Whether to enable CMAS settings (United States) --> <bool name="show_cmas_settings">true</bool> + <!-- Whether to show test settings --> + <bool name="show_test_settings">true</bool> <!-- Whether to append date-time to the alert title --> <bool name="show_date_time_title">false</bool> <!-- Emergecny alert tone duration in milliseconds. -1 indicates playing the tone with the tone's duration --> @@ -37,6 +39,8 @@ <bool name="show_public_safety_settings">true</bool> <!-- Whether to bypass Do-Not-Disturb/silent mode and play emergency alert tone at full volume for presidential alert --> <bool name="full_volume_presidential_alert">false</bool> + <!-- Whether to bypass test alert settings and always enable exercise alert channel --> + <bool name="always_enable_exercise_alert">false</bool> <!-- 4370, 4383 --> <string-array name="cmas_presidential_alerts_channels_range_strings" translatable="false"> <item>0x1112:rat=gsm, emergency=true</item> diff --git a/src/com/android/cellbroadcastreceiver/CellBroadcastAlertService.java b/src/com/android/cellbroadcastreceiver/CellBroadcastAlertService.java index 0a04dd0b9..b6406344d 100644 --- a/src/com/android/cellbroadcastreceiver/CellBroadcastAlertService.java +++ b/src/com/android/cellbroadcastreceiver/CellBroadcastAlertService.java @@ -371,6 +371,12 @@ public class CellBroadcastAlertService extends Service { } if (channelManager.checkCellBroadcastChannelRange(channel, + R.array.exercise_alert_range_strings) + && getResources().getBoolean(R.bool.always_enable_exercise_alert)) { + return true; + } + + if (channelManager.checkCellBroadcastChannelRange(channel, R.array.required_monthly_test_range_strings) || channelManager.checkCellBroadcastChannelRange(channel, R.array.exercise_alert_range_strings) diff --git a/src/com/android/cellbroadcastreceiver/CellBroadcastConfigService.java b/src/com/android/cellbroadcastreceiver/CellBroadcastConfigService.java index ac5503310..f20634a77 100644 --- a/src/com/android/cellbroadcastreceiver/CellBroadcastConfigService.java +++ b/src/com/android/cellbroadcastreceiver/CellBroadcastConfigService.java @@ -103,6 +103,7 @@ public class CellBroadcastConfigService extends IntentService { public void enableCellBroadcastChannels(int subId) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); + Resources res = CellBroadcastSettings.getResources(this, subId); // boolean for each user preference checkbox, true for checked, false for unchecked // Note: If enableAlertsMasterToggle is false, it disables ALL emergency broadcasts @@ -192,9 +193,13 @@ public class CellBroadcastConfigService extends IntentService { channelManager.getCellBroadcastChannelRanges( R.array.required_monthly_test_range_strings)); - setCellBroadcastRange(subId, enableTestAlerts, + // Exercise is part of test toggle with monthly test and operator defined. some carriers + // mandate to show test settings in UI but always enable exercise alert. + setCellBroadcastRange(subId, enableTestAlerts || + res.getBoolean(R.bool.always_enable_exercise_alert), channelManager.getCellBroadcastChannelRanges( R.array.exercise_alert_range_strings)); + setCellBroadcastRange(subId, enableTestAlerts, channelManager.getCellBroadcastChannelRanges( R.array.operator_defined_alert_range_strings)); diff --git a/src/com/android/cellbroadcastreceiver/CellBroadcastSearchIndexableProvider.java b/src/com/android/cellbroadcastreceiver/CellBroadcastSearchIndexableProvider.java index 2134e4631..676af0154 100644 --- a/src/com/android/cellbroadcastreceiver/CellBroadcastSearchIndexableProvider.java +++ b/src/com/android/cellbroadcastreceiver/CellBroadcastSearchIndexableProvider.java @@ -229,6 +229,13 @@ public class CellBroadcastSearchIndexableProvider extends SearchIndexablesProvid cursor.addRow(ref); } + if (!CellBroadcastSettings.isTestAlertsToggleVisible(getContext())) { + ref = new Object[1]; + ref[COLUMN_INDEX_NON_INDEXABLE_KEYS_KEY_VALUE] = + CellBroadcastSettings.KEY_ENABLE_TEST_ALERTS; + cursor.addRow(ref); + } + return cursor; } } diff --git a/src/com/android/cellbroadcastreceiver/CellBroadcastSettings.java b/src/com/android/cellbroadcastreceiver/CellBroadcastSettings.java index 67f23f6db..e3424349b 100644 --- a/src/com/android/cellbroadcastreceiver/CellBroadcastSettings.java +++ b/src/com/android/cellbroadcastreceiver/CellBroadcastSettings.java @@ -320,23 +320,11 @@ public class CellBroadcastSettings extends Activity { if (mMasterToggle != null) preferenceScreen.removePreference(mMasterToggle); } - boolean hideTestAlertMenu = CellBroadcastSettings.isFeatureEnabled(getContext(), - CarrierConfigManager.KEY_CARRIER_FORCE_DISABLE_ETWS_CMAS_TEST_BOOL, false); - CellBroadcastChannelManager channelManager = new CellBroadcastChannelManager( getContext(), SubscriptionManager.DEFAULT_SUBSCRIPTION_ID); - boolean isTestAlertsAvailable = !channelManager.getCellBroadcastChannelRanges( - R.array.required_monthly_test_range_strings).isEmpty() - || !channelManager.getCellBroadcastChannelRanges( - R.array.exercise_alert_range_strings).isEmpty() - || !channelManager.getCellBroadcastChannelRanges( - R.array.operator_defined_alert_range_strings).isEmpty() - || !channelManager.getCellBroadcastChannelRanges( - R.array.etws_test_alerts_range_strings).isEmpty(); - // Check if we want to hide the test alert toggle. - if (hideTestAlertMenu || !enableDevSettings || !isTestAlertsAvailable) { + if (!isTestAlertsToggleVisible(getContext())) { if (mTestCheckBox != null) { mAlertCategory.removePreference(mTestCheckBox); } @@ -550,6 +538,23 @@ public class CellBroadcastSettings extends Activity { } } + public static boolean isTestAlertsToggleVisible(Context context) { + CellBroadcastChannelManager channelManager = new CellBroadcastChannelManager(context, + SubscriptionManager.DEFAULT_SUBSCRIPTION_ID); + Resources res = CellBroadcastSettings.getResources(context, + SubscriptionManager.DEFAULT_SUBSCRIPTION_ID); + boolean isTestAlertsAvailable = !channelManager.getCellBroadcastChannelRanges( + R.array.required_monthly_test_range_strings).isEmpty() + || !channelManager.getCellBroadcastChannelRanges( + R.array.exercise_alert_range_strings).isEmpty() + || !channelManager.getCellBroadcastChannelRanges( + R.array.operator_defined_alert_range_strings).isEmpty() + || !channelManager.getCellBroadcastChannelRanges( + R.array.etws_test_alerts_range_strings).isEmpty(); + + return res.getBoolean(R.bool.show_test_settings) && isTestAlertsAvailable; + } + public static boolean isFeatureEnabled(Context context, String feature, boolean defaultValue) { CarrierConfigManager configManager = (CarrierConfigManager) context.getSystemService(Context.CARRIER_CONFIG_SERVICE); diff --git a/tests/testapp/res/layout/test_buttons.xml b/tests/testapp/res/layout/test_buttons.xml index f47b8d112..75c76df1d 100644 --- a/tests/testapp/res/layout/test_buttons.xml +++ b/tests/testapp/res/layout/test_buttons.xml @@ -175,6 +175,12 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" /> + <Button android:id="@+id/button_gsm_cmas_exercise_test" + android:text="@string/button_gsm_cmas_exercise_test" + android:layout_marginLeft="20dp" + android:layout_width="wrap_content" + android:layout_height="wrap_content" /> + <Button android:id="@+id/button_gsm_public_safety_message" android:text="@string/button_gsm_public_safety_message" android:layout_marginLeft="20dp" diff --git a/tests/testapp/res/values/strings.xml b/tests/testapp/res/values/strings.xml index a2847750f..5748c9026 100644 --- a/tests/testapp/res/values/strings.xml +++ b/tests/testapp/res/values/strings.xml @@ -32,6 +32,7 @@ <string name="button_gsm_cmas_severe_alert" translatable="false">Send GSM CMAS Severe Alert</string> <string name="button_gsm_cmas_amber_alert" translatable="false">Send GSM CMAS AMBER Alert</string> <string name="button_gsm_cmas_monthly_test" translatable="false">Send GSM CMAS Monthly Test Alert</string> + <string name="button_gsm_cmas_exercise_test" translatable="false">Send GSM CMAS Exercise Test Alert</string> <string name="button_gsm_public_safety_message" translatable="false">Send GSM Public Safety Message</string> <string name="button_gsm_state_local_test_alert" translatable="false">Send State/Local Test Alert</string> <string name="button_gsm_7bit_type" translatable="false">Send GSM 7 Bit Test Broadcast</string> diff --git a/tests/testapp/src/com/android/cellbroadcastreceiver/tests/SendGsmCmasMessages.java b/tests/testapp/src/com/android/cellbroadcastreceiver/tests/SendGsmCmasMessages.java index 5a3d0b993..64a770887 100644 --- a/tests/testapp/src/com/android/cellbroadcastreceiver/tests/SendGsmCmasMessages.java +++ b/tests/testapp/src/com/android/cellbroadcastreceiver/tests/SendGsmCmasMessages.java @@ -158,6 +158,25 @@ public class SendGsmCmasMessages { sendBroadcast(activity, cbMessage); } + public static void testSendCmasExerciseTest( + Activity activity, int serialNumber, boolean isAdditionalLang) { + SmsCbMessage cbMessage = + createCmasSmsMessage( + isAdditionalLang + ? SmsCbConstants + .MESSAGE_ID_CMAS_ALERT_EXERCISE_LANGUAGE + : SmsCbConstants.MESSAGE_ID_CMAS_ALERT_EXERCISE, + serialNumber, + "en", + MONTHLY_TEST_ALERT, + SmsCbCmasInfo.CMAS_SEVERITY_UNKNOWN, + SmsCbCmasInfo.CMAS_URGENCY_UNKNOWN, + SmsCbCmasInfo.CMAS_CERTAINTY_UNKNOWN, + SmsCbMessage.MESSAGE_PRIORITY_EMERGENCY); + + sendBroadcast(activity, cbMessage); + } + public static void testSendPublicSafetyMessagesAlert( Activity activity, int serialNumber, boolean isAdditionalLang) { SmsCbMessage cbMessage = diff --git a/tests/testapp/src/com/android/cellbroadcastreceiver/tests/SendTestBroadcastActivity.java b/tests/testapp/src/com/android/cellbroadcastreceiver/tests/SendTestBroadcastActivity.java index 71484ad4d..8dc063655 100644 --- a/tests/testapp/src/com/android/cellbroadcastreceiver/tests/SendTestBroadcastActivity.java +++ b/tests/testapp/src/com/android/cellbroadcastreceiver/tests/SendTestBroadcastActivity.java @@ -342,6 +342,23 @@ public class SendTestBroadcastActivity extends Activity { } }); + /* Send a GSM CMAS exercise test alert to app. */ + Button GsmCmasExerciseTestButton = findViewById(R.id.button_gsm_cmas_exercise_test); + GsmCmasExerciseTestButton.setOnClickListener( + new OnClickListener() { + public void onClick(View v) { + if (mDelayBeforeSending && v != null) { + Message msg = mDelayHandler.obtainMessage(0, this); + mDelayHandler.sendMessageDelayed(msg, DELAY_BEFORE_SENDING_MSEC); + } else { + SendGsmCmasMessages.testSendCmasExerciseTest( + SendTestBroadcastActivity.this, + getSerialNumber(), + mIsAdditionalLangAlert); + } + } + }); + /* Send a GSM public safety messages to app. */ Button GsmPublicSafetyMessagesAlertTestButton = findViewById( R.id.button_gsm_public_safety_message); |