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