pull in new policy updates
[profile/ivi/smartdevicelink.git] / src / components / policy / src / policy / src / sql_pt_ext_queries.cc
1 /*
2  Copyright (c) 2013, " Ford Motor Company
3  All rights reserved.
4
5  Redistribution and use in source and binary forms, " with or without
6  modification, " are permitted provided that the following conditions are met:
7
8  Redistributions of source code must retain the above copyright notice, " this
9  list of conditions and the following disclaimer.
10
11  Redistributions in binary form must reproduce the above copyright notice, "
12  this list of conditions and the following
13  disclaimer in the documentation and/or other materials provided with the
14  distribution.
15
16  Neither the name of the Ford Motor Company nor the names of its contributors
17  may be used to endorse or promote products derived from this software
18  without specific prior written permission.
19
20  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  AND ANY EXPRESS OR IMPLIED WARRANTIES, " INCLUDING, " BUT NOT LIMITED TO, " THE
22  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
24  LIABLE FOR ANY DIRECT, " INDIRECT, " INCIDENTAL, " SPECIAL, " EXEMPLARY, " OR
25  CONSEQUENTIAL DAMAGES (INCLUDING, " BUT NOT LIMITED TO, " PROCUREMENT OF
26  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, " DATA, " OR PROFITS; OR BUSINESS
27  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, " WHETHER IN
28  CONTRACT, " STRICT LIABILITY, " OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, " EVEN IF ADVISED OF THE
30  POSSIBILITY OF SUCH DAMAGE.
31  */
32
33 #include "policy/sql_pt_ext_queries.h"
34
35 namespace policy {
36 namespace sql_pt_ext {
37
38 const std::string kSelectKeepContext =
39   "SELECT `keep_context` FROM `application` WHERE `id` = ? LIMIT 1";
40
41 const std::string kSelectStealFocus =
42   "SELECT `steal_focus` FROM `application` WHERE `id` = ? LIMIT 1";
43
44 const std::string kSelectDefaultHmi =
45   "SELECT `default_hmi` FROM `application` WHERE `id` = ? LIMIT 1";
46
47 const std::string kSelectPriority =
48   "SELECT `priority_value` FROM `application` WHERE `id` = ? LIMIT 1";
49
50 const std::string kResetDeviceConsents = "DELETE FROM `device_consent_group`";
51
52 const std::string kResetAppConsents = "DELETE FROM `consent_group`";
53
54 const std::string kCountDeviceConsentGroup = "SELECT COUNT (`device_id`) "
55     "FROM `device_consent_group` WHERE `device_id` = ?";
56
57 const std::string kCountDevice = "SELECT COUNT (`id`) "
58                                  "FROM `device` WHERE `id` = ?";
59
60 const std::string kSelectDeviceConsentedGroup =
61   "SELECT * FROM `device_consent_group` WHERE `device_id` = ?";
62
63 const std::string kUpdateDeviceConsentedGroup =
64   "UPDATE `device_consent_group` SET `is_consented` = ? WHERE "
65   "(`device_id` = ? AND `functional_group_id` = ?)";
66
67 const std::string kUpdateDevice =
68   "UPDATE `device` SET `hardware` = ?, `firmware_rev` = ?, `os` = ?, "
69   "`os_version` = ?, `carrier` = ?, `max_number_rfcom_ports` = ? "
70   "WHERE `id` = ? ";
71
72 const std::string kInsertDeviceConsentedGroup =
73   "INSERT OR IGNORE INTO `device_consent_group` "
74   "(`device_id`, `functional_group_id`, `is_consented`, `input`) "
75   "VALUES (?,?,?,?)";
76
77 const std::string kInsertDevice =
78   "INSERT OR IGNORE INTO `device` "
79   "(`id`, `hardware`, `firmware_rev`, `os`, `os_version`, `carrier`, `max_number_rfcom_ports`) "
80   "VALUES (?,?,?,?,?,?,?)";
81
82 const std::string kSelectDeviceData = "SELECT * FROM `device`";
83
84 const std::string kSelectConsentGroup =
85   "SELECT * FROM `consent_group` WHERE `device_id` = ? ";
86
87 const std::string kInsertPreconsentedGroups =
88   "INSERT INTO `preconsented_group` (`application_id`, `functional_group_id`)"
89   "  SELECT ?, `id` FROM `functional_group` WHERE `name` = ? LIMIT 1";
90
91 const std::string kSelectPreconsentedGroups =
92   "SELECT `f`.`name` FROM `preconsented_group` AS `p`"
93   "  LEFT JOIN `functional_group` AS `f` "
94   "    ON (`f`.`id` = `p`.`functional_group_id`)"
95   "  WHERE `p`.`application_id` = ?";
96
97 const std::string kDeletePreconsentedGroups = "DELETE FROM `preconsented_group`";
98
99 const std::string kSelectUsageAndErrorCount =
100   "SELECT `count_of_iap_buffer_full`, `count_sync_out_of_memory`, "
101   "  `count_of_sync_reboots` "
102   "FROM `usage_and_error_count` LIMIT 1";
103
104 const std::string kSelectAppLevels =
105   "SELECT `application_id`, `minutes_in_hmi_full`, `minutes_in_hmi_limited`, "
106   "  `minutes_in_hmi_background`, `minutes_in_hmi_none`, "
107   "  `count_of_rfcomm_limit_reached`, `count_of_user_selections`, "
108   "  `count_of_rejections_sync_out_of_memory`, "
109   "  `count_of_rejections_nickname_mismatch`, "
110   "  `count_of_rejections_duplicate_name`, "
111   "  `count_of_rejected_rpcs_calls`, "
112   "  `count_of_rpcs_sent_in_hmi_none`, "
113   "  `count_of_removals_for_bad_behavior`, "
114   "  `count_of_run_attempts_while_revoked`, "
115   "  `app_registration_language_gui`, "
116   "  `app_registration_language_vui` "
117   "FROM `app_level`";
118 const std::string kInsertDeviceData =
119   "INSERT OR IGNORE INTO `device` "
120   "(`id`, `hardware`, `firmware_rev`, `os`, `os_version`, `carrier`, `max_number_rfcom_ports`) "
121   "VALUES (?,?,?,?,?,?,?) ";
122
123 const std::string kInsertConsentGroups =
124   "INSERT OR IGNORE INTO `consent_group` "
125   "(`device_id`, `application_id`, `functional_group_id`, `is_consented`, `input`) "
126   "VALUES (?,?,?,?,?)";
127
128 const std::string kCountUnconsentedGroups =
129   "SELECT COUNT(`a`.`functional_group_id`) FROM `app_group` AS `a` "
130   " WHERE `a`.`application_id` = ?  AND NOT EXISTS "
131   " (SELECT NULL FROM `preconsented_group` AS `p` WHERE "
132   " (`p`.`functional_group_id` = `a`.`functional_group_id` AND "
133   " `p`.`application_id` = `a`.`application_id`)) "
134   " AND NOT EXISTS (SELECT NULL FROM `consent_group` AS `c` "
135   " WHERE (`c`.`application_id` = `a`.`application_id` "
136   " AND `c`.`functional_group_id` = `a`.`functional_group_id` "
137   " AND `c`.`device_id` = ?)) AND NOT EXISTS "
138   " (SELECT NULL FROM `app_group` AS `def` WHERE "
139   " (`def`.`application_id` = ? OR "
140   " `def`.`application_id` = ?) "
141   " AND `def`.`functional_group_id` = `a`.`functional_group_id`)";
142
143
144 const std::string kSelectModuleMeta = "SELECT* FROM `module_meta`";
145
146 const std::string kUpdateMetaParams = "UPDATE `module_meta` SET "
147                                       "`ccpu_version` = ?, `wers_country_code` = ?, `language` = ? ";
148
149 const std::string kUpdateMetaLanguage = "UPDATE `module_meta` SET `language` = ? ";
150
151 const std::string kCountAppLevel =
152   "SELECT COUNT(`application_id`) FROM `app_level`"
153   " WHERE `application_id` = ? ";
154
155 const std::string kUpdateGroupPermissions =
156   "UPDATE `consent_group` "
157   "SET `is_consented` = ?, `input` = ? "
158   "WHERE(`application_id` = ? AND `functional_group_id` = ? AND `device_id` = ?) ";
159
160 const std::string kInsertApplication =
161   "INSERT OR IGNORE INTO `application`(`id`, `keep_context`, `steal_focus`, "
162   " `default_hmi`, `priority_value`, `is_revoked`, `memory_kb`, "
163   " `heart_beat_timeout_ms`, `certificate`) VALUES( ?, ?, ?, ?, ?, ?, ?, ?, ?) ";
164
165 const std::string kSelectFriendlyMsg =
166   "SELECT `tts`, `label`, `line1`, `line2`, `textBody` FROM `message` "
167   "WHERE `message_type_name` = ? AND `language_code` = ? LIMIT 1";
168
169 const std::string kSelectAppGroupsId = "SELECT `functional_group_id` "
170                                        "FROM `app_group` WHERE `application_id` = ? ";
171
172 const std::string kSelectConsentedGroupsId =
173   "SELECT `functional_group_id`, `is_consented` "
174   "FROM `consent_group` WHERE(`application_id` = ? AND `device_id` = ?) ";
175
176 const std::string kCountAppConsents = "SELECT COUNT(*) from `consent_group`"
177                                       "WHERE(`device_id` = ? AND `application_id` = ? AND "
178                                       "`functional_group_id` = ?) ";
179
180 const std::string kSelectPreconsentedGroupsId = "SELECT `functional_group_id` "
181     "FROM `preconsented_group` WHERE `application_id` = ? ";
182
183 const std::string kSelectAppPolicies =
184   "SELECT `id`, `priority_value`, `default_hmi`, `keep_context`, `steal_focus`, "
185   " `memory_kb`, `heart_beat_timeout_ms`, `certificate` FROM `application`";
186
187 const std::string kSelectFunctionalGroupNames = "SELECT `id`, `user_consent_prompt`, `name`"
188     " FROM `functional_group`";
189
190 const std::string kDeleteDeviceConsent = "DELETE FROM `device_consent_group` "
191     "WHERE `device_id` = ? ";
192
193 const std::string kDeleteAppConsent = "DELETE FROM `consent_group` "
194                                       "WHERE `device_id` = ? ";
195
196 const std::string kSelectApplicationIsPreData =
197   "SELECT `is_predata` FROM `application` WHERE `id` = ? ";
198
199 const std::string kUpdateIsPredata =
200   "UPDATE `application` SET `is_predata` = ? WHERE `id` = ? ";
201
202 const std::string kHasAppPreloadedGroups =
203   "SELECT COUNT(`a1`.`functional_group_id`) FROM `app_group` "
204   " AS `a1` JOIN `app_group` AS `a2` "
205   " ON `a1`.`functional_group_id` = `a2`.`functional_group_id` "
206   " WHERE `a1`.`application_id` = ? AND `a2`.`application_id` = ? ";
207
208 const std::string kUpdateUnpairedDevice =
209   "UPDATE `device` SET `unpaired` = ? WHERE `id` = ? ";
210
211 const std::string kSelectUnpairedDevices =
212   "SELECT `id` FROM `device` WHERE `unpaired` = 1";
213
214 }  // namespace sql_pt_ext
215 }  // namespace policy