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)
28 #include <sys/utsname.h>
29 #include <dpl/utils/wrt_global_settings.h>
31 namespace GlobalSettings {
34 const int ROAMING_TEST = 0x00000001;
35 const int POPUPS_TEST = 0x00000002;
36 const int OCSP_TEST = 0x00000004;
37 const int WARP_TEST = 0x00000008;
38 const int CRL_TEST = 0x00000010;
39 const int SCREEN_SHOT_TEST = 0x00000020;
40 const int ALL_TEST = (ROAMING_TEST | POPUPS_TEST | OCSP_TEST | WARP_TEST
41 | CRL_TEST | SCREEN_SHOT_TEST);
42 const char* WRT_TEST_MODE = "WRT_TEST_MODE";
43 const char* MACHINE_NAME_EMUL = "emulated"; // "arch_emulated"
47 MACHINE_TYPE_EMULATOR,
56 : isEmulator(false), testModes(0)
62 bool initializeGlobalSettings();
63 bool initHelper = initializeGlobalSettings();
65 MachineType getMachineType()
67 // get current machine name
70 if ((!u.machine) || (0 == strlen(u.machine))) {
71 return MACHINE_TYPE_UNKNOWN;
73 // If current machine is emul,
74 // machine name include "<arch>_emulated"
75 std::string machine = u.machine;
76 // find "emulated" string in the u.machine
77 if (std::string::npos != machine.find(MACHINE_NAME_EMUL)) {
78 return MACHINE_TYPE_EMULATOR;
80 return MACHINE_TYPE_TARGET;
85 return MACHINE_TYPE_UNKNOWN;
88 bool initializeGlobalSettings()
92 // ignore environment variables if this flag is not set
93 #ifdef GLOBAL_SETTINGS_CONTROL
94 char * envStr = getenv(WRT_TEST_MODE);
97 std::string env = envStr;
101 std::istringstream str(envStr);
102 while (std::getline(str, env, '|')) {
103 if ("popups" == env) {
104 testMode |= POPUPS_TEST;
105 } else if ("roaming" == env) {
106 testMode |= ROAMING_TEST;;
107 } else if ("ocsp" == env) {
108 testMode |= OCSP_TEST;;
109 } else if ("warp" == env) {
110 testMode |= WARP_TEST;;
111 } else if ("crl" == env) {
112 testMode |= CRL_TEST;
113 } else if ("screen" == env) {
114 testMode |= SCREEN_SHOT_TEST;;
118 gSettings.testModes = testMode;
120 // TODO other settings initialization
123 gSettings.isEmulator = (MACHINE_TYPE_EMULATOR == getMachineType());
128 bool TestModeEnabled()
130 return ((gSettings.testModes & ALL_TEST) == ALL_TEST);
133 bool PopupsTestModeEnabled() {
134 return (gSettings.testModes & POPUPS_TEST);
136 bool WarpTestModeEnabled() {
137 return (gSettings.testModes & WARP_TEST);
139 bool RoamingTestModeEnabled() {
140 return (gSettings.testModes & ROAMING_TEST);
142 bool OCSPTestModeEnabled() {
143 return (gSettings.testModes & OCSP_TEST);
145 bool CrlTestModeEnabled() {
146 return (gSettings.testModes & CRL_TEST);
148 bool MakeScreenTestModeEnabled() {
149 return (gSettings.testModes & SCREEN_SHOT_TEST);
154 return gSettings.isEmulator;