summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2023-11-05 07:19:10 +0000
committerAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2023-11-05 07:19:10 +0000
commit17b4c311d40c6895559d9d3272415e62f8fd8b41 (patch)
treeecf6ce4931307c2229163b48218006a9a0c91010
parent8d14369391d4130f8b192c6bdd6b8aefd9d60ad8 (diff)
parent25410eb3c4c93094741e1dea15c4fe2f1b52940e (diff)
downloadCellBroadcastReceiver-17b4c311d40c6895559d9d3272415e62f8fd8b41.tar.gz
Snap for 11053320 from 25410eb3c4c93094741e1dea15c4fe2f1b52940e to mainline-rkpd-releaseaml_rkp_341311000
Change-Id: I83a528baecc519065ca1da73c627743248a8cd6c
-rw-r--r--res/values-mcc234-ja/strings.xml2
-rw-r--r--res/values/constants.xml474
-rw-r--r--src/com/android/cellbroadcastreceiver/CellBroadcastBackupAgent.java12
-rw-r--r--src/com/android/cellbroadcastreceiver/CellBroadcastConfigService.java26
-rw-r--r--src/com/android/cellbroadcastreceiver/CellBroadcastListItem.java18
-rw-r--r--src/com/android/cellbroadcastreceiver/CellBroadcastReceiver.java46
-rw-r--r--src/com/android/cellbroadcastreceiver/CellBroadcastReceiverMetrics.java1
-rw-r--r--src/com/android/cellbroadcastreceiver/CellBroadcastSettings.java3
-rw-r--r--tests/unit/src/com/android/cellbroadcastreceiver/unit/CellBroadcastAlertDialogTest.java6
-rw-r--r--tests/unit/src/com/android/cellbroadcastreceiver/unit/CellBroadcastBackupAgentTest.java4
-rw-r--r--tests/unit/src/com/android/cellbroadcastreceiver/unit/CellBroadcastListItemTest.java105
-rw-r--r--tests/unit/src/com/android/cellbroadcastreceiver/unit/CellBroadcastReceiverTest.java64
12 files changed, 728 insertions, 33 deletions
diff --git a/res/values-mcc234-ja/strings.xml b/res/values-mcc234-ja/strings.xml
index 6a7324ab3..93dca043b 100644
--- a/res/values-mcc234-ja/strings.xml
+++ b/res/values-mcc234-ja/strings.xml
@@ -18,7 +18,7 @@
xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<string name="enable_cmas_extreme_threat_alerts_title" msgid="8511466399220042295">"最重要速報メール"</string>
<string name="enable_cmas_severe_threat_alerts_title" msgid="2271741871998936543">"重要速報メール"</string>
- <string name="enable_cmas_test_alerts_title" msgid="6022925848643811044">"テスト速報メール"</string>
+ <string name="enable_cmas_test_alerts_title" msgid="6022925848643811044">"テストアラート"</string>
<string name="enable_exercise_test_alerts_title" msgid="411880452689537935">"訓練用速報メール"</string>
<string name="cmas_presidential_level_alert" msgid="3429191761649839884">"政府機関発の速報メール"</string>
<string name="cmas_extreme_alert" msgid="3474352706075109113">"最重要速報メール"</string>
diff --git a/res/values/constants.xml b/res/values/constants.xml
new file mode 100644
index 000000000..374acf345
--- /dev/null
+++ b/res/values/constants.xml
@@ -0,0 +1,474 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2023 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>
+ <string-array name="iso_country_code_mcc_table" translatable="false">
+ <!-- Greece -->
+ <item>gr:202</item>
+ <!-- Netherlands (Kingdom of the) -->
+ <item>nl:204</item>
+ <!-- Belgium -->
+ <item>be:206</item>
+ <!-- France -->
+ <item>fr:208</item>
+ <!-- Monaco (Principality of) -->
+ <item>mc:212</item>
+ <!-- Andorra (Principality of) -->
+ <item>ad:213</item>
+ <!-- Spain -->
+ <item>es:214</item>
+ <!-- Hungary (Republic of) -->
+ <item>hu:216</item>
+ <!-- Bosnia and Herzegovina -->
+ <item>ba:218</item>
+ <!-- Croatia (Republic of) -->
+ <item>hr:219</item>
+ <!-- Serbia (Republic of) -->
+ <item>rs:220</item>
+ <!-- Kosovo -->
+ <item>xk:221</item>
+ <!-- Italy -->
+ <item>it:222</item>
+ <!-- Vatican City State -->
+ <item>va:225</item>
+ <!-- Romania -->
+ <item>ro:226</item>
+ <!-- Switzerland (Confederation of) -->
+ <item>ch:228</item>
+ <!-- Czechia -->
+ <item>cz:230</item>
+ <!-- Slovak Republic -->
+ <item>sk:231</item>
+ <!-- Austria -->
+ <item>at:232</item>
+ <!-- United Kingdom of Great Britain and Northern Ireland -->
+ <item>gb:234</item>
+ <!-- Denmark -->
+ <item>dk:238</item>
+ <!-- Sweden -->
+ <item>se:240</item>
+ <!-- Norway -->
+ <item>no:242</item>
+ <!-- Finland -->
+ <item>fi:244</item>
+ <!-- Lithuania (Republic of) -->
+ <item>lt:246</item>
+ <!-- Latvia (Republic of) -->
+ <item>lv:247</item>
+ <!-- Estonia (Republic of) -->
+ <item>ee:248</item>
+ <!-- Russian Federation -->
+ <item>ru:250</item>
+ <!-- Ukraine -->
+ <item>ua:255</item>
+ <!-- Belarus (Republic of) -->
+ <item>by:257</item>
+ <!-- Moldova (Republic of) -->
+ <item>md:259</item>
+ <!-- Poland (Republic of) -->
+ <item>pl:260</item>
+ <!-- Germany (Federal Republic of) -->
+ <item>de:262</item>
+ <!-- Gibraltar -->
+ <item>gi:266</item>
+ <!-- Portugal -->
+ <item>pt:268</item>
+ <!-- Luxembourg -->
+ <item>lu:270</item>
+ <!-- Ireland -->
+ <item>ie:272</item>
+ <!-- Iceland -->
+ <item>is:274</item>
+ <!-- Albania (Republic of) -->
+ <item>al:276</item>
+ <!-- Malta -->
+ <item>mt:278</item>
+ <!-- Cyprus (Republic of) -->
+ <item>cy:280</item>
+ <!-- Georgia -->
+ <item>ge:282</item>
+ <!-- Armenia (Republic of) -->
+ <item>am:283</item>
+ <!-- Bulgaria (Republic of) -->
+ <item>bg:284</item>
+ <!-- Turkey -->
+ <item>tr:286</item>
+ <!-- Faroe Islands -->
+ <item>fo:288</item>
+ <!-- Greenland (Denmark) -->
+ <item>gl:290</item>
+ <!-- San Marino (Republic of) -->
+ <item>sm:292</item>
+ <!-- Slovenia (Republic of) -->
+ <item>si:293</item>
+ <!-- The Former Yugoslav Republic of Macedonia -->
+ <item>mk:294</item>
+ <!-- Liechtenstein (Principality of) -->
+ <item>li:295</item>
+ <!-- Montenegro -->
+ <item>me:297</item>
+ <!-- Canada -->
+ <item>ca:302</item>
+ <!-- Saint Pierre and Miquelon (Collectivité territoriale de la République française) -->
+ <item>pm:308</item>
+ <!-- United States of America -->
+ <item>us:310</item>
+ <!-- Puerto Rico -->
+ <item>pr:330</item>
+ <!-- United States Virgin Islands -->
+ <item>vi:332</item>
+ <!-- Mexico -->
+ <item>mx:334</item>
+ <!-- Jamaica -->
+ <item>jm:338</item>
+ <!-- Guadeloupe (French Department of) -->
+ <item>gp:340</item>
+ <!-- Barbados -->
+ <item>bb:342</item>
+ <!-- Antigua and Barbuda -->
+ <item>ag:344</item>
+ <!-- Cayman Islands -->
+ <item>ky:346</item>
+ <!-- British Virgin Islands -->
+ <item>vg:348</item>
+ <!-- Bermuda -->
+ <item>bm:350</item>
+ <!-- Grenada -->
+ <item>gd:352</item>
+ <!-- Montserrat -->
+ <item>ms:354</item>
+ <!-- Saint Kitts and Nevis -->
+ <item>kn:356</item>
+ <!-- Saint Lucia -->
+ <item>lc:358</item>
+ <!-- Saint Vincent and the Grenadines -->
+ <item>vc:360</item>
+ <!-- Curaçao -->
+ <item>cw:362</item>
+ <!-- Aruba -->
+ <item>aw:363</item>
+ <!-- Bahamas (Commonwealth of the) -->
+ <item>bs:364</item>
+ <!-- Anguilla -->
+ <item>ai:365</item>
+ <!-- Dominica (Commonwealth of) -->
+ <item>dm:366</item>
+ <!-- Cuba -->
+ <item>cu:368</item>
+ <!-- Dominican Republic -->
+ <item>do:370</item>
+ <!-- Haiti (Republic of) -->
+ <item>ht:372</item>
+ <!-- Trinidad and Tobago -->
+ <item>tt:374</item>
+ <!-- Turks and Caicos Islands -->
+ <item>tc:376</item>
+ <!-- Azerbaijani Republic -->
+ <item>az:400</item>
+ <!-- Kazakhstan (Republic of) -->
+ <item>kz:401</item>
+ <!-- Bhutan (Kingdom of) -->
+ <item>bt:402</item>
+ <!-- India (Republic of) -->
+ <item>in:404</item>
+ <!-- Pakistan (Islamic Republic of) -->
+ <item>pk:410</item>
+ <!-- Afghanistan -->
+ <item>af:412</item>
+ <!-- Sri Lanka (Democratic Socialist Republic of) -->
+ <item>lk:413</item>
+ <!-- Myanmar (the Republic of the Union of) -->
+ <item>mm:414</item>
+ <!-- Lebanon -->
+ <item>lb:415</item>
+ <!-- Jordan (Hashemite Kingdom of) -->
+ <item>jo:416</item>
+ <!-- Syrian Arab Republic -->
+ <item>sy:417</item>
+ <!-- Iraq (Republic of) -->
+ <item>iq:418</item>
+ <!-- Kuwait (State of) -->
+ <item>kw:419</item>
+ <!-- Saudi Arabia (Kingdom of) -->
+ <item>sa:420</item>
+ <!-- Yemen (Republic of) -->
+ <item>ye:421</item>
+ <!-- Oman (Sultanate of) -->
+ <item>om:422</item>
+ <!-- Palestine (*) -->
+ <item>ps:423</item>
+ <!-- United Arab Emirates -->
+ <item>ae:424</item>
+ <!-- Israel (State of) -->
+ <item>il:425</item>
+ <!-- Bahrain (Kingdom of) -->
+ <item>bh:426</item>
+ <!-- Qatar (State of) -->
+ <item>qa:427</item>
+ <!-- Mongolia -->
+ <item>mn:428</item>
+ <!-- Nepal (Federal Democratic Republic of) -->
+ <item>np:429</item>
+ <!-- Iran (Islamic Republic of) -->
+ <item>ir:432</item>
+ <!-- Uzbekistan (Republic of) -->
+ <item>uz:434</item>
+ <!-- Tajikistan (Republic of) -->
+ <item>tj:436</item>
+ <!-- Kyrgyz Republic -->
+ <item>kg:437</item>
+ <!-- Turkmenistan -->
+ <item>tm:438</item>
+ <!-- Japan -->
+ <item>jp:440</item>
+ <!-- Korea (Republic of) -->
+ <item>kr:450</item>
+ <!-- Viet Nam (Socialist Republic of) -->
+ <item>vn:452</item>
+ <!-- Hong Kong, China -->
+ <item>hk:454</item>
+ <!-- Macao, China -->
+ <item>mo:455</item>
+ <!-- Cambodia (Kingdom of) -->
+ <item>kh:456</item>
+ <!-- Lao People's Democratic Republic -->
+ <item>la:457</item>
+ <!-- China (People's Republic of) -->
+ <item>cn:460</item>
+ <!-- Taiwan, China -->
+ <item>tw:466</item>
+ <!-- Democratic People's Republic of Korea -->
+ <item>kp:467</item>
+ <!-- Bangladesh (People's Republic of) -->
+ <item>bd:470</item>
+ <!-- Maldives (Republic of) -->
+ <item>mv:472</item>
+ <!-- Malaysia -->
+ <item>my:502</item>
+ <!-- Australia -->
+ <item>au:505</item>
+ <!-- Indonesia (Republic of) -->
+ <item>id:510</item>
+ <!-- Timor-Leste (Democratic Republic of) -->
+ <item>tl:514</item>
+ <!-- Philippines (Republic of the) -->
+ <item>ph:515</item>
+ <!-- Thailand -->
+ <item>th:520</item>
+ <!-- Singapore (Republic of) -->
+ <item>sg:525</item>
+ <!-- Brunei Darussalam -->
+ <item>bn:528</item>
+ <!-- New Zealand -->
+ <item>nz:530</item>
+ <!-- Northern Mariana Islands (Commonwealth of the) (*) -->
+ <item>mp:534</item>
+ <!-- Guam (*) -->
+ <item>gu:535</item>
+ <!-- Nauru (Republic of) -->
+ <item>nr:536</item>
+ <!-- Papua New Guinea -->
+ <item>pg:537</item>
+ <!-- Tonga (Kingdom of) -->
+ <item>to:539</item>
+ <!-- Solomon Islands -->
+ <item>sb:540</item>
+ <!-- Vanuatu (Republic of) -->
+ <item>vu:541</item>
+ <!-- Fiji (Republic of) -->
+ <item>fj:542</item>
+ <!-- Wallis and Futuna (Territoire français d'outre-mer) -->
+ <item>wf:543</item>
+ <!-- American Samoa -->
+ <item>as:544</item>
+ <!-- Kiribati (Republic of) -->
+ <item>ki:545</item>
+ <!-- New Caledonia (Territoire français d'outre-mer) -->
+ <item>nc:546</item>
+ <!-- French Polynesia (Territoire français d'outre-mer) -->
+ <item>pf:547</item>
+ <!-- Cook Islands -->
+ <item>ck:548</item>
+ <!-- Samoa (Independent State of) -->
+ <item>ws:549</item>
+ <!-- Micronesia (Federated States of) -->
+ <item>fm:550</item>
+ <!-- Marshall Islands (Republic of the) -->
+ <item>mh:551</item>
+ <!-- Palau (Republic of) -->
+ <item>pw:552</item>
+ <!-- Tuvalu -->
+ <item>tv:553</item>
+ <!-- Tokelau -->
+ <item>tk:554</item>
+ <!-- Niue -->
+ <item>nu:555</item>
+ <!-- Egypt (Arab Republic of) -->
+ <item>eg:602</item>
+ <!-- Algeria (People's Democratic Republic of) -->
+ <item>dz:603</item>
+ <!-- Morocco (Kingdom of) -->
+ <item>ma:604</item>
+ <!-- Tunisia -->
+ <item>tn:605</item>
+ <!-- Libya -->
+ <item>ly:606</item>
+ <!-- Gambia (Republic of the) -->
+ <item>gm:607</item>
+ <!-- Senegal (Republic of) -->
+ <item>sn:608</item>
+ <!-- Mauritania (Islamic Republic of) -->
+ <item>mr:609</item>
+ <!-- Mali (Republic of) -->
+ <item>ml:610</item>
+ <!-- Guinea (Republic of) -->
+ <item>gn:611</item>
+ <!-- Côte d'Ivoire (Republic of) -->
+ <item>ci:612</item>
+ <!-- Burkina Faso -->
+ <item>bf:613</item>
+ <!-- Niger (Republic of the) -->
+ <item>ne:614</item>
+ <!-- Togolese Republic -->
+ <item>tg:615</item>
+ <!-- Benin (Republic of) -->
+ <item>bj:616</item>
+ <!-- Mauritius (Republic of) -->
+ <item>mu:617</item>
+ <!-- Liberia (Republic of) -->
+ <item>lr:618</item>
+ <!-- Sierra Leone -->
+ <item>sl:619</item>
+ <!-- Ghana -->
+ <item>gh:620</item>
+ <!-- Nigeria (Federal Republic of) -->
+ <item>ng:621</item>
+ <!-- Chad (Republic of) -->
+ <item>td:622</item>
+ <!-- Central African Republic -->
+ <item>cf:623</item>
+ <!-- Cameroon (Republic of) -->
+ <item>cm:624</item>
+ <!-- Cape Verde (Republic of) -->
+ <item>cv:625</item>
+ <!-- Sao Tome and Principe (Democratic Republic of) -->
+ <item>st:626</item>
+ <!-- Equatorial Guinea (Republic of) -->
+ <item>gq:627</item>
+ <!-- Gabonese Republic -->
+ <item>ga:628</item>
+ <!-- Congo (Republic of the) -->
+ <item>cg:629</item>
+ <!-- Democratic Republic of the Congo -->
+ <item>cd:630</item>
+ <!-- Angola (Republic of) -->
+ <item>ao:631</item>
+ <!-- Guinea-Bissau (Republic of) -->
+ <item>gw:632</item>
+ <!-- Seychelles (Republic of) -->
+ <item>sc:633</item>
+ <!-- Sudan (Republic of the) -->
+ <item>sd:634</item>
+ <!-- Rwanda (Republic of) -->
+ <item>rw:635</item>
+ <!-- Ethiopia (Federal Democratic Republic of) -->
+ <item>et:636</item>
+ <!-- Somali Democratic Republic -->
+ <item>so:637</item>
+ <!-- Djibouti (Republic of) -->
+ <item>dj:638</item>
+ <!-- Kenya (Republic of) -->
+ <item>ke:639</item>
+ <!-- Tanzania (United Republic of) -->
+ <item>tz:640</item>
+ <!-- Uganda (Republic of) -->
+ <item>ug:641</item>
+ <!-- Burundi (Republic of) -->
+ <item>bi:642</item>
+ <!-- Mozambique (Republic of) -->
+ <item>mz:643</item>
+ <!-- Zambia (Republic of) -->
+ <item>zm:645</item>
+ <!-- Madagascar (Republic of) -->
+ <item>mg:646</item>
+ <!-- French Departments and Territories in the Indian Ocean -->
+ <item>re:647</item>
+ <!-- Zimbabwe (Republic of) -->
+ <item>zw:648</item>
+ <!-- Namibia (Republic of) -->
+ <item>na:649</item>
+ <!-- Malawi -->
+ <item>mw:650</item>
+ <!-- Lesotho (Kingdom of) -->
+ <item>ls:651</item>
+ <!-- Botswana (Republic of) -->
+ <item>bw:652</item>
+ <!-- Swaziland (Kingdom of) -->
+ <item>sz:653</item>
+ <!-- Comoros (Union of the) -->
+ <item>km:654</item>
+ <!-- South Africa (Republic of) -->
+ <item>za:655</item>
+ <!-- Eritrea -->
+ <item>er:657</item>
+ <!-- Saint Helena, Ascension and Tristan da Cunha -->
+ <item>sh:658</item>
+ <!-- South Sudan (Republic of) -->
+ <item>ss:659</item>
+ <!-- Belize -->
+ <item>bz:702</item>
+ <!-- Guatemala (Republic of) -->
+ <item>gt:704</item>
+ <!-- El Salvador (Republic of) -->
+ <item>sv:706</item>
+ <!-- Honduras (Republic of) -->
+ <item>hn:708</item>
+ <!-- Nicaragua -->
+ <item>ni:710</item>
+ <!-- Costa Rica -->
+ <item>cr:712</item>
+ <!-- Panama (Republic of) -->
+ <item>pa:714</item>
+ <!-- Peru -->
+ <item>pe:716</item>
+ <!-- Argentine Republic -->
+ <item>ar:722</item>
+ <!-- Brazil (Federative Republic of) -->
+ <item>br:724</item>
+ <!-- Chile -->
+ <item>cl:730</item>
+ <!-- Colombia (Republic of) -->
+ <item>co:732</item>
+ <!-- Venezuela (Bolivarian Republic of) -->
+ <item>ve:734</item>
+ <!-- Bolivia (Republic of) -->
+ <item>bo:736</item>
+ <!-- Guyana -->
+ <item>gy:738</item>
+ <!-- Ecuador -->
+ <item>ec:740</item>
+ <!-- French Guiana (French Department of) -->
+ <item>gf:742</item>
+ <!-- Paraguay (Republic of) -->
+ <item>py:744</item>
+ <!-- Suriname (Republic of) -->
+ <item>sr:746</item>
+ <!-- Uruguay (Eastern Republic of) -->
+ <item>uy:748</item>
+ <!-- Falkland Islands (Malvinas) -->
+ <item>fk:750</item>
+ </string-array>
+</resources>
diff --git a/src/com/android/cellbroadcastreceiver/CellBroadcastBackupAgent.java b/src/com/android/cellbroadcastreceiver/CellBroadcastBackupAgent.java
index 185a86a52..059a98434 100644
--- a/src/com/android/cellbroadcastreceiver/CellBroadcastBackupAgent.java
+++ b/src/com/android/cellbroadcastreceiver/CellBroadcastBackupAgent.java
@@ -20,6 +20,7 @@ import android.app.backup.BackupAgentHelper;
import android.app.backup.SharedPreferencesBackupHelper;
import android.content.Intent;
import android.os.UserHandle;
+import android.preference.PreferenceManager;
import android.util.Log;
import com.android.internal.annotations.VisibleForTesting;
@@ -30,19 +31,16 @@ import com.android.internal.annotations.VisibleForTesting;
* now it backs up the whole shared preference file. This can be
* modified in the future to accommodate partial backup.
*/
-public class CellBroadcastBackupAgent extends BackupAgentHelper
-{
- private static final String TAG = "CBBackupAgent";
-
+public class CellBroadcastBackupAgent extends BackupAgentHelper {
@VisibleForTesting
public static final String SHARED_KEY = "shared_pref";
-
- private static final String SHARED_PREFS_NAME = "com.android.cellbroadcastreceiver_preferences";
+ private static final String TAG = "CBBackupAgent";
@Override
public void onCreate() {
Log.d(TAG, "onCreate");
- addHelper(SHARED_KEY, new SharedPreferencesBackupHelper(this, SHARED_PREFS_NAME));
+ addHelper(SHARED_KEY, new SharedPreferencesBackupHelper(this,
+ PreferenceManager.getDefaultSharedPreferencesName(this)));
}
@Override
diff --git a/src/com/android/cellbroadcastreceiver/CellBroadcastConfigService.java b/src/com/android/cellbroadcastreceiver/CellBroadcastConfigService.java
index 99a3d482d..4419c3eab 100644
--- a/src/com/android/cellbroadcastreceiver/CellBroadcastConfigService.java
+++ b/src/com/android/cellbroadcastreceiver/CellBroadcastConfigService.java
@@ -124,12 +124,14 @@ public class CellBroadcastConfigService extends IntentService {
enableCellBroadcastChannels(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID);
}
- String roamingOperator = CellBroadcastReceiver.getRoamingOperatorSupported(
- this);
- CellBroadcastReceiverMetrics.getInstance().onConfigUpdated(
- getApplicationContext(),
- roamingOperator.isEmpty() ? "" : roamingOperator,
- mChannelRangeForMetric);
+ if (!mChannelRangeForMetric.isEmpty()) {
+ String roamingOperator = CellBroadcastReceiver.getRoamingOperatorSupported(
+ this);
+ CellBroadcastReceiverMetrics.getInstance().onConfigUpdated(
+ getApplicationContext(),
+ roamingOperator.isEmpty() ? "" : roamingOperator,
+ mChannelRangeForMetric);
+ }
}
} catch (Exception ex) {
CellBroadcastReceiverMetrics.getInstance().logModuleError(
@@ -558,19 +560,21 @@ public class CellBroadcastConfigService extends IntentService {
+ range.mEndId + "], type:" + range.mRanType
+ ", enable:" + enable);
}
- if (enable) {
+ if (enable && (subId == SubscriptionManager.getDefaultSubscriptionId())) {
mChannelRangeForMetric.add(new Pair(range.mStartId, range.mEndId));
}
CellBroadcastIdRange cbRange = new CellBroadcastIdRange(range.mStartId,
range.mEndId, range.mRanType, enable);
channelIdRanges.add(cbRange);
} else {
+ if (VDBG) {
+ log("enableCellBroadcastRange[" + range.mStartId + "-"
+ + range.mEndId + "], type:" + range.mRanType);
+ }
if (enable) {
- if (VDBG) {
- log("enableCellBroadcastRange[" + range.mStartId + "-"
- + range.mEndId + "], type:" + range.mRanType);
+ if (subId == SubscriptionManager.getDefaultSubscriptionId()) {
+ mChannelRangeForMetric.add(new Pair(range.mStartId, range.mEndId));
}
- mChannelRangeForMetric.add(new Pair(range.mStartId, range.mEndId));
manager.enableCellBroadcastRange(range.mStartId, range.mEndId,
range.mRanType);
} else {
diff --git a/src/com/android/cellbroadcastreceiver/CellBroadcastListItem.java b/src/com/android/cellbroadcastreceiver/CellBroadcastListItem.java
index b5d6efae5..185128765 100644
--- a/src/com/android/cellbroadcastreceiver/CellBroadcastListItem.java
+++ b/src/com/android/cellbroadcastreceiver/CellBroadcastListItem.java
@@ -17,6 +17,7 @@
package com.android.cellbroadcastreceiver;
import android.content.Context;
+import android.content.res.Resources;
import android.database.Cursor;
import android.graphics.Typeface;
import android.provider.Telephony;
@@ -30,6 +31,8 @@ import android.view.accessibility.AccessibilityEvent;
import android.widget.RelativeLayout;
import android.widget.TextView;
+import com.android.internal.annotations.VisibleForTesting;
+
/**
* This class manages the list item view for a single alert.
*/
@@ -37,9 +40,12 @@ public class CellBroadcastListItem extends RelativeLayout {
private SmsCbMessage mCbMessage;
- private TextView mChannelView;
- private TextView mMessageView;
- private TextView mDateView;
+ @VisibleForTesting
+ public TextView mChannelView;
+ @VisibleForTesting
+ public TextView mMessageView;
+ @VisibleForTesting
+ public TextView mDateView;
private Context mContext;
public CellBroadcastListItem(Context context, AttributeSet attrs) {
@@ -66,7 +72,11 @@ public class CellBroadcastListItem extends RelativeLayout {
*/
public void bind(SmsCbMessage message) {
mCbMessage = message;
- mChannelView.setText(CellBroadcastResources.getDialogTitleResource(mContext, message));
+ Resources res = CellBroadcastSettings.getResourcesByOperator(mContext,
+ message.getSubscriptionId(),
+ CellBroadcastReceiver.getRoamingOperatorSupported(mContext));
+ mChannelView.setText(res.getText(
+ CellBroadcastResources.getDialogTitleResource(mContext, message)));
mDateView.setText(DateUtils.formatDateTime(getContext(), message.getReceivedTime(),
DateUtils.FORMAT_NO_NOON_MIDNIGHT | DateUtils.FORMAT_SHOW_TIME
| DateUtils.FORMAT_ABBREV_ALL | DateUtils.FORMAT_SHOW_DATE
diff --git a/src/com/android/cellbroadcastreceiver/CellBroadcastReceiver.java b/src/com/android/cellbroadcastreceiver/CellBroadcastReceiver.java
index cfdcc0480..b39ebbfac 100644
--- a/src/com/android/cellbroadcastreceiver/CellBroadcastReceiver.java
+++ b/src/com/android/cellbroadcastreceiver/CellBroadcastReceiver.java
@@ -21,6 +21,7 @@ import static com.android.cellbroadcastservice.CellBroadcastMetrics.ERRTYPE_PREF
import static com.android.cellbroadcastservice.CellBroadcastMetrics.RPT_SPC;
import static com.android.cellbroadcastservice.CellBroadcastMetrics.SRC_CBR;
+import android.annotation.NonNull;
import android.app.ActivityManager;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
@@ -46,6 +47,7 @@ import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import android.telephony.cdma.CdmaSmsCbProgramData;
import android.text.TextUtils;
+import android.util.ArrayMap;
import android.util.EventLog;
import android.util.Log;
import android.widget.Toast;
@@ -57,6 +59,8 @@ import com.android.internal.annotations.VisibleForTesting;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Locale;
+import java.util.Map;
public class CellBroadcastReceiver extends BroadcastReceiver {
private static final String TAG = "CellBroadcastReceiver";
@@ -113,6 +117,9 @@ public class CellBroadcastReceiver extends BroadcastReceiver {
private Context mContext;
+ // This is to map the iso country code to the MCC string
+ private Map<String, String> mMccMap;
+
/**
* this method is to make this class unit-testable, because CellBroadcastSettings.getResources()
* is a static method and cannot be stubbed.
@@ -132,6 +139,10 @@ public class CellBroadcastReceiver extends BroadcastReceiver {
String action = intent.getAction();
Resources res = getResourcesMethod();
+ if (mMccMap == null) {
+ mMccMap = getMccMap(res);
+ }
+
if (ACTION_MARK_AS_READ.equals(action)) {
// The only way this'll be called is if someone tries to maliciously set something
// as read. Log an event.
@@ -226,17 +237,27 @@ public class CellBroadcastReceiver extends BroadcastReceiver {
logd("onServiceStateChanged, ss: " + ss);
// check whether to support roaming network
String roamingOperator = null;
- if (ss == ServiceState.STATE_IN_SERVICE || ss == ServiceState.STATE_EMERGENCY_ONLY) {
+ if (ss != ServiceState.STATE_POWER_OFF) {
TelephonyManager tm = context.getSystemService(TelephonyManager.class);
String networkOperator = tm.getNetworkOperator();
logd("networkOperator: " + networkOperator);
+ // check the mcc on emergency only mode
+ if (TextUtils.isEmpty(networkOperator)) {
+ String countryCode = tm.getNetworkCountryIso();
+ if (mMccMap != null && !TextUtils.isEmpty(countryCode)) {
+ networkOperator = mMccMap.get(countryCode.toLowerCase(Locale.ROOT).trim());
+ logd("networkOperator on emergency mode: " + networkOperator
+ + " for the country code: " + countryCode);
+ }
+ }
+
// check roaming config only if the network oprator is not empty as the config
// is based on operator numeric
- if (!networkOperator.isEmpty()) {
+ if (!TextUtils.isEmpty(networkOperator)) {
// No roaming supported by default
roamingOperator = "";
- if ((tm.isNetworkRoaming() || ss == ServiceState.STATE_EMERGENCY_ONLY)
+ if ((tm.isNetworkRoaming() || ss != ServiceState.STATE_IN_SERVICE)
&& !networkOperator.equals(tm.getSimOperator())) {
String propRoamingPlmn = SystemProperties.get(
ROAMING_PLMN_SUPPORTED_PROPERTY_KEY, "").trim();
@@ -282,6 +303,25 @@ public class CellBroadcastReceiver extends BroadcastReceiver {
}
/**
+ * Initialize the MCC mapping table
+ */
+ @VisibleForTesting
+ @NonNull
+ public static Map<String, String> getMccMap(@NonNull Resources res) {
+ String[] arr = res.getStringArray(R.array.iso_country_code_mcc_table);
+ Map<String, String> map = new ArrayMap<>(arr.length);
+
+ for (String item : arr) {
+ String[] val = item.split(":");
+ if (val.length > 1) {
+ map.put(val[0].toLowerCase(Locale.ROOT).trim(), val[1].trim());
+ }
+ }
+
+ return map;
+ }
+
+ /**
* Send an intent to reset the users WEA settings if there is a new carrier on the default subId
*
* The settings will be reset only when a new carrier is detected on the default subId. So it
diff --git a/src/com/android/cellbroadcastreceiver/CellBroadcastReceiverMetrics.java b/src/com/android/cellbroadcastreceiver/CellBroadcastReceiverMetrics.java
index c6cb424e6..42f49df63 100644
--- a/src/com/android/cellbroadcastreceiver/CellBroadcastReceiverMetrics.java
+++ b/src/com/android/cellbroadcastreceiver/CellBroadcastReceiverMetrics.java
@@ -65,7 +65,6 @@ public class CellBroadcastReceiverMetrics {
/**
* Get instance of CellBroadcastReceiverMetrics.
*/
- @VisibleForTesting
public static CellBroadcastReceiverMetrics getInstance() {
if (sCbrMetrics == null) {
sCbrMetrics = new CellBroadcastReceiverMetrics();
diff --git a/src/com/android/cellbroadcastreceiver/CellBroadcastSettings.java b/src/com/android/cellbroadcastreceiver/CellBroadcastSettings.java
index 3c71ca147..75a62061d 100644
--- a/src/com/android/cellbroadcastreceiver/CellBroadcastSettings.java
+++ b/src/com/android/cellbroadcastreceiver/CellBroadcastSettings.java
@@ -167,7 +167,8 @@ public class CellBroadcastSettings extends CollapsingToolbarBaseActivity {
public static final String ANY_PREFERENCE_CHANGED_BY_USER = "any_preference_changed_by_user";
// Resource cache per operator
- private static final Map<String, Resources> sResourcesCacheByOperator = new HashMap<>();
+ @VisibleForTesting
+ public static final Map<String, Resources> sResourcesCacheByOperator = new HashMap<>();
private static final Object sCacheLock = new Object();
// Intent sent from cellbroadcastreceiver to notify cellbroadcastservice that area info update
diff --git a/tests/unit/src/com/android/cellbroadcastreceiver/unit/CellBroadcastAlertDialogTest.java b/tests/unit/src/com/android/cellbroadcastreceiver/unit/CellBroadcastAlertDialogTest.java
index a540c335d..ad1f3fa6a 100644
--- a/tests/unit/src/com/android/cellbroadcastreceiver/unit/CellBroadcastAlertDialogTest.java
+++ b/tests/unit/src/com/android/cellbroadcastreceiver/unit/CellBroadcastAlertDialogTest.java
@@ -78,7 +78,6 @@ import org.mockito.MockitoAnnotations;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.ArrayList;
-import java.util.Map;
public class CellBroadcastAlertDialogTest extends
CellBroadcastActivityTestCase<CellBroadcastAlertDialog> {
@@ -726,10 +725,7 @@ public class CellBroadcastAlertDialogTest extends
Resources mockResources2 = mock(Resources.class);
doReturn(false).when(mockResources2).getBoolean(R.bool.show_alert_title);
- Field field = CellBroadcastSettings.class.getDeclaredField("sResourcesCacheByOperator");
- field.setAccessible(true);
- Map<String, Resources> roamingMap = (Map<String, Resources>) field.get(null);
- roamingMap.put("334090", mockResources2);
+ CellBroadcastSettings.sResourcesCacheByOperator.put("334090", mockResources2);
mMessageList.add(CellBroadcastAlertServiceTest.createMessageForCmasMessageClass(12413,
SmsCbConstants.MESSAGE_ID_CMAS_ALERT_CHILD_ABDUCTION_EMERGENCY,
diff --git a/tests/unit/src/com/android/cellbroadcastreceiver/unit/CellBroadcastBackupAgentTest.java b/tests/unit/src/com/android/cellbroadcastreceiver/unit/CellBroadcastBackupAgentTest.java
index 97365a441..2d40d38f9 100644
--- a/tests/unit/src/com/android/cellbroadcastreceiver/unit/CellBroadcastBackupAgentTest.java
+++ b/tests/unit/src/com/android/cellbroadcastreceiver/unit/CellBroadcastBackupAgentTest.java
@@ -66,6 +66,10 @@ public class CellBroadcastBackupAgentTest {
@Test
public void testOnCreate() throws Exception {
+ final String packageName = CellBroadcastInternalReceiver.class.getPackage().getName();
+ doReturn(packageName).when(mMockContext).getPackageName();
+
+ mBackupAgentUT.attach(mMockContext);
mockBackupDispatcher();
mBackupAgentUT.onCreate();
// Ideally we should verify creation of SharedPreferencesBackupHelper, but it's not quite
diff --git a/tests/unit/src/com/android/cellbroadcastreceiver/unit/CellBroadcastListItemTest.java b/tests/unit/src/com/android/cellbroadcastreceiver/unit/CellBroadcastListItemTest.java
new file mode 100644
index 000000000..000efb967
--- /dev/null
+++ b/tests/unit/src/com/android/cellbroadcastreceiver/unit/CellBroadcastListItemTest.java
@@ -0,0 +1,105 @@
+/*
+ * Copyright (C) 2023 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.
+ */
+
+package com.android.cellbroadcastreceiver.unit;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+
+import android.app.Activity;
+import android.content.SharedPreferences;
+import android.content.res.Resources;
+import android.telephony.SmsCbCmasInfo;
+import android.telephony.SmsCbLocation;
+import android.telephony.SmsCbMessage;
+import android.telephony.SubscriptionInfo;
+import android.telephony.SubscriptionManager;
+import android.widget.TextView;
+
+import com.android.cellbroadcastreceiver.CellBroadcastListItem;
+import com.android.cellbroadcastreceiver.CellBroadcastSettings;
+import com.android.internal.telephony.gsm.SmsCbConstants;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+
+public final class CellBroadcastListItemTest extends
+ CellBroadcastActivityTestCase<Activity> {
+ private static final String FAKE_MCC = "123";
+ private static final String FAKE_TITLE = "Fake Alert";
+ private static final int FAKE_SUB_ID = SubscriptionManager.DEFAULT_SUBSCRIPTION_ID;
+
+ @Mock
+ private SharedPreferences mMockPref;
+ @Mock
+ private Resources mMockResources;
+ @Mock
+ private SubscriptionInfo mMockSubInfo;
+ @Mock
+ private SubscriptionManager mMockSubManager;
+ @Mock
+ private TextView mMockChannelView;
+ @Mock
+ private TextView mMockDateView;
+ @Mock
+ private TextView mMockMessageView;
+
+ private SmsCbMessage mMessage;
+ private CellBroadcastListItem mItem;
+
+ @Before
+ public void setUp() throws Exception {
+ super.setUp();
+ MockitoAnnotations.initMocks(this);
+ doReturn(FAKE_MCC).when(mMockPref).getString(anyString(), anyString());
+ doReturn(FAKE_TITLE).when(mMockResources).getText(anyInt());
+ doReturn(mMockSubInfo).when(mMockSubManager).getActiveSubscriptionInfo(anyInt());
+ mContext.injectSharedPreferences(mMockPref);
+ CellBroadcastSettings.sResourcesCacheByOperator.put(FAKE_MCC, mMockResources);
+ mMessage = new SmsCbMessage(1, 2, 1, new SmsCbLocation(),
+ SmsCbConstants.MESSAGE_ID_CMAS_ALERT_PRESIDENTIAL_LEVEL,
+ "language", "body", SmsCbMessage.MESSAGE_PRIORITY_EMERGENCY, null,
+ new SmsCbCmasInfo(0, 2, 3, 4, 5, 6), 0, FAKE_SUB_ID);
+ mItem = new CellBroadcastListItem(mContext, null);
+ mItem.mChannelView = mMockChannelView;
+ mItem.mDateView = mMockDateView;
+ mItem.mMessageView = mMockMessageView;
+ }
+
+ public CellBroadcastListItemTest() {
+ super(Activity.class);
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ @Test
+ public void testCellBroadcastListItemBindOnRoaming() {
+ mItem.bind(mMessage);
+
+ verify(mMockChannelView, times(1)).setText(eq(FAKE_TITLE), any());
+ }
+}
diff --git a/tests/unit/src/com/android/cellbroadcastreceiver/unit/CellBroadcastReceiverTest.java b/tests/unit/src/com/android/cellbroadcastreceiver/unit/CellBroadcastReceiverTest.java
index 301d5bec3..5c444b6d8 100644
--- a/tests/unit/src/com/android/cellbroadcastreceiver/unit/CellBroadcastReceiverTest.java
+++ b/tests/unit/src/com/android/cellbroadcastreceiver/unit/CellBroadcastReceiverTest.java
@@ -62,10 +62,15 @@ import org.mockito.Mock;
import java.util.ArrayList;
import java.util.List;
+import java.util.Map;
public class CellBroadcastReceiverTest extends CellBroadcastTest {
private static final long MAX_INIT_WAIT_MS = 5000;
+ private static final String[] MCC_TABLE = {
+ "gr:202", "nL:204", "Be:206", "US:310"
+ };
+
CellBroadcastReceiver mCellBroadcastReceiver;
String mPackageName = "testPackageName";
@@ -118,6 +123,7 @@ public class CellBroadcastReceiverTest extends CellBroadcastTest {
public void setUp() throws Exception {
super.setUp(this.getClass().getSimpleName());
doReturn(mConfiguration).when(mResources).getConfiguration();
+ doReturn(MCC_TABLE).when(mResources).getStringArray(R.array.iso_country_code_mcc_table);
mCellBroadcastReceiver = spy(new CellBroadcastReceiver());
doReturn(mResources).when(mCellBroadcastReceiver).getResourcesMethod();
doNothing().when(mCellBroadcastReceiver).startConfigServiceToEnableChannels();
@@ -645,6 +651,64 @@ public class CellBroadcastReceiverTest extends CellBroadcastTest {
"roaming_operator_supported", "321")).isEqualTo("");
}
+ @Test
+ public void testOnSimlessChange() {
+ mFakeSharedPreferences.putInt("service_state", ServiceState.STATE_IN_SERVICE);
+ mFakeSharedPreferences.putString("roaming_operator_supported", "");
+ doReturn("Us").when(mMockTelephonyManager).getNetworkCountryIso();
+ mockTelephonyManager();
+ doReturn("android.intent.action.SERVICE_STATE").when(mIntent).getAction();
+ doReturn(ServiceState.STATE_OUT_OF_SERVICE).when(mIntent)
+ .getIntExtra(anyString(), anyInt());
+ doReturn("").when(mMockTelephonyManager).getSimOperator();
+ doReturn("").when(mMockTelephonyManager).getNetworkOperator();
+ doReturn(false).when(mMockTelephonyManager).isNetworkRoaming();
+ doReturn(new String[] {"XXX"}).when(mResources).getStringArray(anyInt());
+
+ mCellBroadcastReceiver.onReceive(mContext, mIntent);
+
+ // verify the roaming operator is set correctly for simless case
+ verify(mCellBroadcastReceiver, times(1)).startConfigServiceToEnableChannels();
+ assertThat(mFakeSharedPreferences.getString(
+ "roaming_operator_supported", "")).isEqualTo("310");
+
+ doReturn(ServiceState.STATE_OUT_OF_SERVICE).when(mIntent)
+ .getIntExtra(anyString(), anyInt());
+ doReturn("123456").when(mMockTelephonyManager).getSimOperator();
+ doReturn("123456").when(mMockTelephonyManager).getNetworkOperator();
+
+ mCellBroadcastReceiver.onReceive(mContext, mIntent);
+
+ // verify the roaming operator is reset when sim loaded
+ verify(mCellBroadcastReceiver, times(2)).startConfigServiceToEnableChannels();
+ assertThat(mFakeSharedPreferences.getString(
+ "roaming_operator_supported", "")).isEqualTo("");
+ }
+
+ @Test
+ public void testGetMccMap() {
+ final String[] mccArray = new String[] {
+ //valid values
+ "gr:202", "nL:204", "Be:206", "US:310",
+ //invalid values
+ "aaa", "123", "aaa123", "aaa 123"
+ };
+ int validNum = 4;
+ doReturn(mccArray).when(mResources).getStringArray(anyInt());
+
+ Map<String, String> map = CellBroadcastReceiver.getMccMap(mResources);
+
+ assertThat(map.size()).isEqualTo(validNum);
+ // 2 times expected as it has been called in setup
+ verify(mResources, times(2)).getStringArray(eq(R.array.iso_country_code_mcc_table));
+
+ for (int i = 0; i < validNum; i++) {
+ String[] values = mccArray[i].split(":");
+ assertThat(map.get(values[0].toLowerCase())).isEqualTo(values[1]);
+ assertThat(map.get(values[0].toUpperCase())).isEqualTo(null);
+ }
+ }
+
@After
public void tearDown() throws Exception {
super.tearDown();