2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
8 // http://floralicense.org/license/
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.
18 * @file CallAppControlRequestMgr.cpp
19 * @brief Manages AppControl Request to other apps.
22 #include "CallAppControlRequestMgr.h"
23 #include "CallTypes.h"
25 using namespace Tizen::App;
26 using namespace Tizen::Base;
27 using namespace Tizen::Base::Collection;
29 CallAppControlRequestMgr* CallAppControlRequestMgr::__pInstance = null;
31 CallAppControlRequestMgr::CallAppControlRequestMgr(void)
33 __pOpenedAppControl = null;
36 CallAppControlRequestMgr::~CallAppControlRequestMgr(void)
38 if (__pOpenedAppControl != null)
40 delete __pOpenedAppControl;
41 __pOpenedAppControl = null;
46 CallAppControlRequestMgr::CreateInstance(void)
48 __pInstance = new (std::nothrow) CallAppControlRequestMgr();
49 result r = __pInstance->Construct();
57 std::atexit(DestroyInstance);
60 CallAppControlRequestMgr*
61 CallAppControlRequestMgr::GetInstance(void)
63 if (__pInstance == null)
71 CallAppControlRequestMgr::DestroyInstance(void)
73 if (__pInstance != null)
81 CallAppControlRequestMgr::Construct(void)
87 CallAppControlRequestMgr::IsAppControlRunning(void)
90 return (__pOpenedAppControl != null);
94 CallAppControlRequestMgr::AbortAppControlRequest(void)
97 if (__pOpenedAppControl != null)
99 result r = __pOpenedAppControl->Stop();
100 AppLog("Abort failed with r=%d", r);
101 delete __pOpenedAppControl;
102 __pOpenedAppControl = null;
108 CallAppControlRequestMgr::AppControlRequestCompleted(void)
111 if (__pOpenedAppControl != null)
113 delete __pOpenedAppControl;
114 __pOpenedAppControl = null;
119 CallAppControlRequestMgr::LaunchComposeMessageAppControl(String& contactNumber, IAppControlResponseListener* pListener)
121 String tempContactNumber;
123 int semiColonIndex = 0;
125 contactNumber.IndexOf(",", 0, commaIndex);
126 contactNumber.IndexOf(";", 0, semiColonIndex);
128 if(commaIndex != -1 && semiColonIndex != -1)
130 index = commaIndex < semiColonIndex ? commaIndex : semiColonIndex;
132 else if(commaIndex != -1 || semiColonIndex != -1)
134 index = commaIndex > semiColonIndex ? commaIndex : semiColonIndex;
138 index = contactNumber.GetLength();
140 contactNumber.SubString(0, index, tempContactNumber);
142 if (__pOpenedAppControl != null)
144 //An AppControl is already running.
145 String provider = __pOpenedAppControl->GetAppControlProviderId();
146 String operation = __pOpenedAppControl->GetOperationId();
147 AppLog( "Error:- AppControl is already running for provider id = %ls, operation id = %ls",
148 provider.GetPointer(), operation.GetPointer());
152 result r = E_FAILURE;
155 extraData.Construct();
156 extraData.Add(new (std::nothrow) String(MESSAGE_TYPE), new (std::nothrow) String(MESSAGE_SMS_TYPE));
157 extraData.Add(new (std::nothrow) String(MESSAGE_TO), new (std::nothrow) String(tempContactNumber));
159 __pOpenedAppControl = AppManager::FindAppControlN(PROVIDER_ID_MESSAGE, OPERATION_ID_COMPOSE);
160 if (__pOpenedAppControl != null)
162 r = __pOpenedAppControl->Start(null, null, &extraData, pListener);
164 extraData.RemoveAll(true);
168 //AppControl request failed, delete AppControl.
169 delete __pOpenedAppControl;
170 __pOpenedAppControl = null;
175 //AppControl request was successful.
181 CallAppControlRequestMgr::LaunchViewContactAppControl(String& contactId, IAppControlResponseListener* pListener)
183 AppLogDebug("ENTER");
184 if (__pOpenedAppControl != null)
186 //An AppControl is already running.
187 String provider = __pOpenedAppControl->GetAppControlProviderId();
188 String operation = __pOpenedAppControl->GetOperationId();
189 AppLog( "Error:- AppControl is already running for provider id = %ls, operation id = %ls",
190 provider.GetPointer(), operation.GetPointer());
194 result r = E_FAILURE;
197 extraData.Construct();
198 extraData.Add(new (std::nothrow) String(CONTACTS_VIEW_TYPE), new (std::nothrow) String(CONTACTS_VIEW_TYPE_CONTACT));
199 extraData.Add(new (std::nothrow) String(CONTACTS_VIEW_TYPE_CONTACT), new (std::nothrow) String(CONTACTS_VIEW_TYPE_CONTACT));
200 extraData.Add(new (std::nothrow) String(CONTACT_KEY_ITEM_ID), new (std::nothrow) String(contactId));
201 extraData.Add(new (std::nothrow) String(CONTACTS_ID_KEY), new (std::nothrow) String(contactId));
202 extraData.Add(new (std::nothrow) String(CONTACT_KEY_ITEM_TYPE), new (std::nothrow) String(ITEM_TYPE_PERSON));
204 __pOpenedAppControl = AppManager::FindAppControlN(PROVIDER_ID_CONTACTS, OPERATION_ID_VIEW);
205 if (__pOpenedAppControl != null)
207 r = __pOpenedAppControl->Start(null, null, &extraData, pListener);
209 extraData.RemoveAll(true);
213 //AppControl request failed, delete AppControl.
214 delete __pOpenedAppControl;
215 __pOpenedAppControl = null;
220 //AppControl request was successful.
226 CallAppControlRequestMgr::LaunchAddContactAppControl(String& contactNumber, IAppControlResponseListener* pListener)
228 AppLogDebug("ENTER");
229 if (__pOpenedAppControl != null)
231 //An AppControl is already running.
232 String provider = __pOpenedAppControl->GetAppControlProviderId();
233 String operation = __pOpenedAppControl->GetOperationId();
234 AppLog( "Error:- AppControl is already running for provider id = %ls, operation id = %ls",
235 provider.GetPointer(), operation.GetPointer());
239 result r = E_FAILURE;
242 extraData.Construct();
243 extraData.Add(new (std::nothrow) String(INPUT_TYPE_PHONE), new (std::nothrow) String(contactNumber));
244 extraData.Add(new (std::nothrow) String(CONTACT_KEY_ITEM_TYPE), new (std::nothrow) String(ITEM_TYPE_CONTACT));
246 __pOpenedAppControl = AppManager::FindAppControlN(PROVIDER_ID_CONTACTS, OPERATION_ID_ADD);
247 if (__pOpenedAppControl != null)
249 r = __pOpenedAppControl->Start(null, null, &extraData, pListener);
251 extraData.RemoveAll(true);
255 //AppControl request failed, delete AppControl.
256 delete __pOpenedAppControl;
257 __pOpenedAppControl = null;
262 //AppControl request was successful.
268 CallAppControlRequestMgr::LaunchDialerAppControl(IAppControlResponseListener* pListener)
270 AppLogDebug("ENTER");
271 if (__pOpenedAppControl != null)
273 //An AppControl is already running.
274 String provider = __pOpenedAppControl->GetAppControlProviderId();
275 String operation = __pOpenedAppControl->GetOperationId();
276 AppLog( "Error:- AppControl is already running for provider id = %ls, operation id = %ls",
277 provider.GetPointer(), operation.GetPointer());
281 result r = E_FAILURE;
283 extraData.Construct();
284 extraData.Add(new (std::nothrow) String(PARAM_PHONE_NUMBER), new (std::nothrow) String(L""));
286 __pOpenedAppControl = AppManager::FindAppControlN(PROVIDER_ID_PHONE, OPERATION_ID_DIAL);
287 if (__pOpenedAppControl != null)
289 r = __pOpenedAppControl->Start(null, null, &extraData, pListener);
291 extraData.RemoveAll(true);
295 //AppControl request failed, delete AppControl.
296 delete __pOpenedAppControl;
297 __pOpenedAppControl = null;
302 //AppControl request was successful.