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 org.junit.Assert.assertEquals; 20 import static org.mockito.Matchers.anyInt; 21 import static org.mockito.Matchers.anyString; 22 import static org.mockito.Mockito.doReturn; 23 import static org.mockito.Mockito.eq; 24 import static org.mockito.Mockito.spy; 25 import static org.mockito.Mockito.times; 26 import static org.mockito.Mockito.verify; 27 28 import android.content.Context; 29 import android.content.ContextWrapper; 30 import android.content.SharedPreferences; 31 import android.telephony.SmsManager; 32 import android.test.suitebuilder.annotation.SmallTest; 33 34 import com.android.internal.telephony.ISms; 35 import com.android.internal.telephony.cdma.sms.SmsEnvelope; 36 import com.android.internal.telephony.gsm.SmsCbConstants; 37 38 import org.junit.After; 39 import org.junit.Before; 40 import org.junit.Test; 41 import org.mockito.ArgumentCaptor; 42 import org.mockito.Mock; 43 44 import java.lang.reflect.Method; 45 46 /** 47 * Cell broadcast config service tests 48 */ 49 public class CellBroadcastConfigServiceTest extends CellBroadcastTest { 50 51 @Mock 52 ISms.Stub mMockedSmsService; 53 54 @Mock 55 SharedPreferences mMockedSharedPreferences; 56 57 private CellBroadcastConfigService mConfigService; 58 59 private SmsManager mSmsManager = SmsManager.getDefault(); 60 61 @Before 62 public void setUp() throws Exception { 63 super.setUp(getClass().getSimpleName()); 64 mConfigService = spy(new CellBroadcastConfigService()); 65 66 Class[] cArgs = new Class[1]; 67 cArgs[0] = Context.class; 68 69 Method method = ContextWrapper.class.getDeclaredMethod("attachBaseContext", cArgs); 70 method.setAccessible(true); 71 method.invoke(mConfigService, mContext); 72 73 doReturn(mMockedSharedPreferences).when(mContext) 74 .getSharedPreferences(anyString(), anyInt()); 75 76 mMockedServiceManager.replaceService("isms", mMockedSmsService); 77 doReturn(mMockedSmsService).when(mMockedSmsService).queryLocalInterface(anyString()); 78 } 79 80 @After 81 public void tearDown() throws Exception { 82 super.tearDown(); 83 } 84 85 private boolean setCellBroadcastRange(boolean enable, int type, int start, int end) 86 throws Exception { 87 88 Class[] cArgs = new Class[5]; 89 cArgs[0] = SmsManager.class; 90 cArgs[1] = Boolean.TYPE; 91 cArgs[2] = cArgs[3] = cArgs[4] = Integer.TYPE; 92 93 Method method = 94 CellBroadcastConfigService.class.getDeclaredMethod("setCellBroadcastRange", cArgs); 95 method.setAccessible(true); 96 97 return (boolean) method.invoke(mConfigService, mSmsManager, enable, type, start, end); 98 } 99 100 /** 101 * Test enable cell broadcast range 102 */ 103 @Test 104 @SmallTest 105 public void testEnableCellBroadcastRange() throws Exception { 106 setCellBroadcastRange(true, 0, 10, 20); 107 ArgumentCaptor<Integer> captorStart = ArgumentCaptor.forClass(Integer.class); 108 ArgumentCaptor<Integer> captorEnd = ArgumentCaptor.forClass(Integer.class); 109 ArgumentCaptor<Integer> captorType = ArgumentCaptor.forClass(Integer.class); 110 111 verify(mMockedSmsService, times(1)).enableCellBroadcastRangeForSubscriber(anyInt(), 112 captorStart.capture(), captorEnd.capture(), captorType.capture()); 113 114 assertEquals(10, captorStart.getValue().intValue()); 115 assertEquals(20, captorEnd.getValue().intValue()); 116 assertEquals(0, captorType.getValue().intValue()); 117 } 118 119 /** 120 * Test disable cell broadcast range 121 */ 122 @Test 123 @SmallTest 124 public void testDisableCellBroadcastRange() throws Exception { 125 setCellBroadcastRange(false, 0, 10, 20); 126 ArgumentCaptor<Integer> captorStart = ArgumentCaptor.forClass(Integer.class); 127 ArgumentCaptor<Integer> captorEnd = ArgumentCaptor.forClass(Integer.class); 128 ArgumentCaptor<Integer> captorType = ArgumentCaptor.forClass(Integer.class); 129 130 verify(mMockedSmsService, times(1)).disableCellBroadcastRangeForSubscriber(anyInt(), 131 captorStart.capture(), captorEnd.capture(), captorType.capture()); 132 133 assertEquals(10, captorStart.getValue().intValue()); 134 assertEquals(20, captorEnd.getValue().intValue()); 135 assertEquals(0, captorType.getValue().intValue()); 136 } 137 138 private void setPreference(String pref, boolean value) { 139 doReturn(value).when(mMockedSharedPreferences).getBoolean(eq(pref), eq(true)); 140 } 141 142 /** 143 * Test enabling channels for default countries (US) 144 */ 145 @Test 146 @SmallTest 147 public void testEnablingChannelsDefault() throws Exception { 148 setPreference(CellBroadcastSettings.KEY_ENABLE_EMERGENCY_ALERTS, true); 149 setPreference(CellBroadcastSettings.KEY_ENABLE_CMAS_EXTREME_THREAT_ALERTS, true); 150 setPreference(CellBroadcastSettings.KEY_ENABLE_CMAS_SEVERE_THREAT_ALERTS, true); 151 setPreference(CellBroadcastSettings.KEY_ENABLE_CMAS_AMBER_ALERTS, true); 152 153 mConfigService.setCellBroadcastOnSub(mSmsManager, true); 154 155 verify(mMockedSmsService, times(1)).enableCellBroadcastRangeForSubscriber( 156 eq(0), 157 eq(SmsEnvelope.SERVICE_CATEGORY_CMAS_PRESIDENTIAL_LEVEL_ALERT), 158 eq(SmsEnvelope.SERVICE_CATEGORY_CMAS_PRESIDENTIAL_LEVEL_ALERT), 159 eq(SmsManager.CELL_BROADCAST_RAN_TYPE_CDMA)); 160 161 verify(mMockedSmsService, times(1)).enableCellBroadcastRangeForSubscriber( 162 eq(0), 163 eq(SmsEnvelope.SERVICE_CATEGORY_CMAS_EXTREME_THREAT), 164 eq(SmsEnvelope.SERVICE_CATEGORY_CMAS_EXTREME_THREAT), 165 eq(SmsManager.CELL_BROADCAST_RAN_TYPE_CDMA)); 166 167 verify(mMockedSmsService, times(1)).enableCellBroadcastRangeForSubscriber( 168 eq(0), 169 eq(SmsEnvelope.SERVICE_CATEGORY_CMAS_SEVERE_THREAT), 170 eq(SmsEnvelope.SERVICE_CATEGORY_CMAS_SEVERE_THREAT), 171 eq(SmsManager.CELL_BROADCAST_RAN_TYPE_CDMA)); 172 173 verify(mMockedSmsService, times(1)).enableCellBroadcastRangeForSubscriber( 174 eq(0), 175 eq(SmsEnvelope.SERVICE_CATEGORY_CMAS_CHILD_ABDUCTION_EMERGENCY), 176 eq(SmsEnvelope.SERVICE_CATEGORY_CMAS_CHILD_ABDUCTION_EMERGENCY), 177 eq(SmsManager.CELL_BROADCAST_RAN_TYPE_CDMA)); 178 179 verify(mMockedSmsService, times(1)).disableCellBroadcastRangeForSubscriber( 180 eq(0), 181 eq(SmsEnvelope.SERVICE_CATEGORY_CMAS_TEST_MESSAGE), 182 eq(SmsEnvelope.SERVICE_CATEGORY_CMAS_TEST_MESSAGE), 183 eq(SmsManager.CELL_BROADCAST_RAN_TYPE_CDMA)); 184 185 186 // GSM 187 verify(mMockedSmsService, times(1)).enableCellBroadcastRangeForSubscriber( 188 eq(0), 189 eq(SmsCbConstants.MESSAGE_ID_ETWS_EARTHQUAKE_WARNING), 190 eq(SmsCbConstants.MESSAGE_ID_ETWS_EARTHQUAKE_AND_TSUNAMI_WARNING), 191 eq(SmsManager.CELL_BROADCAST_RAN_TYPE_GSM)); 192 193 verify(mMockedSmsService, times(1)).enableCellBroadcastRangeForSubscriber( 194 eq(0), 195 eq(SmsCbConstants.MESSAGE_ID_ETWS_OTHER_EMERGENCY_TYPE), 196 eq(SmsCbConstants.MESSAGE_ID_ETWS_OTHER_EMERGENCY_TYPE), 197 eq(SmsManager.CELL_BROADCAST_RAN_TYPE_GSM)); 198 199 verify(mMockedSmsService, times(1)).disableCellBroadcastRangeForSubscriber( 200 eq(0), 201 eq(SmsCbConstants.MESSAGE_ID_ETWS_TEST_MESSAGE), 202 eq(SmsCbConstants.MESSAGE_ID_ETWS_TEST_MESSAGE), 203 eq(SmsManager.CELL_BROADCAST_RAN_TYPE_GSM)); 204 205 verify(mMockedSmsService, times(1)).enableCellBroadcastRangeForSubscriber( 206 eq(0), 207 eq(SmsCbConstants.MESSAGE_ID_CMAS_ALERT_PRESIDENTIAL_LEVEL), 208 eq(SmsCbConstants.MESSAGE_ID_CMAS_ALERT_PRESIDENTIAL_LEVEL), 209 eq(SmsManager.CELL_BROADCAST_RAN_TYPE_GSM)); 210 211 verify(mMockedSmsService, times(1)).enableCellBroadcastRangeForSubscriber( 212 eq(0), 213 eq(SmsCbConstants.MESSAGE_ID_CMAS_ALERT_EXTREME_IMMEDIATE_OBSERVED), 214 eq(SmsCbConstants.MESSAGE_ID_CMAS_ALERT_EXTREME_IMMEDIATE_LIKELY), 215 eq(SmsManager.CELL_BROADCAST_RAN_TYPE_GSM)); 216 217 verify(mMockedSmsService, times(1)).enableCellBroadcastRangeForSubscriber( 218 eq(0), 219 eq(SmsCbConstants.MESSAGE_ID_CMAS_ALERT_EXTREME_EXPECTED_OBSERVED), 220 eq(SmsCbConstants.MESSAGE_ID_CMAS_ALERT_SEVERE_EXPECTED_LIKELY), 221 eq(SmsManager.CELL_BROADCAST_RAN_TYPE_GSM)); 222 223 verify(mMockedSmsService, times(1)).enableCellBroadcastRangeForSubscriber( 224 eq(0), 225 eq(SmsCbConstants.MESSAGE_ID_CMAS_ALERT_CHILD_ABDUCTION_EMERGENCY), 226 eq(SmsCbConstants.MESSAGE_ID_CMAS_ALERT_CHILD_ABDUCTION_EMERGENCY), 227 eq(SmsManager.CELL_BROADCAST_RAN_TYPE_GSM)); 228 229 verify(mMockedSmsService, times(1)).disableCellBroadcastRangeForSubscriber( 230 eq(0), 231 eq(SmsCbConstants.MESSAGE_ID_CMAS_ALERT_REQUIRED_MONTHLY_TEST), 232 eq(SmsCbConstants.MESSAGE_ID_CMAS_ALERT_OPERATOR_DEFINED_USE), 233 eq(SmsManager.CELL_BROADCAST_RAN_TYPE_GSM)); 234 } 235 236 /** 237 * Test enabling channels for Presidential alert 238 */ 239 @Test 240 @SmallTest 241 public void testEnablingPresidential() throws Exception { 242 setPreference(CellBroadcastSettings.KEY_ENABLE_EMERGENCY_ALERTS, true); 243 mConfigService.setCellBroadcastOnSub(mSmsManager, true); 244 245 verify(mMockedSmsService, times(1)).enableCellBroadcastRangeForSubscriber( 246 eq(0), 247 eq(SmsEnvelope.SERVICE_CATEGORY_CMAS_PRESIDENTIAL_LEVEL_ALERT), 248 eq(SmsEnvelope.SERVICE_CATEGORY_CMAS_PRESIDENTIAL_LEVEL_ALERT), 249 eq(SmsManager.CELL_BROADCAST_RAN_TYPE_CDMA)); 250 251 verify(mMockedSmsService, times(1)).enableCellBroadcastRangeForSubscriber( 252 eq(0), 253 eq(SmsCbConstants.MESSAGE_ID_CMAS_ALERT_PRESIDENTIAL_LEVEL), 254 eq(SmsCbConstants.MESSAGE_ID_CMAS_ALERT_PRESIDENTIAL_LEVEL), 255 eq(SmsManager.CELL_BROADCAST_RAN_TYPE_GSM)); 256 257 verify(mMockedSmsService, times(1)).enableCellBroadcastRangeForSubscriber( 258 eq(0), 259 eq(SmsCbConstants.MESSAGE_ID_CMAS_ALERT_PRESIDENTIAL_LEVEL_LANGUAGE), 260 eq(SmsCbConstants.MESSAGE_ID_CMAS_ALERT_PRESIDENTIAL_LEVEL_LANGUAGE), 261 eq(SmsManager.CELL_BROADCAST_RAN_TYPE_GSM)); 262 263 setPreference(CellBroadcastSettings.KEY_ENABLE_EMERGENCY_ALERTS, false); 264 mConfigService.setCellBroadcastOnSub(mSmsManager, true); 265 266 verify(mMockedSmsService, times(2)).enableCellBroadcastRangeForSubscriber( 267 eq(0), 268 eq(SmsEnvelope.SERVICE_CATEGORY_CMAS_PRESIDENTIAL_LEVEL_ALERT), 269 eq(SmsEnvelope.SERVICE_CATEGORY_CMAS_PRESIDENTIAL_LEVEL_ALERT), 270 eq(SmsManager.CELL_BROADCAST_RAN_TYPE_CDMA)); 271 272 verify(mMockedSmsService, times(2)).enableCellBroadcastRangeForSubscriber( 273 eq(0), 274 eq(SmsCbConstants.MESSAGE_ID_CMAS_ALERT_PRESIDENTIAL_LEVEL), 275 eq(SmsCbConstants.MESSAGE_ID_CMAS_ALERT_PRESIDENTIAL_LEVEL), 276 eq(SmsManager.CELL_BROADCAST_RAN_TYPE_GSM)); 277 278 verify(mMockedSmsService, times(2)).enableCellBroadcastRangeForSubscriber( 279 eq(0), 280 eq(SmsCbConstants.MESSAGE_ID_CMAS_ALERT_PRESIDENTIAL_LEVEL_LANGUAGE), 281 eq(SmsCbConstants.MESSAGE_ID_CMAS_ALERT_PRESIDENTIAL_LEVEL_LANGUAGE), 282 eq(SmsManager.CELL_BROADCAST_RAN_TYPE_GSM)); 283 284 setPreference(CellBroadcastSettings.KEY_ENABLE_EMERGENCY_ALERTS, true); 285 mConfigService.setCellBroadcastOnSub(mSmsManager, false); 286 287 verify(mMockedSmsService, times(1)).disableCellBroadcastRangeForSubscriber( 288 eq(0), 289 eq(SmsEnvelope.SERVICE_CATEGORY_CMAS_PRESIDENTIAL_LEVEL_ALERT), 290 eq(SmsEnvelope.SERVICE_CATEGORY_CMAS_PRESIDENTIAL_LEVEL_ALERT), 291 eq(SmsManager.CELL_BROADCAST_RAN_TYPE_CDMA)); 292 293 verify(mMockedSmsService, times(1)).disableCellBroadcastRangeForSubscriber( 294 eq(0), 295 eq(SmsCbConstants.MESSAGE_ID_CMAS_ALERT_PRESIDENTIAL_LEVEL), 296 eq(SmsCbConstants.MESSAGE_ID_CMAS_ALERT_PRESIDENTIAL_LEVEL), 297 eq(SmsManager.CELL_BROADCAST_RAN_TYPE_GSM)); 298 299 verify(mMockedSmsService, times(1)).disableCellBroadcastRangeForSubscriber( 300 eq(0), 301 eq(SmsCbConstants.MESSAGE_ID_CMAS_ALERT_PRESIDENTIAL_LEVEL_LANGUAGE), 302 eq(SmsCbConstants.MESSAGE_ID_CMAS_ALERT_PRESIDENTIAL_LEVEL_LANGUAGE), 303 eq(SmsManager.CELL_BROADCAST_RAN_TYPE_GSM)); 304 305 } 306 307 /** 308 * Test enabling channels for extreme alert 309 */ 310 @Test 311 @SmallTest 312 public void testEnablingExtreme() throws Exception { 313 setPreference(CellBroadcastSettings.KEY_ENABLE_EMERGENCY_ALERTS, true); 314 setPreference(CellBroadcastSettings.KEY_ENABLE_CMAS_EXTREME_THREAT_ALERTS, true); 315 mConfigService.setCellBroadcastOnSub(mSmsManager, true); 316 317 verify(mMockedSmsService, times(1)).enableCellBroadcastRangeForSubscriber( 318 eq(0), 319 eq(SmsEnvelope.SERVICE_CATEGORY_CMAS_EXTREME_THREAT), 320 eq(SmsEnvelope.SERVICE_CATEGORY_CMAS_EXTREME_THREAT), 321 eq(SmsManager.CELL_BROADCAST_RAN_TYPE_CDMA)); 322 323 verify(mMockedSmsService, times(1)).enableCellBroadcastRangeForSubscriber( 324 eq(0), 325 eq(SmsCbConstants.MESSAGE_ID_CMAS_ALERT_EXTREME_IMMEDIATE_OBSERVED), 326 eq(SmsCbConstants.MESSAGE_ID_CMAS_ALERT_EXTREME_IMMEDIATE_LIKELY), 327 eq(SmsManager.CELL_BROADCAST_RAN_TYPE_GSM)); 328 329 verify(mMockedSmsService, times(1)).enableCellBroadcastRangeForSubscriber( 330 eq(0), 331 eq(SmsCbConstants.MESSAGE_ID_CMAS_ALERT_EXTREME_IMMEDIATE_OBSERVED_LANGUAGE), 332 eq(SmsCbConstants.MESSAGE_ID_CMAS_ALERT_EXTREME_IMMEDIATE_LIKELY_LANGUAGE), 333 eq(SmsManager.CELL_BROADCAST_RAN_TYPE_GSM)); 334 335 setPreference(CellBroadcastSettings.KEY_ENABLE_CMAS_EXTREME_THREAT_ALERTS, false); 336 mConfigService.setCellBroadcastOnSub(mSmsManager, true); 337 338 verify(mMockedSmsService, times(1)).disableCellBroadcastRangeForSubscriber( 339 eq(0), 340 eq(SmsEnvelope.SERVICE_CATEGORY_CMAS_EXTREME_THREAT), 341 eq(SmsEnvelope.SERVICE_CATEGORY_CMAS_EXTREME_THREAT), 342 eq(SmsManager.CELL_BROADCAST_RAN_TYPE_CDMA)); 343 344 verify(mMockedSmsService, times(1)).disableCellBroadcastRangeForSubscriber( 345 eq(0), 346 eq(SmsCbConstants.MESSAGE_ID_CMAS_ALERT_EXTREME_IMMEDIATE_OBSERVED), 347 eq(SmsCbConstants.MESSAGE_ID_CMAS_ALERT_EXTREME_IMMEDIATE_LIKELY), 348 eq(SmsManager.CELL_BROADCAST_RAN_TYPE_GSM)); 349 350 verify(mMockedSmsService, times(1)).disableCellBroadcastRangeForSubscriber( 351 eq(0), 352 eq(SmsCbConstants.MESSAGE_ID_CMAS_ALERT_EXTREME_IMMEDIATE_OBSERVED_LANGUAGE), 353 eq(SmsCbConstants.MESSAGE_ID_CMAS_ALERT_EXTREME_IMMEDIATE_LIKELY_LANGUAGE), 354 eq(SmsManager.CELL_BROADCAST_RAN_TYPE_GSM)); 355 356 setPreference(CellBroadcastSettings.KEY_ENABLE_CMAS_EXTREME_THREAT_ALERTS, true); 357 mConfigService.setCellBroadcastOnSub(mSmsManager, false); 358 359 verify(mMockedSmsService, times(2)).disableCellBroadcastRangeForSubscriber( 360 eq(0), 361 eq(SmsEnvelope.SERVICE_CATEGORY_CMAS_EXTREME_THREAT), 362 eq(SmsEnvelope.SERVICE_CATEGORY_CMAS_EXTREME_THREAT), 363 eq(SmsManager.CELL_BROADCAST_RAN_TYPE_CDMA)); 364 365 verify(mMockedSmsService, times(2)).disableCellBroadcastRangeForSubscriber( 366 eq(0), 367 eq(SmsCbConstants.MESSAGE_ID_CMAS_ALERT_EXTREME_IMMEDIATE_OBSERVED), 368 eq(SmsCbConstants.MESSAGE_ID_CMAS_ALERT_EXTREME_IMMEDIATE_LIKELY), 369 eq(SmsManager.CELL_BROADCAST_RAN_TYPE_GSM)); 370 371 verify(mMockedSmsService, times(2)).disableCellBroadcastRangeForSubscriber( 372 eq(0), 373 eq(SmsCbConstants.MESSAGE_ID_CMAS_ALERT_EXTREME_IMMEDIATE_OBSERVED_LANGUAGE), 374 eq(SmsCbConstants.MESSAGE_ID_CMAS_ALERT_EXTREME_IMMEDIATE_LIKELY_LANGUAGE), 375 eq(SmsManager.CELL_BROADCAST_RAN_TYPE_GSM)); 376 377 } 378 379 /** 380 * Test enabling channels for severe alert 381 */ 382 @Test 383 @SmallTest 384 public void testEnablingSevere() throws Exception { 385 setPreference(CellBroadcastSettings.KEY_ENABLE_EMERGENCY_ALERTS, true); 386 setPreference(CellBroadcastSettings.KEY_ENABLE_CMAS_SEVERE_THREAT_ALERTS, true); 387 mConfigService.setCellBroadcastOnSub(mSmsManager, true); 388 389 verify(mMockedSmsService, times(1)).enableCellBroadcastRangeForSubscriber( 390 eq(0), 391 eq(SmsEnvelope.SERVICE_CATEGORY_CMAS_SEVERE_THREAT), 392 eq(SmsEnvelope.SERVICE_CATEGORY_CMAS_SEVERE_THREAT), 393 eq(SmsManager.CELL_BROADCAST_RAN_TYPE_CDMA)); 394 395 verify(mMockedSmsService, times(1)).enableCellBroadcastRangeForSubscriber( 396 eq(0), 397 eq(SmsCbConstants.MESSAGE_ID_CMAS_ALERT_EXTREME_EXPECTED_OBSERVED), 398 eq(SmsCbConstants.MESSAGE_ID_CMAS_ALERT_SEVERE_EXPECTED_LIKELY), 399 eq(SmsManager.CELL_BROADCAST_RAN_TYPE_GSM)); 400 401 verify(mMockedSmsService, times(1)).enableCellBroadcastRangeForSubscriber( 402 eq(0), 403 eq(SmsCbConstants.MESSAGE_ID_CMAS_ALERT_EXTREME_EXPECTED_OBSERVED_LANGUAGE), 404 eq(SmsCbConstants.MESSAGE_ID_CMAS_ALERT_SEVERE_EXPECTED_LIKELY_LANGUAGE), 405 eq(SmsManager.CELL_BROADCAST_RAN_TYPE_GSM)); 406 407 setPreference(CellBroadcastSettings.KEY_ENABLE_CMAS_SEVERE_THREAT_ALERTS, false); 408 mConfigService.setCellBroadcastOnSub(mSmsManager, true); 409 410 verify(mMockedSmsService, times(1)).disableCellBroadcastRangeForSubscriber( 411 eq(0), 412 eq(SmsEnvelope.SERVICE_CATEGORY_CMAS_SEVERE_THREAT), 413 eq(SmsEnvelope.SERVICE_CATEGORY_CMAS_SEVERE_THREAT), 414 eq(SmsManager.CELL_BROADCAST_RAN_TYPE_CDMA)); 415 416 verify(mMockedSmsService, times(1)).disableCellBroadcastRangeForSubscriber( 417 eq(0), 418 eq(SmsCbConstants.MESSAGE_ID_CMAS_ALERT_EXTREME_EXPECTED_OBSERVED), 419 eq(SmsCbConstants.MESSAGE_ID_CMAS_ALERT_SEVERE_EXPECTED_LIKELY), 420 eq(SmsManager.CELL_BROADCAST_RAN_TYPE_GSM)); 421 422 verify(mMockedSmsService, times(1)).disableCellBroadcastRangeForSubscriber( 423 eq(0), 424 eq(SmsCbConstants.MESSAGE_ID_CMAS_ALERT_EXTREME_EXPECTED_OBSERVED_LANGUAGE), 425 eq(SmsCbConstants.MESSAGE_ID_CMAS_ALERT_SEVERE_EXPECTED_LIKELY_LANGUAGE), 426 eq(SmsManager.CELL_BROADCAST_RAN_TYPE_GSM)); 427 428 setPreference(CellBroadcastSettings.KEY_ENABLE_CMAS_SEVERE_THREAT_ALERTS, true); 429 mConfigService.setCellBroadcastOnSub(mSmsManager, false); 430 431 verify(mMockedSmsService, times(2)).disableCellBroadcastRangeForSubscriber( 432 eq(0), 433 eq(SmsEnvelope.SERVICE_CATEGORY_CMAS_SEVERE_THREAT), 434 eq(SmsEnvelope.SERVICE_CATEGORY_CMAS_SEVERE_THREAT), 435 eq(SmsManager.CELL_BROADCAST_RAN_TYPE_CDMA)); 436 437 verify(mMockedSmsService, times(2)).disableCellBroadcastRangeForSubscriber( 438 eq(0), 439 eq(SmsCbConstants.MESSAGE_ID_CMAS_ALERT_EXTREME_EXPECTED_OBSERVED), 440 eq(SmsCbConstants.MESSAGE_ID_CMAS_ALERT_SEVERE_EXPECTED_LIKELY), 441 eq(SmsManager.CELL_BROADCAST_RAN_TYPE_GSM)); 442 443 verify(mMockedSmsService, times(2)).disableCellBroadcastRangeForSubscriber( 444 eq(0), 445 eq(SmsCbConstants.MESSAGE_ID_CMAS_ALERT_EXTREME_EXPECTED_OBSERVED_LANGUAGE), 446 eq(SmsCbConstants.MESSAGE_ID_CMAS_ALERT_SEVERE_EXPECTED_LIKELY_LANGUAGE), 447 eq(SmsManager.CELL_BROADCAST_RAN_TYPE_GSM)); 448 } 449 450 /** 451 * Test enabling channels for amber alert 452 */ 453 @Test 454 @SmallTest 455 public void testEnablingAmber() throws Exception { 456 setPreference(CellBroadcastSettings.KEY_ENABLE_EMERGENCY_ALERTS, true); 457 setPreference(CellBroadcastSettings.KEY_ENABLE_CMAS_AMBER_ALERTS, true); 458 mConfigService.setCellBroadcastOnSub(mSmsManager, true); 459 460 verify(mMockedSmsService, times(1)).enableCellBroadcastRangeForSubscriber( 461 eq(0), 462 eq(SmsEnvelope.SERVICE_CATEGORY_CMAS_CHILD_ABDUCTION_EMERGENCY), 463 eq(SmsEnvelope.SERVICE_CATEGORY_CMAS_CHILD_ABDUCTION_EMERGENCY), 464 eq(SmsManager.CELL_BROADCAST_RAN_TYPE_CDMA)); 465 466 verify(mMockedSmsService, times(1)).enableCellBroadcastRangeForSubscriber( 467 eq(0), 468 eq(SmsCbConstants.MESSAGE_ID_CMAS_ALERT_CHILD_ABDUCTION_EMERGENCY), 469 eq(SmsCbConstants.MESSAGE_ID_CMAS_ALERT_CHILD_ABDUCTION_EMERGENCY), 470 eq(SmsManager.CELL_BROADCAST_RAN_TYPE_GSM)); 471 472 verify(mMockedSmsService, times(1)).enableCellBroadcastRangeForSubscriber( 473 eq(0), 474 eq(SmsCbConstants.MESSAGE_ID_CMAS_ALERT_CHILD_ABDUCTION_EMERGENCY_LANGUAGE), 475 eq(SmsCbConstants.MESSAGE_ID_CMAS_ALERT_CHILD_ABDUCTION_EMERGENCY_LANGUAGE), 476 eq(SmsManager.CELL_BROADCAST_RAN_TYPE_GSM)); 477 478 setPreference(CellBroadcastSettings.KEY_ENABLE_CMAS_AMBER_ALERTS, false); 479 mConfigService.setCellBroadcastOnSub(mSmsManager, true); 480 481 verify(mMockedSmsService, times(1)).disableCellBroadcastRangeForSubscriber( 482 eq(0), 483 eq(SmsEnvelope.SERVICE_CATEGORY_CMAS_CHILD_ABDUCTION_EMERGENCY), 484 eq(SmsEnvelope.SERVICE_CATEGORY_CMAS_CHILD_ABDUCTION_EMERGENCY), 485 eq(SmsManager.CELL_BROADCAST_RAN_TYPE_CDMA)); 486 487 verify(mMockedSmsService, times(1)).disableCellBroadcastRangeForSubscriber( 488 eq(0), 489 eq(SmsCbConstants.MESSAGE_ID_CMAS_ALERT_CHILD_ABDUCTION_EMERGENCY), 490 eq(SmsCbConstants.MESSAGE_ID_CMAS_ALERT_CHILD_ABDUCTION_EMERGENCY), 491 eq(SmsManager.CELL_BROADCAST_RAN_TYPE_GSM)); 492 493 verify(mMockedSmsService, times(1)).disableCellBroadcastRangeForSubscriber( 494 eq(0), 495 eq(SmsCbConstants.MESSAGE_ID_CMAS_ALERT_CHILD_ABDUCTION_EMERGENCY_LANGUAGE), 496 eq(SmsCbConstants.MESSAGE_ID_CMAS_ALERT_CHILD_ABDUCTION_EMERGENCY_LANGUAGE), 497 eq(SmsManager.CELL_BROADCAST_RAN_TYPE_GSM)); 498 499 setPreference(CellBroadcastSettings.KEY_ENABLE_CMAS_AMBER_ALERTS, true); 500 mConfigService.setCellBroadcastOnSub(mSmsManager, false); 501 502 verify(mMockedSmsService, times(2)).disableCellBroadcastRangeForSubscriber( 503 eq(0), 504 eq(SmsEnvelope.SERVICE_CATEGORY_CMAS_CHILD_ABDUCTION_EMERGENCY), 505 eq(SmsEnvelope.SERVICE_CATEGORY_CMAS_CHILD_ABDUCTION_EMERGENCY), 506 eq(SmsManager.CELL_BROADCAST_RAN_TYPE_CDMA)); 507 508 verify(mMockedSmsService, times(2)).disableCellBroadcastRangeForSubscriber( 509 eq(0), 510 eq(SmsCbConstants.MESSAGE_ID_CMAS_ALERT_CHILD_ABDUCTION_EMERGENCY), 511 eq(SmsCbConstants.MESSAGE_ID_CMAS_ALERT_CHILD_ABDUCTION_EMERGENCY), 512 eq(SmsManager.CELL_BROADCAST_RAN_TYPE_GSM)); 513 514 verify(mMockedSmsService, times(2)).disableCellBroadcastRangeForSubscriber( 515 eq(0), 516 eq(SmsCbConstants.MESSAGE_ID_CMAS_ALERT_CHILD_ABDUCTION_EMERGENCY_LANGUAGE), 517 eq(SmsCbConstants.MESSAGE_ID_CMAS_ALERT_CHILD_ABDUCTION_EMERGENCY_LANGUAGE), 518 eq(SmsManager.CELL_BROADCAST_RAN_TYPE_GSM)); 519 } 520 521 /** 522 * Test enabling channels for ETWS alert 523 */ 524 @Test 525 @SmallTest 526 public void testEnablingETWS() throws Exception { 527 setPreference(CellBroadcastSettings.KEY_ENABLE_EMERGENCY_ALERTS, true); 528 mConfigService.setCellBroadcastOnSub(mSmsManager, true); 529 530 verify(mMockedSmsService, times(1)).enableCellBroadcastRangeForSubscriber( 531 eq(0), 532 eq(SmsCbConstants.MESSAGE_ID_ETWS_EARTHQUAKE_WARNING), 533 eq(SmsCbConstants.MESSAGE_ID_ETWS_EARTHQUAKE_AND_TSUNAMI_WARNING), 534 eq(SmsManager.CELL_BROADCAST_RAN_TYPE_GSM)); 535 536 verify(mMockedSmsService, times(1)).enableCellBroadcastRangeForSubscriber( 537 eq(0), 538 eq(SmsCbConstants.MESSAGE_ID_ETWS_OTHER_EMERGENCY_TYPE), 539 eq(SmsCbConstants.MESSAGE_ID_ETWS_OTHER_EMERGENCY_TYPE), 540 eq(SmsManager.CELL_BROADCAST_RAN_TYPE_GSM)); 541 542 setPreference(CellBroadcastSettings.KEY_ENABLE_EMERGENCY_ALERTS, false); 543 mConfigService.setCellBroadcastOnSub(mSmsManager, true); 544 545 verify(mMockedSmsService, times(1)).disableCellBroadcastRangeForSubscriber( 546 eq(0), 547 eq(SmsCbConstants.MESSAGE_ID_ETWS_EARTHQUAKE_WARNING), 548 eq(SmsCbConstants.MESSAGE_ID_ETWS_EARTHQUAKE_AND_TSUNAMI_WARNING), 549 eq(SmsManager.CELL_BROADCAST_RAN_TYPE_GSM)); 550 551 verify(mMockedSmsService, times(1)).disableCellBroadcastRangeForSubscriber( 552 eq(0), 553 eq(SmsCbConstants.MESSAGE_ID_ETWS_OTHER_EMERGENCY_TYPE), 554 eq(SmsCbConstants.MESSAGE_ID_ETWS_OTHER_EMERGENCY_TYPE), 555 eq(SmsManager.CELL_BROADCAST_RAN_TYPE_GSM)); 556 557 setPreference(CellBroadcastSettings.KEY_ENABLE_EMERGENCY_ALERTS, true); 558 mConfigService.setCellBroadcastOnSub(mSmsManager, false); 559 560 verify(mMockedSmsService, times(2)).disableCellBroadcastRangeForSubscriber( 561 eq(0), 562 eq(SmsCbConstants.MESSAGE_ID_ETWS_EARTHQUAKE_WARNING), 563 eq(SmsCbConstants.MESSAGE_ID_ETWS_EARTHQUAKE_AND_TSUNAMI_WARNING), 564 eq(SmsManager.CELL_BROADCAST_RAN_TYPE_GSM)); 565 566 verify(mMockedSmsService, times(2)).disableCellBroadcastRangeForSubscriber( 567 eq(0), 568 eq(SmsCbConstants.MESSAGE_ID_ETWS_OTHER_EMERGENCY_TYPE), 569 eq(SmsCbConstants.MESSAGE_ID_ETWS_OTHER_EMERGENCY_TYPE), 570 eq(SmsManager.CELL_BROADCAST_RAN_TYPE_GSM)); 571 } 572 }