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
17package com.android.cellbroadcastreceiver;
18
19import android.telephony.CarrierConfigManager;
20import android.test.suitebuilder.annotation.SmallTest;
21
22import com.android.cellbroadcastreceiver.CellBroadcastAlertAudio.ToneType;
23import com.android.cellbroadcastreceiver.CellBroadcastOtherChannelsManager.CellBroadcastChannelRange;
24
25import org.junit.After;
26import org.junit.Before;
27import org.junit.Test;
28
29import java.util.ArrayList;
30
31import static org.junit.Assert.assertEquals;
32import static org.junit.Assert.assertFalse;
33import static org.junit.Assert.assertTrue;
34
35/**
36 * APN retry manager tests
37 */
38public class CellBroadcastOtherChannelsManagerTest extends CellBroadcastTest {
39
40    @Before
41    public void setUp() throws Exception {
42        super.setUp(getClass().getSimpleName());
43    }
44
45    @After
46    public void tearDown() throws Exception {
47        super.tearDown();
48    }
49
50    /**
51     * Test getting cell broadcast additional channels from Carrier Config.
52     */
53    @Test
54    @SmallTest
55    public void testGetCellBroadcastChannelRanges() throws Exception {
56        int subId = 1234;
57        carrierConfigSetStringArray(subId,
58                CarrierConfigManager.KEY_CARRIER_ADDITIONAL_CBS_CHANNELS_STRINGS,
59                new String[]{
60                        "12:type=earthquake, emergency=true",
61                        "456:type=tsunami, emergency=true",
62                        "0xAC00-0xAFED:type=other, emergency=false",
63                        "54-60:emergency=true",
64                        "100-200"
65                });
66        ArrayList<CellBroadcastChannelRange> list = CellBroadcastOtherChannelsManager.getInstance().
67                getCellBroadcastChannelRanges(mContext, subId);
68
69        assertEquals(12, list.get(0).mStartId);
70        assertEquals(12, list.get(0).mEndId);
71        assertEquals(ToneType.EARTHQUAKE, list.get(0).mToneType);
72        assertTrue(list.get(0).mIsEmergency);
73
74        assertEquals(456, list.get(1).mStartId);
75        assertEquals(456, list.get(1).mEndId);
76        assertEquals(ToneType.TSUNAMI, list.get(1).mToneType);
77        assertTrue(list.get(1).mIsEmergency);
78
79        assertEquals(0xAC00, list.get(2).mStartId);
80        assertEquals(0xAFED, list.get(2).mEndId);
81        assertEquals(ToneType.OTHER, list.get(2).mToneType);
82        assertFalse(list.get(2).mIsEmergency);
83
84        assertEquals(54, list.get(3).mStartId);
85        assertEquals(60, list.get(3).mEndId);
86        assertEquals(ToneType.CMAS_DEFAULT, list.get(3).mToneType);
87        assertTrue(list.get(3).mIsEmergency);
88
89        assertEquals(100, list.get(4).mStartId);
90        assertEquals(200, list.get(4).mEndId);
91        assertEquals(ToneType.CMAS_DEFAULT, list.get(4).mToneType);
92        assertFalse(list.get(4).mIsEmergency);
93    }
94}
95