• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License
15  */
16 
17 package com.android.cellbroadcastreceiver;
18 
19 import static android.telephony.SmsManager.CELL_BROADCAST_RAN_TYPE_CDMA;
20 import static android.telephony.SmsManager.CELL_BROADCAST_RAN_TYPE_GSM;
21 
22 import static com.android.internal.telephony.cdma.sms.SmsEnvelope.SERVICE_CATEGORY_CMAS_CHILD_ABDUCTION_EMERGENCY;
23 import static com.android.internal.telephony.cdma.sms.SmsEnvelope.SERVICE_CATEGORY_CMAS_EXTREME_THREAT;
24 import static com.android.internal.telephony.cdma.sms.SmsEnvelope.SERVICE_CATEGORY_CMAS_PRESIDENTIAL_LEVEL_ALERT;
25 import static com.android.internal.telephony.cdma.sms.SmsEnvelope.SERVICE_CATEGORY_CMAS_SEVERE_THREAT;
26 import static com.android.internal.telephony.gsm.SmsCbConstants.MESSAGE_ID_CMAS_ALERT_CHILD_ABDUCTION_EMERGENCY;
27 import static com.android.internal.telephony.gsm.SmsCbConstants.MESSAGE_ID_CMAS_ALERT_CHILD_ABDUCTION_EMERGENCY_LANGUAGE;
28 import static com.android.internal.telephony.gsm.SmsCbConstants.MESSAGE_ID_CMAS_ALERT_EXTREME_EXPECTED_OBSERVED;
29 import static com.android.internal.telephony.gsm.SmsCbConstants.MESSAGE_ID_CMAS_ALERT_EXTREME_EXPECTED_OBSERVED_LANGUAGE;
30 import static com.android.internal.telephony.gsm.SmsCbConstants.MESSAGE_ID_CMAS_ALERT_EXTREME_IMMEDIATE_LIKELY;
31 import static com.android.internal.telephony.gsm.SmsCbConstants.MESSAGE_ID_CMAS_ALERT_EXTREME_IMMEDIATE_LIKELY_LANGUAGE;
32 import static com.android.internal.telephony.gsm.SmsCbConstants.MESSAGE_ID_CMAS_ALERT_EXTREME_IMMEDIATE_OBSERVED;
33 import static com.android.internal.telephony.gsm.SmsCbConstants.MESSAGE_ID_CMAS_ALERT_EXTREME_IMMEDIATE_OBSERVED_LANGUAGE;
34 import static com.android.internal.telephony.gsm.SmsCbConstants.MESSAGE_ID_CMAS_ALERT_PRESIDENTIAL_LEVEL;
35 import static com.android.internal.telephony.gsm.SmsCbConstants.MESSAGE_ID_CMAS_ALERT_PRESIDENTIAL_LEVEL_LANGUAGE;
36 import static com.android.internal.telephony.gsm.SmsCbConstants.MESSAGE_ID_CMAS_ALERT_SEVERE_EXPECTED_LIKELY;
37 import static com.android.internal.telephony.gsm.SmsCbConstants.MESSAGE_ID_CMAS_ALERT_SEVERE_EXPECTED_LIKELY_LANGUAGE;
38 import static com.android.internal.telephony.gsm.SmsCbConstants.MESSAGE_ID_ETWS_EARTHQUAKE_AND_TSUNAMI_WARNING;
39 import static com.android.internal.telephony.gsm.SmsCbConstants.MESSAGE_ID_ETWS_EARTHQUAKE_WARNING;
40 import static com.android.internal.telephony.gsm.SmsCbConstants.MESSAGE_ID_ETWS_OTHER_EMERGENCY_TYPE;
41 
42 import static org.mockito.Matchers.anyInt;
43 import static org.mockito.Matchers.anyString;
44 import static org.mockito.Mockito.doReturn;
45 import static org.mockito.Mockito.times;
46 import static org.mockito.Mockito.verify;
47 
48 import android.content.Intent;
49 
50 import com.android.internal.telephony.ISms;
51 
52 import org.junit.After;
53 import org.junit.Before;
54 import org.mockito.ArgumentCaptor;
55 import org.mockito.Captor;
56 import org.mockito.Mock;
57 
58 public class CellBroadcastBootupConfigTest extends
59         CellBroadcastServiceTestCase<CellBroadcastConfigService> {
60 
61     @Mock
62     ISms.Stub mSmsService;
63 
64     @Captor
65     private ArgumentCaptor<Integer> mStartIds;
66 
67     @Captor
68     private ArgumentCaptor<Integer> mEndIds;
69 
70     @Captor
71     private ArgumentCaptor<Integer> mTypes;
72 
CellBroadcastBootupConfigTest()73     public CellBroadcastBootupConfigTest() {
74         super(CellBroadcastConfigService.class);
75     }
76 
77     @Before
setUp()78     public void setUp() throws Exception {
79         super.setUp();
80 
81         doReturn(mSmsService).when(mSmsService).queryLocalInterface(anyString());
82         mMockedServiceManager.replaceService("isms", mSmsService);
83         putResources(R.array.cmas_presidential_alerts_channels_range_strings, new String[]{
84                 "0x1112-0x1112:rat=gsm",
85                 "0x1000-0x1000:rat=cdma",
86                 "0x111F-0x111F:rat=gsm",
87         });
88         putResources(R.array.cmas_alert_extreme_channels_range_strings, new String[]{
89                 "0x1113-0x1114:rat=gsm",
90                 "0x1001-0x1001:rat=cdma",
91                 "0x1120-0x1121:rat=gsm",
92         });
93         putResources(R.array.cmas_alerts_severe_range_strings, new String[]{
94                 "0x1115-0x111A:rat=gsm",
95                 "0x1002-0x1002:rat=cdma",
96                 "0x1122-0x1127:rat=gsm",
97         });
98         putResources(R.array.cmas_amber_alerts_channels_range_strings, new String[]{
99                 "0x111B-0x111B:rat=gsm",
100                 "0x1003-0x1003:rat=cdma",
101                 "0x1128-0x1128:rat=gsm",
102         });
103         putResources(R.array.etws_alerts_range_strings, new String[]{
104                 "0x1100-0x1102:rat=gsm",
105                 "0x1104-0x1104:rat=gsm",
106         });
107     }
108 
109     @After
tearDown()110     public void tearDown() throws Exception {
111         super.tearDown();
112     }
113 
114     private static class CbConfig {
115         final int startId;
116         final int endId;
117         final int type;
118 
CbConfig(int startId, int endId, int type)119         CbConfig(int startId, int endId, int type) {
120             this.startId = startId;
121             this.endId = endId;
122             this.type = type;
123         }
124     }
125 
126     // Test if CellbroadcastConfigService properly configure all the required channels.
testConfiguration()127     public void testConfiguration() throws Exception {
128 
129         Intent intent = new Intent(mContext, CellBroadcastConfigService.class);
130         intent.setAction(CellBroadcastConfigService.ACTION_ENABLE_CHANNELS);
131 
132         startService(intent);
133         waitForMs(200);
134 
135         CbConfig[] configs = new CbConfig[] {
136                 new CbConfig(MESSAGE_ID_CMAS_ALERT_PRESIDENTIAL_LEVEL,
137                         MESSAGE_ID_CMAS_ALERT_PRESIDENTIAL_LEVEL,
138                         CELL_BROADCAST_RAN_TYPE_GSM),
139                 new CbConfig(SERVICE_CATEGORY_CMAS_PRESIDENTIAL_LEVEL_ALERT,
140                         SERVICE_CATEGORY_CMAS_PRESIDENTIAL_LEVEL_ALERT,
141                         CELL_BROADCAST_RAN_TYPE_CDMA),
142                 new CbConfig(MESSAGE_ID_CMAS_ALERT_PRESIDENTIAL_LEVEL_LANGUAGE,
143                         MESSAGE_ID_CMAS_ALERT_PRESIDENTIAL_LEVEL_LANGUAGE,
144                         CELL_BROADCAST_RAN_TYPE_GSM),
145                 new CbConfig(MESSAGE_ID_CMAS_ALERT_EXTREME_IMMEDIATE_OBSERVED,
146                         MESSAGE_ID_CMAS_ALERT_EXTREME_IMMEDIATE_LIKELY,
147                         CELL_BROADCAST_RAN_TYPE_GSM),
148                 new CbConfig(SERVICE_CATEGORY_CMAS_EXTREME_THREAT,
149                         SERVICE_CATEGORY_CMAS_EXTREME_THREAT,
150                         CELL_BROADCAST_RAN_TYPE_CDMA),
151                 new CbConfig(MESSAGE_ID_CMAS_ALERT_EXTREME_IMMEDIATE_OBSERVED_LANGUAGE,
152                         MESSAGE_ID_CMAS_ALERT_EXTREME_IMMEDIATE_LIKELY_LANGUAGE,
153                         CELL_BROADCAST_RAN_TYPE_GSM),
154                 new CbConfig(MESSAGE_ID_CMAS_ALERT_EXTREME_EXPECTED_OBSERVED,
155                         MESSAGE_ID_CMAS_ALERT_SEVERE_EXPECTED_LIKELY,
156                         CELL_BROADCAST_RAN_TYPE_GSM),
157                 new CbConfig(SERVICE_CATEGORY_CMAS_SEVERE_THREAT,
158                         SERVICE_CATEGORY_CMAS_SEVERE_THREAT,
159                         CELL_BROADCAST_RAN_TYPE_CDMA),
160                 new CbConfig(MESSAGE_ID_CMAS_ALERT_EXTREME_EXPECTED_OBSERVED_LANGUAGE,
161                         MESSAGE_ID_CMAS_ALERT_SEVERE_EXPECTED_LIKELY_LANGUAGE,
162                         CELL_BROADCAST_RAN_TYPE_GSM),
163                 new CbConfig(MESSAGE_ID_CMAS_ALERT_CHILD_ABDUCTION_EMERGENCY,
164                         MESSAGE_ID_CMAS_ALERT_CHILD_ABDUCTION_EMERGENCY,
165                         CELL_BROADCAST_RAN_TYPE_GSM),
166                 new CbConfig(SERVICE_CATEGORY_CMAS_CHILD_ABDUCTION_EMERGENCY,
167                         SERVICE_CATEGORY_CMAS_CHILD_ABDUCTION_EMERGENCY,
168                         CELL_BROADCAST_RAN_TYPE_CDMA),
169                 new CbConfig(MESSAGE_ID_CMAS_ALERT_CHILD_ABDUCTION_EMERGENCY_LANGUAGE,
170                         MESSAGE_ID_CMAS_ALERT_CHILD_ABDUCTION_EMERGENCY_LANGUAGE,
171                         CELL_BROADCAST_RAN_TYPE_GSM),
172                 new CbConfig(MESSAGE_ID_ETWS_EARTHQUAKE_WARNING,
173                         MESSAGE_ID_ETWS_EARTHQUAKE_AND_TSUNAMI_WARNING,
174                         CELL_BROADCAST_RAN_TYPE_GSM),
175                 new CbConfig(MESSAGE_ID_ETWS_OTHER_EMERGENCY_TYPE,
176                         MESSAGE_ID_ETWS_OTHER_EMERGENCY_TYPE,
177                         CELL_BROADCAST_RAN_TYPE_GSM),
178         };
179 
180         verify(mSmsService, times(configs.length)).enableCellBroadcastRangeForSubscriber(anyInt(),
181                 mStartIds.capture(), mEndIds.capture(), mTypes.capture());
182 
183         for (int i = 0; i < configs.length; i++) {
184             assertEquals("i=" + i, configs[i].startId, mStartIds.getAllValues().get(i).intValue());
185             assertEquals("i=" + i, configs[i].endId, mEndIds.getAllValues().get(i).intValue());
186             assertEquals("i=" + i, configs[i].type, mTypes.getAllValues().get(i).intValue());
187         }
188      }
189 }
190