Update privilege string, PackageAppInfo for wgt
[platform/framework/native/appfw.git] / src / app / FAppNotificationManager.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 /**
19  * @file                FAppNotificationManager.cpp
20  * @brief               This is the placeholder for NotificationManager class.
21  */
22
23 #include <new>
24
25 #include <FAppNotificationManager.h>
26
27 #include <FBaseSysLog.h>
28 #include <FSec_AccessController.h>
29 #include "FApp_NotificationManagerImpl.h"
30
31 using namespace Tizen::Base;
32 using namespace Tizen::Security;
33
34 namespace Tizen { namespace App
35 {
36
37 NotificationManager::NotificationManager()
38         : __pNotificationManagerImpl(null)
39 {
40         //default constructor
41 }
42
43 NotificationManager::~NotificationManager()
44 {
45         delete __pNotificationManagerImpl;
46 }
47
48 result
49 NotificationManager::Construct(void)
50 {
51         SysAssertf(__pNotificationManagerImpl == null,
52                         "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
53
54         __pNotificationManagerImpl = new (std::nothrow) _NotificationManagerImpl();
55         SysTryReturnResult(NID_APP, __pNotificationManagerImpl != null, E_OUT_OF_MEMORY, "Allocation failed.");
56
57         return __pNotificationManagerImpl->Construct();
58 }
59
60 int
61 NotificationManager::GetBadgeNumber(void)
62 {
63         SysAssertf(__pNotificationManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
64
65         result r = _AccessController::CheckUserPrivilege(_PRV_NOTIFICATION);
66         SysTryReturnResult(NID_APP,  !IsFailed(r), E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
67
68         return __pNotificationManagerImpl->GetBadgeNumber();
69 }
70
71 result
72 NotificationManager::Notify(int badgeNumber)
73 {
74         SysAssertf(__pNotificationManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
75
76         result r = _AccessController::CheckUserPrivilege(_PRV_NOTIFICATION);
77         SysTryReturnResult(NID_APP,  !IsFailed(r), E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
78
79         return __pNotificationManagerImpl->Notify(badgeNumber);
80 }
81
82 result
83 NotificationManager::Notify(const String& messageText)
84 {
85         SysAssertf(__pNotificationManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
86
87         result r = _AccessController::CheckUserPrivilege(_PRV_NOTIFICATION);
88         SysTryReturnResult(NID_APP,  !IsFailed(r), E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
89
90         return __pNotificationManagerImpl->Notify(messageText);
91 }
92
93 result
94 NotificationManager::Notify(const String& messageText, int badgeNumber)
95 {
96         SysAssertf(__pNotificationManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
97
98         result r = _AccessController::CheckUserPrivilege(_PRV_NOTIFICATION);
99         SysTryReturnResult(NID_APP,  !IsFailed(r), E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
100
101         return __pNotificationManagerImpl->Notify(messageText, badgeNumber);
102 }
103
104 result
105 NotificationManager::Notify(const String& messageText, int badgeNumber, const String& launchArguments)
106 {
107         SysAssertf(__pNotificationManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
108
109         result r = _AccessController::CheckUserPrivilege(_PRV_NOTIFICATION);
110         SysTryReturnResult(NID_APP,  !IsFailed(r), E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
111
112         return __pNotificationManagerImpl->Notify(messageText, badgeNumber, launchArguments);
113 }
114
115 int
116 NotificationManager::GetBadgeNumber(const AppId& appId)
117 {
118         SysAssertf(__pNotificationManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
119
120         result r = _AccessController::CheckUserPrivilege(_PRV_NOTIFICATION);
121         SysTryReturnResult(NID_APP,  !IsFailed(r), E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
122
123         return __pNotificationManagerImpl->GetBadgeNumber(appId);
124 }
125
126
127 result
128 NotificationManager::NotifyOnBehalf(const AppId& appId, int badgeNumber)
129 {
130         SysAssertf(__pNotificationManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
131
132         result r = _AccessController::CheckUserPrivilege(_PRV_NOTIFICATION, _PRV_NOTIFICATIONMANAGER);
133         SysTryReturnResult(NID_APP,  !IsFailed(r), E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
134
135         return __pNotificationManagerImpl->NotifyOnBehalf(appId, badgeNumber);
136 }
137
138 result
139 NotificationManager::NotifyOnBehalf(const AppId& appId, const String& messageText)
140 {
141         SysAssertf(__pNotificationManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
142
143         result r = _AccessController::CheckUserPrivilege(_PRV_NOTIFICATION, _PRV_NOTIFICATIONMANAGER);
144         SysTryReturnResult(NID_APP,  !IsFailed(r), E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
145
146         return __pNotificationManagerImpl->NotifyOnBehalf(appId, messageText);
147 }
148
149 result
150 NotificationManager::NotifyOnBehalf(const AppId& appId, const String& messageText, int badgeNumber)
151 {
152         SysAssertf(__pNotificationManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
153
154         result r = _AccessController::CheckUserPrivilege(_PRV_NOTIFICATION, _PRV_NOTIFICATIONMANAGER);
155         SysTryReturnResult(NID_APP,  !IsFailed(r), E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
156
157         return __pNotificationManagerImpl->NotifyOnBehalf(appId, messageText, badgeNumber);
158 }
159
160 result
161 NotificationManager::NotifyOnBehalf(const AppId& appId, const String& messageText, const String& launchArguments)
162 {
163         SysAssertf(__pNotificationManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
164
165         result r = _AccessController::CheckUserPrivilege(_PRV_NOTIFICATION, _PRV_NOTIFICATIONMANAGER);
166         SysTryReturnResult(NID_APP,  !IsFailed(r), E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
167
168         return __pNotificationManagerImpl->NotifyOnBehalf(appId, messageText, launchArguments);
169 }
170
171 result
172 NotificationManager::NotifyOngoingActivity(const String& messageText)
173 {
174         SysAssertf(__pNotificationManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
175
176         result r = _AccessController::CheckUserPrivilege(_PRV_NOTIFICATION);
177         SysTryReturnResult(NID_APP,  !IsFailed(r), E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
178
179         return __pNotificationManagerImpl->NotifyOngoingActivity(messageText);
180 }
181
182 result
183 NotificationManager::NotifyOngoingActivity(const String& messageText, const String& launchArguments)
184 {
185         SysAssertf(__pNotificationManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
186
187         result r = _AccessController::CheckUserPrivilege(_PRV_NOTIFICATION);
188         SysTryReturnResult(NID_APP,  !IsFailed(r), E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
189
190
191         return __pNotificationManagerImpl->NotifyOngoingActivity(messageText, launchArguments);
192 }
193
194 result
195 NotificationManager::NotifyOngoingActivityOnBehalf(const AppId& appId, const String& messageText)
196 {
197         SysAssertf(__pNotificationManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
198
199         result r = _AccessController::CheckUserPrivilege(_PRV_NOTIFICATION, _PRV_NOTIFICATIONMANAGER);
200         SysTryReturnResult(NID_APP,  !IsFailed(r), E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
201
202
203         return __pNotificationManagerImpl->NotifyOngoingActivityOnBehalf(appId, messageText);
204 }
205
206 result
207 NotificationManager::NotifyOngoingActivityOnBehalf(const AppId& appId, const String& messageText, const String& launchArguments)
208 {
209         SysAssertf(__pNotificationManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
210
211         result r = _AccessController::CheckUserPrivilege(_PRV_NOTIFICATION, _PRV_NOTIFICATIONMANAGER);
212         SysTryReturnResult(NID_APP,  !IsFailed(r), E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
213
214         return __pNotificationManagerImpl->NotifyOngoingActivityOnBehalf(appId, messageText, launchArguments);
215 }
216
217 result
218 NotificationManager::RemoveOngoingActivityNotification(void)
219 {
220         SysAssertf(__pNotificationManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
221
222         result r = _AccessController::CheckUserPrivilege(_PRV_NOTIFICATION);
223         SysTryReturnResult(NID_APP,  !IsFailed(r), E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
224
225         return __pNotificationManagerImpl->RemoveOngoingActivityNotification();
226 }
227
228 result
229 NotificationManager::RemoveOngoingActivityNotificationOnBehalf(const AppId& appId)
230 {
231         SysAssertf(__pNotificationManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
232
233         result r = _AccessController::CheckUserPrivilege(_PRV_NOTIFICATION, _PRV_NOTIFICATIONMANAGER);
234         SysTryReturnResult(NID_APP,  !IsFailed(r), E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
235
236         return __pNotificationManagerImpl->RemoveOngoingActivityNotificationOnBehalf(appId);
237 }
238
239 result
240 NotificationManager::RemoveNotification(void)
241 {
242         SysAssertf(__pNotificationManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
243
244         result r = _AccessController::CheckUserPrivilege(_PRV_NOTIFICATION);
245         SysTryReturnResult(NID_APP,  !IsFailed(r), E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
246
247         return __pNotificationManagerImpl->RemoveNotification();
248 }
249
250 result
251 NotificationManager::RemoveNotificationOnBehalf(const AppId& appId)
252 {
253         SysAssertf(__pNotificationManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
254
255         result r = _AccessController::CheckUserPrivilege(_PRV_NOTIFICATION, _PRV_NOTIFICATIONMANAGER);
256         SysTryReturnResult(NID_APP,  !IsFailed(r), E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
257
258         return __pNotificationManagerImpl->RemoveNotificationOnBehalf(appId);
259 }
260
261 };
262 };    // Tizen::App