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 global_dao_read_only.cpp
18 * @author Pawel Sikorski (p.sikorski@samsung.com)
20 * @brief This file contains the definition of global dao class.
23 #include <dpl/wrt-dao-ro/global_dao_read_only.h>
25 #include <dpl/foreach.h>
26 #include <dpl/log/log.h>
27 #include <dpl/string.h>
28 #include <dpl/db/orm.h>
29 #include <orm_generator_wrt.h>
30 #include <dpl/wrt-dao-ro/webruntime_database.h>
31 #include <dpl/wrt-dao-ro/WrtDatabase.h>
32 #include <dpl/wrt-dao-ro/common_dao_types.h>
35 bool GlobalDAOReadOnly::GetDeveloperMode()
37 LogDebug("Getting Developer mode");
39 using namespace DPL::DB::ORM;
40 using namespace DPL::DB::ORM::wrt;
41 WRT_DB_SELECT(select, GlobalProperties, &WrtDatabase::interface())
42 return select->GetSingleValue<GlobalProperties::developer_mode>();
44 Catch(DPL::DB::SqlConnection::Exception::Base){
45 ReThrowMsg(GlobalDAOReadOnly::Exception::DatabaseError,
46 "Failed to get developer mode");
50 bool GlobalDAOReadOnly::GetSecureByDefault()
52 using namespace DPL::DB::ORM;
53 using namespace DPL::DB::ORM::wrt;
54 WRT_DB_SELECT(select, GlobalProperties, &WrtDatabase::interface())
55 return select->GetSingleValue<GlobalProperties::secure_by_default>();
58 bool GlobalDAOReadOnly::getComplianceMode()
60 LogDebug("Getting compliance mode");
62 using namespace DPL::DB::ORM;
63 using namespace DPL::DB::ORM::wrt;
64 WRT_DB_SELECT(select, GlobalProperties, &WrtDatabase::interface())
65 return select->GetSingleValue<GlobalProperties::compliance_mode>();
67 Catch(DPL::DB::SqlConnection::Exception::Base){
68 ReThrowMsg(GlobalDAOReadOnly::Exception::DatabaseError,
69 "Failed to get compliance mode");
73 std::string GlobalDAOReadOnly::getComplianceFakeImei()
75 LogDebug("Getting compliance fake IMEI");
77 using namespace DPL::DB::ORM;
78 using namespace DPL::DB::ORM::wrt;
79 WRT_DB_SELECT(select, GlobalProperties, &WrtDatabase::interface())
80 DPL::Optional<DPL::String> result =
81 select->GetSingleValue<GlobalProperties::compliance_fake_imei>();
85 return DPL::ToUTF8String(*result);
87 Catch(DPL::DB::SqlConnection::Exception::Base){
88 ReThrowMsg(GlobalDAOReadOnly::Exception::DatabaseError,
89 "Failed to get compliance fake IMEI");
93 std::string GlobalDAOReadOnly::getComplianceFakeMeid()
95 LogDebug("Getting compliance fake MEID");
97 using namespace DPL::DB::ORM;
98 using namespace DPL::DB::ORM::wrt;
99 WRT_DB_SELECT(select, GlobalProperties, &WrtDatabase::interface())
100 DPL::Optional<DPL::String> result =
101 select->GetSingleValue<GlobalProperties::compliance_fake_meid>();
103 return std::string();
105 return DPL::ToUTF8String(*result);
107 Catch(DPL::DB::SqlConnection::Exception::Base){
108 ReThrowMsg(GlobalDAOReadOnly::Exception::DatabaseError,
109 "Failed to get compliance fake MEID");
113 bool GlobalDAOReadOnly::IsValidSubTag(const DPL::String& tag, int type)
115 using namespace DPL::DB::ORM;
116 using namespace DPL::DB::ORM::wrt;
117 WRT_DB_SELECT(select, iana_records, &WrtDatabase::interface())
118 select->Where(Equals<iana_records::SUBTAG>(tag));
119 auto row = select->GetRowList();
120 if (row.size() == 0 || row.front().Get_TYPE() != type) {
127 GlobalDAOReadOnly::NetworkAccessMode
128 GlobalDAOReadOnly::GetHomeNetworkDataUsage()
130 LogDebug("Getting home network data usage");
132 using namespace DPL::DB::ORM;
133 using namespace DPL::DB::ORM::wrt;
134 WRT_DB_SELECT(select, GlobalProperties, &WrtDatabase::interface())
135 return static_cast<GlobalDAOReadOnly::NetworkAccessMode>(
136 select->GetSingleValue<
137 GlobalProperties::home_network_data_usage>());
139 Catch(DPL::DB::SqlConnection::Exception::Base){
140 ReThrowMsg(GlobalDAOReadOnly::Exception::DatabaseError,
141 "Failed to get home network data usage");
145 GlobalDAOReadOnly::NetworkAccessMode GlobalDAOReadOnly::GetRoamingDataUsage()
147 LogDebug("Getting roaming network data usage");
149 using namespace DPL::DB::ORM;
150 using namespace DPL::DB::ORM::wrt;
151 WRT_DB_SELECT(select, GlobalProperties, &WrtDatabase::interface())
152 return static_cast<GlobalDAOReadOnly::NetworkAccessMode>(
153 select->GetSingleValue<GlobalProperties::roaming_data_usage>());
155 Catch(DPL::DB::SqlConnection::Exception::Base){
156 ReThrowMsg(GlobalDAOReadOnly::Exception::DatabaseError,
157 "Failed to get roaming network data usage");
161 //user agent strings are stored in db...
162 //and it is configurable for test in development.
163 DPL::String GlobalDAOReadOnly::GetUserAgentValue(const DPL::String &key)
165 LogDebug("Get User Agent Value : " << key);
167 using namespace DPL::DB::ORM;
168 using namespace DPL::DB::ORM::wrt;
169 WRT_DB_SELECT(select, UserAgents, &WrtDatabase::interface())
170 select->Where(Equals<UserAgents::key_name>(key));
171 DPL::Optional<DPL::String> agent =
172 select->GetSingleValue<UserAgents::key_value>();
173 if (agent.IsNull()) {
174 return DPL::FromUTF8String("");
179 Catch(DPL::DB::SqlConnection::Exception::Base){
180 ReThrowMsg(GlobalDAOReadOnly::Exception::DatabaseError,
181 "Failed to get user agent string");
185 DeviceCapabilitySet GlobalDAOReadOnly::GetDeviceCapability(
186 const DPL::String &apifeature)
188 // This could be done with one simply sql query but support for join is
191 using namespace DPL::DB::ORM;
192 using namespace DPL::DB::ORM::wrt;
195 FeatureDeviceCapProxy::Select::RowList rows;
196 DeviceCapabilitySet result;
199 WRT_DB_SELECT(select, FeaturesList, &WrtDatabase::interface())
200 select->Where(Equals<FeaturesList::FeatureName>(apifeature));
201 featureUUID = select->GetSingleValue<FeaturesList::FeatureUUID>();
205 WRT_DB_SELECT(select,
206 FeatureDeviceCapProxy,
207 &WrtDatabase::interface())
208 select->Where(Equals<FeatureDeviceCapProxy::FeatureUUID>(
210 rows = select->GetRowList();
214 WRT_DB_SELECT(select, DeviceCapabilities, &WrtDatabase::interface())
215 select->Where(Equals<DeviceCapabilities::DeviceCapID>(
216 it->Get_DeviceCapID()));
217 result.insert(select->
218 GetSingleValue<DeviceCapabilities::DeviceCapName>());
222 } Catch(DPL::DB::SqlConnection::Exception::Base){
223 ReThrowMsg(GlobalDAOReadOnly::Exception::DatabaseError,
224 "Failed to update roaming network data usage");
228 WidgetAccessInfoList GlobalDAOReadOnly::GetWhiteURIList()
230 LogDebug("Getting WhiteURIList.");
232 using namespace DPL::DB::ORM;
233 using namespace DPL::DB::ORM::wrt;
234 WRT_DB_SELECT(select, WidgetWhiteURIList, &WrtDatabase::interface())
236 WidgetAccessInfoList resultList;
237 typedef std::list<WidgetWhiteURIList::Row> RowList;
238 RowList list = select->GetRowList();
240 for (RowList::iterator i = list.begin(); i != list.end(); ++i) {
241 WidgetAccessInfo whiteURI;
242 whiteURI.strIRI = i->Get_uri();
243 whiteURI.bSubDomains = i->Get_subdomain_access();
244 resultList.push_back(whiteURI);
245 LogInfo("[uri] : " << whiteURI.strIRI <<
246 ", [subdomain] : " << whiteURI.bSubDomains);
249 } Catch(DPL::DB::SqlConnection::Exception::Base) {
250 ReThrowMsg(GlobalDAOReadOnly::Exception::DatabaseError,
251 "Failed to get whiteURI list");
255 bool GlobalDAOReadOnly::GetCookieSharingMode()
257 LogDebug("Getting Cookie Sharing mode");
259 using namespace DPL::DB::ORM;
260 using namespace DPL::DB::ORM::wrt;
261 WRT_DB_SELECT(select, GlobalProperties, &WrtDatabase::interface())
262 return select->GetSingleValue<GlobalProperties::cookie_sharing_mode>();
264 Catch(DPL::DB::SqlConnection::Exception::Base){
265 ReThrowMsg(GlobalDAOReadOnly::Exception::DatabaseError,
266 "Failed to get Cookie Sharing mode");