1 /*
2  * Copyright (C) 2022 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.compliancetests;
18 
19 import android.text.TextUtils;
20 
21 import org.json.JSONArray;
22 import org.json.JSONException;
23 import org.json.JSONObject;
24 
25 public class CellBroadcastCarrierTestConfig implements ITestConfig {
26     private static final String CARRIER_MCCMNC_FIELD = "mccmnc";
27     private static final String CARRIER_DISABLE_NAVIGATION = "disable_navigation";
28     private static final String CARRIER_FULLSCREEN = "fullscreen";
29     private static final String CARRIER_LANGUAGE = "language";
30     private static final String CARRIER_CHECK_SETTING_MAIN_LANG = "check_setting_with_main_lang";
31 
32     public String mMccMnc;
33     public boolean mDisableNavigation;
34     public boolean mNeedFullScreen;
35     public String mLanguageTag;
36     public boolean mCheckSettingWithMainLanguage = true;
37 
CellBroadcastCarrierTestConfig(JSONObject carriersObject, String carrierName)38     public CellBroadcastCarrierTestConfig(JSONObject carriersObject, String carrierName)
39             throws JSONException {
40         JSONObject carrierObject = carriersObject.getJSONObject(carrierName);
41         JSONArray mccMncList = carrierObject.getJSONArray(CARRIER_MCCMNC_FIELD);
42         mMccMnc = mccMncList.getString(0);
43         String disableNavigationString =
44                 getObjectString(carrierObject, CARRIER_DISABLE_NAVIGATION);
45         mDisableNavigation = false;
46         if (!TextUtils.isEmpty(disableNavigationString) && disableNavigationString.equals("true")) {
47             mDisableNavigation = true;
48         }
49         String fullScreenString = getObjectString(carrierObject, CARRIER_FULLSCREEN);
50         mNeedFullScreen = false;
51         if (!TextUtils.isEmpty(fullScreenString) && fullScreenString.equals("true")) {
52             mNeedFullScreen = true;
53         }
54         mLanguageTag = getObjectString(carrierObject, CARRIER_LANGUAGE);
55         String checkSettingWithMainLanguageTag = getObjectString(carrierObject,
56                 CARRIER_CHECK_SETTING_MAIN_LANG);
57         if (checkSettingWithMainLanguageTag != null
58                 && checkSettingWithMainLanguageTag.equals("false")) {
59             mCheckSettingWithMainLanguage = false;
60         }
61     }
62 }
63