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>
36 bool GlobalDAOReadOnly::GetDeveloperMode()
38 LogDebug("Getting Developer mode");
40 using namespace DPL::DB::ORM;
41 using namespace DPL::DB::ORM::wrt;
42 WRT_DB_SELECT(select, GlobalProperties, &WrtDatabase::interface())
43 return select->GetSingleValue<GlobalProperties::developer_mode>();
45 Catch(DPL::DB::SqlConnection::Exception::Base){
46 ReThrowMsg(GlobalDAOReadOnly::Exception::DatabaseError,
47 "Failed to get developer mode");
51 bool GlobalDAOReadOnly::GetSecureByDefault()
53 using namespace DPL::DB::ORM;
54 using namespace DPL::DB::ORM::wrt;
55 WRT_DB_SELECT(select, GlobalProperties, &WrtDatabase::interface())
56 return select->GetSingleValue<GlobalProperties::secure_by_default>();
59 bool GlobalDAOReadOnly::getComplianceMode()
61 LogDebug("Getting compliance mode");
63 using namespace DPL::DB::ORM; 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; using namespace DPL::DB::ORM::wrt;
78 WRT_DB_SELECT(select, GlobalProperties, &WrtDatabase::interface())
79 DPL::Optional<DPL::String> result =
80 select->GetSingleValue<GlobalProperties::compliance_fake_imei>();
84 return DPL::ToUTF8String(*result);
86 Catch (DPL::DB::SqlConnection::Exception::Base){
87 ReThrowMsg(GlobalDAOReadOnly::Exception::DatabaseError,
88 "Failed to get compliance fake IMEI");
92 std::string GlobalDAOReadOnly::getComplianceFakeMeid()
94 LogDebug("Getting compliance fake MEID");
96 using namespace DPL::DB::ORM; using namespace DPL::DB::ORM::wrt;
97 WRT_DB_SELECT(select, GlobalProperties, &WrtDatabase::interface())
98 DPL::Optional<DPL::String> result =
99 select->GetSingleValue<GlobalProperties::compliance_fake_meid>();
101 return std::string();
103 return DPL::ToUTF8String(*result);
105 Catch (DPL::DB::SqlConnection::Exception::Base){
106 ReThrowMsg(GlobalDAOReadOnly::Exception::DatabaseError,
107 "Failed to get compliance fake MEID");
111 bool GlobalDAOReadOnly::IsValidSubTag(const DPL::String& tag, int type)
113 using namespace DPL::DB::ORM;
114 using namespace DPL::DB::ORM::wrt;
115 WRT_DB_SELECT(select, iana_records, &WrtDatabase::interface())
116 select->Where(Equals<iana_records::SUBTAG>(tag));
117 auto row = select->GetRowList();
118 if (row.size() == 0 || row.front().Get_TYPE() != type) {
125 GlobalDAOReadOnly::NetworkAccessMode
126 GlobalDAOReadOnly::GetHomeNetworkDataUsage()
128 LogDebug("Getting home network data usage");
130 using namespace DPL::DB::ORM;
131 using namespace DPL::DB::ORM::wrt;
132 WRT_DB_SELECT(select, GlobalProperties, &WrtDatabase::interface())
133 return static_cast<GlobalDAOReadOnly::NetworkAccessMode>(
134 select->GetSingleValue<
135 GlobalProperties::home_network_data_usage>());
137 Catch(DPL::DB::SqlConnection::Exception::Base){
138 ReThrowMsg(GlobalDAOReadOnly::Exception::DatabaseError,
139 "Failed to get home network data usage");
143 GlobalDAOReadOnly::NetworkAccessMode GlobalDAOReadOnly::GetRoamingDataUsage()
145 LogDebug("Getting roaming network data usage");
147 using namespace DPL::DB::ORM;
148 using namespace DPL::DB::ORM::wrt;
149 WRT_DB_SELECT(select, GlobalProperties, &WrtDatabase::interface())
150 return static_cast<GlobalDAOReadOnly::NetworkAccessMode>(
151 select->GetSingleValue<GlobalProperties::roaming_data_usage>());
153 Catch(DPL::DB::SqlConnection::Exception::Base){
154 ReThrowMsg(GlobalDAOReadOnly::Exception::DatabaseError,
155 "Failed to get roaming network data usage");
159 //user agent strings are stored in db...
160 //and it is configurable for test in development.
161 DPL::String GlobalDAOReadOnly::GetUserAgentValue(const DPL::String &key)
163 LogDebug("Get User Agent Value : " << key);
165 using namespace DPL::DB::ORM;
166 using namespace DPL::DB::ORM::wrt;
167 WRT_DB_SELECT(select, UserAgents, &WrtDatabase::interface())
168 select->Where(Equals<UserAgents::key_name>(key));
169 DPL::Optional<DPL::String> agent =
170 select->GetSingleValue<UserAgents::key_value>();
171 if (agent.IsNull()) {
172 return DPL::FromUTF8String("");
177 Catch(DPL::DB::SqlConnection::Exception::Base){
178 ReThrowMsg(GlobalDAOReadOnly::Exception::DatabaseError,
179 "Failed to get user agent string");
183 DeviceCapabilitySet GlobalDAOReadOnly::GetDeviceCapability(
184 const DPL::String &apifeature)
186 // This could be done with one simply sql query but support for join is
189 using namespace DPL::DB::ORM; using namespace DPL::DB::ORM::wrt;
192 FeatureDeviceCapProxy::Select::RowList rows;
193 DeviceCapabilitySet result;
196 WRT_DB_SELECT(select, FeaturesList, &WrtDatabase::interface())
197 select->Where(Equals<FeaturesList::FeatureName>(apifeature));
198 featureUUID = select->GetSingleValue<FeaturesList::FeatureUUID>();
202 WRT_DB_SELECT(select, FeatureDeviceCapProxy, &WrtDatabase::interface())
203 select->Where(Equals<FeatureDeviceCapProxy::FeatureUUID>(
205 rows = select->GetRowList();
209 WRT_DB_SELECT(select, DeviceCapabilities, &WrtDatabase::interface())
210 select->Where(Equals<DeviceCapabilities::DeviceCapID>(
211 it->Get_DeviceCapID()));
212 result.insert(select->
213 GetSingleValue<DeviceCapabilities::DeviceCapName>());
217 }Catch(DPL::DB::SqlConnection::Exception::Base){
218 ReThrowMsg(GlobalDAOReadOnly::Exception::DatabaseError,
219 "Failed to update roaming network data usage");
223 WidgetAccessInfoList GlobalDAOReadOnly::GetWhiteURIList()
225 LogDebug("Getting WhiteURIList.");
227 using namespace DPL::DB::ORM;
228 using namespace DPL::DB::ORM::wrt;
229 WRT_DB_SELECT(select, WidgetWhiteURIList, &WrtDatabase::interface())
231 WidgetAccessInfoList resultList;
232 typedef std::list<WidgetWhiteURIList::Row> RowList;
233 RowList list = select->GetRowList();
235 for (RowList::iterator i = list.begin(); i != list.end(); ++i) {
236 WidgetAccessInfo whiteURI;
237 whiteURI.strIRI = i->Get_uri();
238 whiteURI.bSubDomains = i->Get_subdomain_access();
239 resultList.push_back(whiteURI);
240 LogInfo("[uri] : " << whiteURI.strIRI <<
241 ", [subdomain] : " << whiteURI.bSubDomains);
244 } Catch(DPL::DB::SqlConnection::Exception::Base) {
245 ReThrowMsg(GlobalDAOReadOnly::Exception::DatabaseError,
246 "Failed to get whiteURI list");
250 bool GlobalDAOReadOnly::GetCookieSharingMode()
252 LogDebug("Getting Cookie Sharing mode");
254 using namespace DPL::DB::ORM;
255 using namespace DPL::DB::ORM::wrt;
256 WRT_DB_SELECT(select, GlobalProperties, &WrtDatabase::interface())
257 return select->GetSingleValue<GlobalProperties::cookie_sharing_mode>();
259 Catch(DPL::DB::SqlConnection::Exception::Base){
260 ReThrowMsg(GlobalDAOReadOnly::Exception::DatabaseError,
261 "Failed to get Cookie Sharing mode");