2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 * @file wrt_global_settings.cpp
19 * @author Pawel Sikorski(p.sikorski@samsung.com)
20 * @author Lukasz Wrzosek (l.wrzosek@samsung.com)
27 #include <sys/utsname.h>
28 #include <dpl/utils/wrt_global_settings.h>
30 namespace GlobalSettings {
33 const int ROAMING_TEST = 0x00000001;
34 const int POPUPS_TEST = 0x00000002;
35 const int OCSP_TEST = 0x00000004;
36 const int WARP_TEST = 0x00000008;
37 const int CRL_TEST = 0x00000010;
38 const int SCREEN_SHOT_TEST = 0x00000020;
39 const int ALL_TEST = (ROAMING_TEST | POPUPS_TEST | OCSP_TEST | WARP_TEST
40 | CRL_TEST | SCREEN_SHOT_TEST);
41 const char* WRT_TEST_MODE = "WRT_TEST_MODE";
42 const char* MACHINE_NAME_EMUL = "emulated"; // "arch_emulated"
46 MACHINE_TYPE_EMULATOR,
55 : isEmulator(false), testModes(0)
61 bool initializeGlobalSettings();
62 bool initHelper = initializeGlobalSettings();
64 MachineType getMachineType()
66 // get current machine name
69 if ((!u.machine) || (0 == strlen(u.machine))) {
70 return MACHINE_TYPE_UNKNOWN;
72 // If current machine is emul,
73 // machine name include "<arch>_emulated"
74 std::string machine = u.machine;
75 // find "emulated" string in the u.machine
76 if (std::string::npos != machine.find(MACHINE_NAME_EMUL)) {
77 return MACHINE_TYPE_EMULATOR;
79 return MACHINE_TYPE_TARGET;
84 return MACHINE_TYPE_UNKNOWN;
87 bool initializeGlobalSettings()
91 // ignore environment variables if this flag is not set
92 #ifdef GLOBAL_SETTINGS_CONTROL
93 char * envStr = getenv(WRT_TEST_MODE);
96 std::string env = envStr;
100 std::istringstream str(envStr);
101 while (std::getline(str, env, '|')) {
102 if ("popups" == env) {
103 testMode |= POPUPS_TEST;
104 } else if ("roaming" == env) {
105 testMode |= ROAMING_TEST;;
106 } else if ("ocsp" == env) {
107 testMode |= OCSP_TEST;;
108 } else if ("warp" == env) {
109 testMode |= WARP_TEST;;
110 } else if ("crl" == env) {
111 testMode |= CRL_TEST;
112 } else if ("screen" == env) {
113 testMode |= SCREEN_SHOT_TEST;;
117 gSettings.testModes = testMode;
119 // TODO other settings initialization
122 gSettings.isEmulator = (MACHINE_TYPE_EMULATOR == getMachineType());
127 bool TestModeEnabled()
129 return ((gSettings.testModes & ALL_TEST) == ALL_TEST);
132 bool PopupsTestModeEnabled() {
133 return (gSettings.testModes & POPUPS_TEST);
135 bool WarpTestModeEnabled() {
136 return (gSettings.testModes & WARP_TEST);
138 bool RoamingTestModeEnabled() {
139 return (gSettings.testModes & ROAMING_TEST);
141 bool OCSPTestModeEnabled() {
142 return (gSettings.testModes & OCSP_TEST);
144 bool CrlTestModeEnabled() {
145 return (gSettings.testModes & CRL_TEST);
147 bool MakeScreenTestModeEnabled() {
148 return (gSettings.testModes & SCREEN_SHOT_TEST);
153 return gSettings.isEmulator;