License and Privilege changes
[apps/osp/Call.git] / src / CallAppControlRequestMgr.cpp
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Flora License, Version 1.1 (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://floralicense.org/license/
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        CallAppControlRequestMgr.cpp
19  * @brief       Manages AppControl Request to other apps.
20  */
21 #include <FApp.h>
22 #include "CallAppControlRequestMgr.h"
23 #include "CallTypes.h"
24
25 using namespace Tizen::App;
26 using namespace Tizen::Base;
27 using namespace Tizen::Base::Collection;
28
29 CallAppControlRequestMgr* CallAppControlRequestMgr::__pInstance = null;
30
31 CallAppControlRequestMgr::CallAppControlRequestMgr(void)
32 {
33         __pOpenedAppControl = null;
34 }
35
36 CallAppControlRequestMgr::~CallAppControlRequestMgr(void)
37 {
38         if (__pOpenedAppControl != null)
39         {
40                 delete __pOpenedAppControl;
41                 __pOpenedAppControl = null;
42         }
43 }
44
45 void
46 CallAppControlRequestMgr::CreateInstance(void)
47 {
48         __pInstance = new (std::nothrow) CallAppControlRequestMgr();
49         result r = __pInstance->Construct();
50         if(IsFailed(r))
51         {
52                 delete __pInstance;
53                 __pInstance = null;
54                 return;
55         }
56
57         std::atexit(DestroyInstance);
58 }
59
60 CallAppControlRequestMgr*
61 CallAppControlRequestMgr::GetInstance(void)
62 {
63         if (__pInstance == null)
64         {
65                 CreateInstance();
66         }
67         return __pInstance;
68 }
69
70 void
71 CallAppControlRequestMgr::DestroyInstance(void)
72 {
73         if (__pInstance != null)
74         {
75                 delete __pInstance;
76                 __pInstance = null;
77         }
78 }
79
80 result
81 CallAppControlRequestMgr::Construct(void)
82 {
83         return E_SUCCESS;
84 }
85
86 bool
87 CallAppControlRequestMgr::IsAppControlRunning(void)
88 {
89         AppLog("ENTER");
90         return (__pOpenedAppControl != null);
91 }
92
93 void
94 CallAppControlRequestMgr::AbortAppControlRequest(void)
95 {
96         AppLog("ENTER");
97         if (__pOpenedAppControl != null)
98         {
99                 result r = __pOpenedAppControl->Stop();
100                 AppLog("Abort failed with r=%d", r);
101                 delete __pOpenedAppControl;
102                 __pOpenedAppControl = null;
103         }
104         AppLog("ENTER");
105 }
106
107 void
108 CallAppControlRequestMgr::AppControlRequestCompleted(void)
109 {
110         AppLog("ENTER");
111         if (__pOpenedAppControl != null)
112         {
113                 delete __pOpenedAppControl;
114                 __pOpenedAppControl = null;
115         }
116 }
117
118 bool
119 CallAppControlRequestMgr::LaunchComposeMessageAppControl(String& contactNumber, IAppControlResponseListener* pListener)
120 {
121         if (__pOpenedAppControl != null)
122         {
123                 //An AppControl is already running.
124                 String provider = __pOpenedAppControl->GetAppControlProviderId();
125                 String operation = __pOpenedAppControl->GetOperationId();
126                 AppLog( "Error:- AppControl is already running for provider id = %ls, operation id = %ls",
127                                 provider.GetPointer(), operation.GetPointer());
128                 return false;
129         }
130
131         result r = E_FAILURE;
132         //request parameters
133         HashMap extraData;
134         extraData.Construct();
135         extraData.Add(new (std::nothrow) String(MESSAGE_TYPE), new (std::nothrow) String(MESSAGE_SMS_TYPE));
136         extraData.Add(new (std::nothrow) String(MESSAGE_TO), new (std::nothrow) String(contactNumber));
137
138         __pOpenedAppControl = AppManager::FindAppControlN(PROVIDER_ID_MESSAGE, OPERATION_ID_COMPOSE);
139         if (__pOpenedAppControl != null)
140         {
141                 r = __pOpenedAppControl->Start(null, null, &extraData, pListener);
142         }
143         extraData.RemoveAll(true);
144
145         if(r != E_SUCCESS)
146         {
147                 //AppControl request failed, delete AppControl.
148                 delete __pOpenedAppControl;
149                 __pOpenedAppControl = null;
150                 return false;
151         }
152         else
153         {
154                 //AppControl request was successful.
155                 return true;
156         }
157 }
158
159 bool
160 CallAppControlRequestMgr::LaunchViewContactAppControl(String& contactId, IAppControlResponseListener* pListener)
161 {
162         AppLogDebug("ENTER");
163         if (__pOpenedAppControl != null)
164         {
165                 //An AppControl is already running.
166                 String provider = __pOpenedAppControl->GetAppControlProviderId();
167                 String operation = __pOpenedAppControl->GetOperationId();
168                 AppLog( "Error:- AppControl is already running for provider id = %ls, operation id = %ls",
169                                 provider.GetPointer(), operation.GetPointer());
170                 return false;
171         }
172
173         result r = E_FAILURE;
174         //request parameters
175         HashMap extraData;
176         extraData.Construct();
177         extraData.Add(new (std::nothrow) String(CONTACTS_VIEW_TYPE), new (std::nothrow) String(CONTACTS_VIEW_TYPE_CONTACT));
178         extraData.Add(new (std::nothrow) String(CONTACTS_VIEW_TYPE_CONTACT), new (std::nothrow) String(CONTACTS_VIEW_TYPE_CONTACT));
179         extraData.Add(new (std::nothrow) String(CONTACT_KEY_ITEM_ID), new (std::nothrow) String(contactId));
180         extraData.Add(new (std::nothrow) String(CONTACTS_ID_KEY), new (std::nothrow) String(contactId));
181         extraData.Add(new (std::nothrow) String(CONTACT_KEY_ITEM_TYPE), new (std::nothrow) String(ITEM_TYPE_PERSON));
182
183         __pOpenedAppControl = AppManager::FindAppControlN(PROVIDER_ID_CONTACTS, OPERATION_ID_VIEW);
184         if (__pOpenedAppControl != null)
185         {
186                 r = __pOpenedAppControl->Start(null, null, &extraData, pListener);
187         }
188         extraData.RemoveAll(true);
189
190         if(r != E_SUCCESS)
191         {
192                 //AppControl request failed, delete AppControl.
193                 delete __pOpenedAppControl;
194                 __pOpenedAppControl = null;
195                 return false;
196         }
197         else
198         {
199                 //AppControl request was successful.
200                 return true;
201         }
202 }
203
204 bool
205 CallAppControlRequestMgr::LaunchAddContactAppControl(String& contactNumber, IAppControlResponseListener* pListener)
206 {
207         AppLogDebug("ENTER");
208         if (__pOpenedAppControl != null)
209         {
210                 //An AppControl is already running.
211                 String provider = __pOpenedAppControl->GetAppControlProviderId();
212                 String operation = __pOpenedAppControl->GetOperationId();
213                 AppLog( "Error:- AppControl is already running for provider id = %ls, operation id = %ls",
214                                 provider.GetPointer(), operation.GetPointer());
215                 return false;
216         }
217
218         result r = E_FAILURE;
219         //request parameters
220         HashMap extraData;
221         extraData.Construct();
222         extraData.Add(new (std::nothrow) String(INPUT_TYPE_PHONE), new (std::nothrow) String(contactNumber));
223         extraData.Add(new (std::nothrow) String(CONTACT_KEY_ITEM_TYPE), new (std::nothrow) String(ITEM_TYPE_CONTACT));
224
225         __pOpenedAppControl = AppManager::FindAppControlN(PROVIDER_ID_CONTACTS, OPERATION_ID_ADD);
226         if (__pOpenedAppControl != null)
227         {
228                 r = __pOpenedAppControl->Start(null, null, &extraData, pListener);
229         }
230         extraData.RemoveAll(true);
231
232         if(r != E_SUCCESS)
233         {
234                 //AppControl request failed, delete AppControl.
235                 delete __pOpenedAppControl;
236                 __pOpenedAppControl = null;
237                 return false;
238         }
239         else
240         {
241                 //AppControl request was successful.
242                 return true;
243         }
244 }
245
246 bool
247 CallAppControlRequestMgr::LaunchDialerAppControl(IAppControlResponseListener* pListener)
248 {
249         AppLogDebug("ENTER");
250         if (__pOpenedAppControl != null)
251         {
252                 //An AppControl is already running.
253                 String provider = __pOpenedAppControl->GetAppControlProviderId();
254                 String operation = __pOpenedAppControl->GetOperationId();
255                 AppLog( "Error:- AppControl is already running for provider id = %ls, operation id = %ls",
256                                 provider.GetPointer(), operation.GetPointer());
257                 return false;
258         }
259
260         result r = E_FAILURE;
261         HashMap extraData;
262         extraData.Construct();
263         extraData.Add(new (std::nothrow) String(PARAM_PHONE_NUMBER), new (std::nothrow) String(L""));
264
265         __pOpenedAppControl = AppManager::FindAppControlN(PROVIDER_ID_PHONE, OPERATION_ID_DIAL);
266         if (__pOpenedAppControl != null)
267         {
268                 r = __pOpenedAppControl->Start(null, null, &extraData, pListener);
269         }
270         extraData.RemoveAll(true);
271
272         if(r != E_SUCCESS)
273         {
274                 //AppControl request failed, delete AppControl.
275                 delete __pOpenedAppControl;
276                 __pOpenedAppControl = null;
277                 return false;
278         }
279         else
280         {
281                 //AppControl request was successful.
282                 return true;
283         }
284 }