• 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 android.content.Intent;
20 
21 import com.android.internal.telephony.ISms;
22 
23 import org.junit.After;
24 import org.junit.Before;
25 import org.mockito.ArgumentCaptor;
26 import org.mockito.Captor;
27 import org.mockito.Mock;
28 
29 import static android.telephony.SmsManager.CELL_BROADCAST_RAN_TYPE_CDMA;
30 import static android.telephony.SmsManager.CELL_BROADCAST_RAN_TYPE_GSM;
31 import static com.android.internal.telephony.cdma.sms.SmsEnvelope.SERVICE_CATEGORY_CMAS_CHILD_ABDUCTION_EMERGENCY;
32 import static com.android.internal.telephony.cdma.sms.SmsEnvelope.SERVICE_CATEGORY_CMAS_EXTREME_THREAT;
33 import static com.android.internal.telephony.cdma.sms.SmsEnvelope.SERVICE_CATEGORY_CMAS_PRESIDENTIAL_LEVEL_ALERT;
34 import static com.android.internal.telephony.cdma.sms.SmsEnvelope.SERVICE_CATEGORY_CMAS_SEVERE_THREAT;
35 import static com.android.internal.telephony.gsm.SmsCbConstants.MESSAGE_ID_CMAS_ALERT_CHILD_ABDUCTION_EMERGENCY;
36 import static com.android.internal.telephony.gsm.SmsCbConstants.MESSAGE_ID_CMAS_ALERT_CHILD_ABDUCTION_EMERGENCY_LANGUAGE;
37 import static com.android.internal.telephony.gsm.SmsCbConstants.MESSAGE_ID_CMAS_ALERT_EXTREME_EXPECTED_OBSERVED;
38 import static com.android.internal.telephony.gsm.SmsCbConstants.MESSAGE_ID_CMAS_ALERT_EXTREME_EXPECTED_OBSERVED_LANGUAGE;
39 import static com.android.internal.telephony.gsm.SmsCbConstants.MESSAGE_ID_CMAS_ALERT_EXTREME_IMMEDIATE_LIKELY;
40 import static com.android.internal.telephony.gsm.SmsCbConstants.MESSAGE_ID_CMAS_ALERT_EXTREME_IMMEDIATE_LIKELY_LANGUAGE;
41 import static com.android.internal.telephony.gsm.SmsCbConstants.MESSAGE_ID_CMAS_ALERT_EXTREME_IMMEDIATE_OBSERVED;
42 import static com.android.internal.telephony.gsm.SmsCbConstants.MESSAGE_ID_CMAS_ALERT_EXTREME_IMMEDIATE_OBSERVED_LANGUAGE;
43 import static com.android.internal.telephony.gsm.SmsCbConstants.MESSAGE_ID_CMAS_ALERT_PRESIDENTIAL_LEVEL;
44 import static com.android.internal.telephony.gsm.SmsCbConstants.MESSAGE_ID_CMAS_ALERT_PRESIDENTIAL_LEVEL_LANGUAGE;
45 import static com.android.internal.telephony.gsm.SmsCbConstants.MESSAGE_ID_CMAS_ALERT_SEVERE_EXPECTED_LIKELY;
46 import static com.android.internal.telephony.gsm.SmsCbConstants.MESSAGE_ID_CMAS_ALERT_SEVERE_EXPECTED_LIKELY_LANGUAGE;
47 import static com.android.internal.telephony.gsm.SmsCbConstants.MESSAGE_ID_ETWS_EARTHQUAKE_AND_TSUNAMI_WARNING;
48 import static com.android.internal.telephony.gsm.SmsCbConstants.MESSAGE_ID_ETWS_EARTHQUAKE_WARNING;
49 import static com.android.internal.telephony.gsm.SmsCbConstants.MESSAGE_ID_ETWS_OTHER_EMERGENCY_TYPE;
50 import static org.mockito.Matchers.anyInt;
51 import static org.mockito.Matchers.anyString;
52 import static org.mockito.Mockito.doReturn;
53 import static org.mockito.Mockito.times;
54 import static org.mockito.Mockito.verify;
55 
56 public class CellBroadcastBootupConfigTest extends
57         CellBroadcastServiceTestCase<CellBroadcastConfigService> {
58 
59     @Mock
60     ISms.Stub mSmsService;
61 
62     @Captor
63     private ArgumentCaptor<Integer> mStartIds;
64 
65     @Captor
66     private ArgumentCaptor<Integer> mEndIds;
67 
68     @Captor
69     private ArgumentCaptor<Integer> mTypes;
70 
71     private MockedServiceManager mMockedServiceManager;
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 = new MockedServiceManager();
83         mMockedServiceManager.replaceService("isms", mSmsService);
84     }
85 
86     @After
tearDown()87     public void tearDown() throws Exception {
88         mMockedServiceManager.restoreAllServices();
89         super.tearDown();
90     }
91 
92     private static class CbConfig {
93         final int startId;
94         final int endId;
95         final int type;
96 
CbConfig(int startId, int endId, int type)97         CbConfig(int startId, int endId, int type) {
98             this.startId = startId;
99             this.endId = endId;
100             this.type = type;
101         }
102     }
103 
104     // Test if CellbroadcastConfigService properly configure all the required channels.
testConfiguration()105     public void testConfiguration() throws Exception {
106         Intent intent = new Intent(mContext, CellBroadcastConfigService.class);
107         intent.setAction(CellBroadcastConfigService.ACTION_ENABLE_CHANNELS);
108 
109         startService(intent);
110         waitForMs(200);
111 
112         CbConfig[] configs = new CbConfig[] {
113                 new CbConfig(SERVICE_CATEGORY_CMAS_PRESIDENTIAL_LEVEL_ALERT,
114                         SERVICE_CATEGORY_CMAS_PRESIDENTIAL_LEVEL_ALERT,
115                         CELL_BROADCAST_RAN_TYPE_CDMA),
116                 new CbConfig(SERVICE_CATEGORY_CMAS_EXTREME_THREAT,
117                         SERVICE_CATEGORY_CMAS_EXTREME_THREAT,
118                         CELL_BROADCAST_RAN_TYPE_CDMA),
119                 new CbConfig(SERVICE_CATEGORY_CMAS_SEVERE_THREAT,
120                         SERVICE_CATEGORY_CMAS_SEVERE_THREAT,
121                         CELL_BROADCAST_RAN_TYPE_CDMA),
122                 new CbConfig(SERVICE_CATEGORY_CMAS_CHILD_ABDUCTION_EMERGENCY,
123                         SERVICE_CATEGORY_CMAS_CHILD_ABDUCTION_EMERGENCY,
124                         CELL_BROADCAST_RAN_TYPE_CDMA),
125                 new CbConfig(MESSAGE_ID_ETWS_EARTHQUAKE_WARNING,
126                         MESSAGE_ID_ETWS_EARTHQUAKE_AND_TSUNAMI_WARNING,
127                         CELL_BROADCAST_RAN_TYPE_GSM),
128                 new CbConfig(MESSAGE_ID_ETWS_OTHER_EMERGENCY_TYPE,
129                         MESSAGE_ID_ETWS_OTHER_EMERGENCY_TYPE,
130                         CELL_BROADCAST_RAN_TYPE_GSM),
131                 new CbConfig(MESSAGE_ID_CMAS_ALERT_PRESIDENTIAL_LEVEL,
132                         MESSAGE_ID_CMAS_ALERT_PRESIDENTIAL_LEVEL,
133                         CELL_BROADCAST_RAN_TYPE_GSM),
134                 new CbConfig(MESSAGE_ID_CMAS_ALERT_EXTREME_IMMEDIATE_OBSERVED,
135                         MESSAGE_ID_CMAS_ALERT_EXTREME_IMMEDIATE_LIKELY,
136                         CELL_BROADCAST_RAN_TYPE_GSM),
137                 new CbConfig(MESSAGE_ID_CMAS_ALERT_EXTREME_EXPECTED_OBSERVED,
138                         MESSAGE_ID_CMAS_ALERT_SEVERE_EXPECTED_LIKELY,
139                         CELL_BROADCAST_RAN_TYPE_GSM),
140                 new CbConfig(MESSAGE_ID_CMAS_ALERT_CHILD_ABDUCTION_EMERGENCY,
141                         MESSAGE_ID_CMAS_ALERT_CHILD_ABDUCTION_EMERGENCY,
142                         CELL_BROADCAST_RAN_TYPE_GSM),
143                 new CbConfig(MESSAGE_ID_CMAS_ALERT_PRESIDENTIAL_LEVEL_LANGUAGE,
144                         MESSAGE_ID_CMAS_ALERT_PRESIDENTIAL_LEVEL_LANGUAGE,
145                         CELL_BROADCAST_RAN_TYPE_GSM),
146                 new CbConfig(MESSAGE_ID_CMAS_ALERT_EXTREME_IMMEDIATE_OBSERVED_LANGUAGE,
147                         MESSAGE_ID_CMAS_ALERT_EXTREME_IMMEDIATE_LIKELY_LANGUAGE,
148                         CELL_BROADCAST_RAN_TYPE_GSM),
149                 new CbConfig(MESSAGE_ID_CMAS_ALERT_EXTREME_EXPECTED_OBSERVED_LANGUAGE,
150                         MESSAGE_ID_CMAS_ALERT_SEVERE_EXPECTED_LIKELY_LANGUAGE,
151                         CELL_BROADCAST_RAN_TYPE_GSM),
152                 new CbConfig(MESSAGE_ID_CMAS_ALERT_CHILD_ABDUCTION_EMERGENCY_LANGUAGE,
153                         MESSAGE_ID_CMAS_ALERT_CHILD_ABDUCTION_EMERGENCY_LANGUAGE,
154                         CELL_BROADCAST_RAN_TYPE_GSM),
155         };
156 
157         verify(mSmsService, times(configs.length)).enableCellBroadcastRangeForSubscriber(anyInt(),
158                 mStartIds.capture(), mEndIds.capture(), mTypes.capture());
159 
160         for (int i = 0; i < configs.length; i++) {
161             assertEquals("i=" + i, configs[i].startId, mStartIds.getAllValues().get(i).intValue());
162             assertEquals("i=" + i, configs[i].endId, mEndIds.getAllValues().get(i).intValue());
163             assertEquals("i=" + i, configs[i].type, mTypes.getAllValues().get(i).intValue());
164         }
165      }
166 }