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 WidgetPackageList GlobalDAOReadOnly::GetDefferedWidgetPackageInstallationList()
53 LogDebug("Getting widget packages list defered for installation");
55 using namespace DPL::DB::ORM;
56 using namespace DPL::DB::ORM::wrt;
57 WRT_DB_SELECT(select, DefferedWidgetPackageInstallation, &WrtDatabase::interface())
58 return select->GetValueList<DefferedWidgetPackageInstallation::path>();
60 Catch(DPL::DB::SqlConnection::Exception::Base){
61 ReThrowMsg(GlobalDAOReadOnly::Exception::DatabaseError,
62 "Failed to get defered widget packages list");
66 bool GlobalDAOReadOnly::GetSecureByDefault()
68 using namespace DPL::DB::ORM;
69 using namespace DPL::DB::ORM::wrt;
70 WRT_DB_SELECT(select, GlobalProperties, &WrtDatabase::interface())
71 return select->GetSingleValue<GlobalProperties::secure_by_default>();
74 bool GlobalDAOReadOnly::getComplianceMode()
76 LogDebug("Getting compliance mode");
78 using namespace DPL::DB::ORM; using namespace DPL::DB::ORM::wrt;
79 WRT_DB_SELECT(select, GlobalProperties, &WrtDatabase::interface())
80 return select->GetSingleValue<GlobalProperties::compliance_mode>();
82 Catch (DPL::DB::SqlConnection::Exception::Base){
83 ReThrowMsg(GlobalDAOReadOnly::Exception::DatabaseError,
84 "Failed to get compliance mode");
88 std::string GlobalDAOReadOnly::getComplianceFakeImei()
90 LogDebug("Getting compliance fake IMEI");
92 using namespace DPL::DB::ORM; using namespace DPL::DB::ORM::wrt;
93 WRT_DB_SELECT(select, GlobalProperties, &WrtDatabase::interface())
94 DPL::Optional<DPL::String> result =
95 select->GetSingleValue<GlobalProperties::compliance_fake_imei>();
99 return DPL::ToUTF8String(*result);
101 Catch (DPL::DB::SqlConnection::Exception::Base){
102 ReThrowMsg(GlobalDAOReadOnly::Exception::DatabaseError,
103 "Failed to get compliance fake IMEI");
107 std::string GlobalDAOReadOnly::getComplianceFakeMeid()
109 LogDebug("Getting compliance fake MEID");
111 using namespace DPL::DB::ORM; using namespace DPL::DB::ORM::wrt;
112 WRT_DB_SELECT(select, GlobalProperties, &WrtDatabase::interface())
113 DPL::Optional<DPL::String> result =
114 select->GetSingleValue<GlobalProperties::compliance_fake_meid>();
116 return std::string();
118 return DPL::ToUTF8String(*result);
120 Catch (DPL::DB::SqlConnection::Exception::Base){
121 ReThrowMsg(GlobalDAOReadOnly::Exception::DatabaseError,
122 "Failed to get compliance fake MEID");
126 bool GlobalDAOReadOnly::IsValidSubTag(const DPL::String& tag, int type)
128 using namespace DPL::DB::ORM;
129 using namespace DPL::DB::ORM::wrt;
130 WRT_DB_SELECT(select, iana_records, &WrtDatabase::interface())
131 select->Where(Equals<iana_records::SUBTAG>(tag));
132 auto row = select->GetRowList();
133 if (row.size() == 0 || row.front().Get_TYPE() != type) {
140 GlobalDAOReadOnly::NetworkAccessMode
141 GlobalDAOReadOnly::GetHomeNetworkDataUsage()
143 LogDebug("Getting home network data usage");
145 using namespace DPL::DB::ORM;
146 using namespace DPL::DB::ORM::wrt;
147 WRT_DB_SELECT(select, GlobalProperties, &WrtDatabase::interface())
148 return static_cast<GlobalDAOReadOnly::NetworkAccessMode>(
149 select->GetSingleValue<
150 GlobalProperties::home_network_data_usage>());
152 Catch(DPL::DB::SqlConnection::Exception::Base){
153 ReThrowMsg(GlobalDAOReadOnly::Exception::DatabaseError,
154 "Failed to get home network data usage");
158 GlobalDAOReadOnly::NetworkAccessMode GlobalDAOReadOnly::GetRoamingDataUsage()
160 LogDebug("Getting roaming network data usage");
162 using namespace DPL::DB::ORM;
163 using namespace DPL::DB::ORM::wrt;
164 WRT_DB_SELECT(select, GlobalProperties, &WrtDatabase::interface())
165 return static_cast<GlobalDAOReadOnly::NetworkAccessMode>(
166 select->GetSingleValue<GlobalProperties::roaming_data_usage>());
168 Catch(DPL::DB::SqlConnection::Exception::Base){
169 ReThrowMsg(GlobalDAOReadOnly::Exception::DatabaseError,
170 "Failed to get roaming network data usage");
174 //user agent strings are stored in db...
175 //and it is configurable for test in development.
176 DPL::String GlobalDAOReadOnly::GetUserAgentValue(const DPL::String &key)
178 LogDebug("Get User Agent Value : " << key);
180 using namespace DPL::DB::ORM;
181 using namespace DPL::DB::ORM::wrt;
182 WRT_DB_SELECT(select, UserAgents, &WrtDatabase::interface())
183 select->Where(Equals<UserAgents::key_name>(key));
184 DPL::Optional<DPL::String> agent =
185 select->GetSingleValue<UserAgents::key_value>();
186 if (agent.IsNull()) {
187 return DPL::FromUTF8String("");
192 Catch(DPL::DB::SqlConnection::Exception::Base){
193 ReThrowMsg(GlobalDAOReadOnly::Exception::DatabaseError,
194 "Failed to get user agent string");
198 DeviceCapabilitySet GlobalDAOReadOnly::GetDeviceCapability(
199 const DPL::String &apifeature)
201 // This could be done with one simply sql query but support for join is
204 using namespace DPL::DB::ORM; using namespace DPL::DB::ORM::wrt;
207 FeatureDeviceCapProxy::Select::RowList rows;
208 DeviceCapabilitySet result;
211 WRT_DB_SELECT(select, FeaturesList, &WrtDatabase::interface())
212 select->Where(Equals<FeaturesList::FeatureName>(apifeature));
213 featureUUID = select->GetSingleValue<FeaturesList::FeatureUUID>();
217 WRT_DB_SELECT(select, FeatureDeviceCapProxy, &WrtDatabase::interface())
218 select->Where(Equals<FeatureDeviceCapProxy::FeatureUUID>(
220 rows = select->GetRowList();
224 WRT_DB_SELECT(select, DeviceCapabilities, &WrtDatabase::interface())
225 select->Where(Equals<DeviceCapabilities::DeviceCapID>(
226 it->Get_DeviceCapID()));
227 result.insert(select->
228 GetSingleValue<DeviceCapabilities::DeviceCapName>());
232 }Catch(DPL::DB::SqlConnection::Exception::Base){
233 ReThrowMsg(GlobalDAOReadOnly::Exception::DatabaseError,
234 "Failed to update roaming network data usage");
238 WidgetAccessInfoList GlobalDAOReadOnly::GetWhiteURIList()
240 LogDebug("Getting WhiteURIList.");
242 using namespace DPL::DB::ORM;
243 using namespace DPL::DB::ORM::wrt;
244 WRT_DB_SELECT(select, WidgetWhiteURIList, &WrtDatabase::interface())
246 WidgetAccessInfoList resultList;
247 typedef std::list<WidgetWhiteURIList::Row> RowList;
248 RowList list = select->GetRowList();
250 for (RowList::iterator i = list.begin(); i != list.end(); ++i) {
251 WidgetAccessInfo whiteURI;
252 whiteURI.strIRI = i->Get_uri();
253 whiteURI.bSubDomains = i->Get_subdomain_access();
254 resultList.push_back(whiteURI);
255 LogInfo("[uri] : " << whiteURI.strIRI <<
256 ", [subdomain] : " << whiteURI.bSubDomains);
259 } Catch(DPL::DB::SqlConnection::Exception::Base) {
260 ReThrowMsg(GlobalDAOReadOnly::Exception::DatabaseError,
261 "Failed to get whiteURI list");