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.JSONException;
22 import org.json.JSONObject;
23 
24 public class CellBroadcastChannelTestConfig implements ITestConfig {
25     private static final String CHANNEL_DEFAULT_VALUE_FIELD = "default_value";
26     private static final String CHANNEL_TITLE = "title";
27     private static final String CHANNEL_FILTER_LANGUAGE = "filter_language";
28     private static final String CHANNEL_ALERT_TYPE = "alert_type";
29     private static final String CHANNEL_TEST_MODE = "test_mode";
30     private static final String CHANNEL_DISPLAY = "display";
31     private static final String CHANNEL_WARNING_TYPE = "warning_type";
32 
33     public boolean mChannelDefaultValue = true;
34     public String mExpectedTitle;
35     public String mFilteredLanguage;
36     public boolean mIgnoreMessageByLanguageFilter;
37     public boolean mFilteredLanguageBySecondLanguagePref;
38     public boolean mAlertTypeIsNotification;
39     public boolean mIsEnabledOnTestMode;
40     public boolean mNeedDisplay = true;
41     public String mWarningType;
42 
CellBroadcastChannelTestConfig(JSONObject channelsObject, String carrierName, String channel)43     public CellBroadcastChannelTestConfig(JSONObject channelsObject,
44             String carrierName, String channel) throws JSONException {
45         JSONObject channelsForCarrier = channelsObject.getJSONObject(carrierName);
46         JSONObject object = channelsForCarrier.getJSONObject(channel);
47         String defaultValue = object.getString(CHANNEL_DEFAULT_VALUE_FIELD);
48         if (!TextUtils.isEmpty(defaultValue) && defaultValue.equals("false")) {
49             mChannelDefaultValue = false;
50         }
51         mExpectedTitle = object.getString(CHANNEL_TITLE);
52         mFilteredLanguage = getObjectString(object, CHANNEL_FILTER_LANGUAGE);
53         mIgnoreMessageByLanguageFilter = false;
54         if (!TextUtils.isEmpty(mFilteredLanguage)
55                 && mFilteredLanguage.equals("language_setting")) {
56             mIgnoreMessageByLanguageFilter = true;
57         } else if (!TextUtils.isEmpty(mFilteredLanguage)
58                 && mFilteredLanguage.equals("second_language_pref")) {
59             mFilteredLanguageBySecondLanguagePref = true;
60         }
61         String alertType = getObjectString(object, CHANNEL_ALERT_TYPE);
62         mAlertTypeIsNotification = false;
63         if (!TextUtils.isEmpty(alertType) && alertType.equals("notification")) {
64             mAlertTypeIsNotification = true;
65         }
66         String testModeString = getObjectString(object, CHANNEL_TEST_MODE);
67         if (!TextUtils.isEmpty(testModeString) && testModeString.equals("true")) {
68             mIsEnabledOnTestMode = true;
69         }
70         String displayString = getObjectString(object, CHANNEL_DISPLAY);
71         if (!TextUtils.isEmpty(displayString) && displayString.equals("false")) {
72             mNeedDisplay = false;
73         }
74         mWarningType = getObjectString(object, CHANNEL_WARNING_TYPE);
75     }
76 }
77