2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
9 // http://www.apache.org/licenses/LICENSE-2.0
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.
19 * @file ContactAppControlDllEntry.cpp
20 * @brief This is the implementation for the ContactAppControlDllEntry.cpp class.
23 #include <unique_ptr.h>
24 #include <appsvc/appsvc.h>
27 #include <FBaseSysLog.h>
28 #include <FBaseInteger.h>
29 #include <FBaseUtilStringUtil.h>
30 #include <FAppAppControl.h>
31 #include <FBaseColHashMap.h>
32 #include <FBaseColAllElementsDeleter.h>
34 #include <FBase_StringConverter.h>
35 #include <FIo_FileImpl.h>
36 #include <FSys_EnvironmentImpl.h>
37 #include <FApp_AppControlManager.h>
38 #include <FApp_AppMessageImpl.h>
41 using namespace Tizen::App;
42 using namespace Tizen::Base;
43 using namespace Tizen::Base::Utility;
44 using namespace Tizen::Base::Collection;
45 using namespace Tizen::Io;
46 using namespace Tizen::System;
47 using namespace Tizen::Social;
53 static char PICK_OP_SEL_MODE_KEY[] = "selectionMode";
54 static char PICK_OP_RET_KEY_RET_TYPE[] = "returnType";
55 static char PICK_OP_RET_KEY_VALUE[] = "value";
57 static char EDIT_OP_KEY_CONTACT_ID[] = "contactId";
58 static char EDIT_OP_KEY_PHONE[] = "phone";
59 static char EDIT_OP_KEY_EMAIL[] = "email";
60 static char EDIT_OP_KEY_URL[] = "url";
62 static char VIEW_OP_KEY_VIEW_TYPE[] = "viewType";
63 static char VIEW_OP_KEY_VCARD_PATH[] = "path";
64 static char VIEW_OP_KEY_CONTACT_ID[] = "contactId";
66 static char VIEW_OP_VALUE_CONTACT[] = "contact";
67 static char VIEW_OP_VALUE_VCARD[] = "vcf";
68 static int VIEW_OP_VALUE_LENGTH_MAX = 7;
70 static char PICK_OP_SEL_MODE_VALUE_SINGLE[] = "single";
71 static char PICK_OP_SEL_MODE_VALUE_MULTIPLE[] = "multiple";
73 static char PICK_OP_RET_VALUE_PHONE[] = "phone";
74 static char PICK_OP_RET_VALUE_EMAIL[] = "email";
75 static char PICK_OP_RET_VALUE_VCARD[] = "vcard";
76 static char PICK_OP_RET_VALUE_CONTACT_ID[] = "contactId";
78 static int PICK_OP_SEL_MODE_VALUE_LENGTH_MAX = 8;
79 static int PICK_OP_RET_VALUE_LENGTH_MAX = 10;
81 static char ADD_OP_KEY_NUMBER[] = "phone";
82 static char ADD_OP_KEY_EMAIL[] = "email";
83 static char ADD_OP_KEY_URL[] = "url";
86 static char CORE_OP_KEY_TYPE[] = "type";
87 static char CORE_OP_KEY_PERSON_ID[] = "ct_person_id";
88 static char CORE_OP_KEY_NUMBER[] = "ct_num";
89 static char CORE_OP_KEY_EMAIL[] = "ct_email";
90 static char CORE_OP_KEY_URL[] = "ct_web";
91 static char CORE_OP_KEY_VCARD[] = "ct_vcard";
93 static char CORE_OP_VALUE_EDIT_PERSON[] = "11";
94 static char CORE_OP_VALUE_EDIT_PERSON_BY_SEL[] = "20";
96 static char CORE_OP_VALUE_VIEW_PERSON[] = "0";
99 static char CORE_OP_VALUE_PICK_PERSON_ID[] = "11";
100 static char CORE_OP_VALUE_PICK_NUMBER[] = "12";
101 static char CORE_OP_VALUE_PICK_EMAIL[] = "13";
102 static char CORE_OP_VALUE_PICK_VCARD[] = "14";
103 static char CORE_OP_VALUE_PICK_PERSON_ID_LIST[] = "31";
104 static char CORE_OP_VALUE_PICK_NUMBER_LIST[] = "32";
105 static char CORE_OP_VALUE_PICK_EMAIL_LIST[] = "33";
107 static char CORE_OP_VALUE_ADD_CONTACT[] = "21";
109 static char CORE_RESULT_TYPE_KEY_NUMBER[] = "num_id";
110 static char CORE_RESULT_TYPE_KEY_NUMBER_LIST[] = "num_id_list";
111 static char CORE_RESULT_TYPE_KEY_EMAIL[] = "email_id";
112 static char CORE_RESULT_TYPE_KEY_EMAIL_LIST[] = "email_id_list";
113 static char CORE_RESULT_TYPE_KEY_PERSON[] = "person_id";
114 static char CORE_RESULT_TYPE_KEY_PERSON_LIST[] = "person_id_list";
115 static char CORE_RESULT_TYPE_KEY_VCARD[] = "vcard";
117 result _OSP_EXPORT_ StartAppControl(int req, const String&, const String&, const String*, const String*, const IMap*);
118 result _OSP_EXPORT_ TerminateAppControl(int req);
119 void OnAppControlResult(void*, int, service_result_e, void*);
121 static int __req = -1;
122 static int __processId = -1;
124 static const wchar_t __allowedAppControlPickTable[][2][64] =
126 {L"osp.appcontrol.CONTACT", L"osp.appcontrol.operation.PICK"},
127 {L"osp.appcontrol.provider.contact", L"osp.appcontrol.operation.pick"},
128 {L"http://tizen.org/appcontrol/provider/contact", L"http://tizen.org/appcontrol/operation/pick"},
129 {L"tizen.contacts", L"http://tizen.org/appcontrol/operation/pick"},
132 static const wchar_t __allowedAppControlAddTable[][2][64] =
134 {L"osp.appcontrol.CONTACT", L"osp.appcontrol.operation.ADD"},
135 {L"osp.appcontrol.provider.contact", L"osp.appcontrol.operation.add"},
136 {L"http://tizen.org/appcontrol/provider/contact", L"http://tizen.org/appcontrol/operation/add"},
137 {L"tizen.contacts", L"http://tizen.org/appcontrol/operation/add"},
140 static const wchar_t __allowedAppControlEditTable[][2][64] =
142 {L"osp.appcontrol.CONTACT", L"osp.appcontrol.operation.EDIT"},
143 {L"osp.appcontrol.provider.contact", L"osp.appcontrol.operation.edit"},
144 {L"http://tizen.org/appcontrol/provider/contact", L"http://tizen.org/appcontrol/operation/edit"},
145 {L"tizen.contacts", L"http://tizen.org/appcontrol/operation/edit"},
148 static const wchar_t __allowedAppControlViewTable[][2][64] =
150 {L"osp.appcontrol.CONTACT", L"osp.appcontrol.operation.VIEW"},
151 {L"osp.appcontrol.provider.contact", L"osp.appcontrol.operation.view"},
152 {L"http://tizen.org/appcontrol/provider/contact", L"http://tizen.org/appcontrol/operation/view"},
153 {L"tizen.contacts", L"http://tizen.org/appcontrol/operation/view"},
156 class ScopedConnection
159 ScopedConnection(void)
162 int ret = contacts_connect2();
163 if (ret == CONTACTS_ERROR_NONE)
169 ~ScopedConnection(void)
173 contacts_disconnect2();
177 bool IsConnected(void) const
190 ScopedHandle(contacts_record_h handle)
197 if (__handle != null)
199 contacts_record_destroy(__handle, true);
203 contacts_record_h Get(void)
208 contacts_record_h Release(void)
210 contacts_record_h handle = __handle;
217 contacts_record_h __handle;
223 ScopedList(contacts_list_h handle)
230 if (__handle != null)
232 contacts_list_destroy(__handle, true);
236 contacts_list_h Get(void)
242 contacts_list_h __handle;
248 ScopedFilter(contacts_filter_h filter)
255 if (__filter != null)
257 contacts_filter_destroy(__filter);
261 contacts_filter_h Get(void)
267 contacts_filter_h __filter;
273 ScopedQuery(contacts_query_h query)
282 contacts_query_destroy(__query);
286 contacts_query_h Get(void)
292 contacts_query_h __query;
295 StartAppControlForPick(const String* pUri, const String* pMime, const IMap* pMap)
300 const char* pBuf = appsvc_get_data(msg.GetBundle(), PICK_OP_SEL_MODE_KEY);
303 SysLog(NID_APP, "selectionMode has not been set");
304 return E_INVALID_ARG;
307 if (strncmp(pBuf, PICK_OP_SEL_MODE_VALUE_SINGLE, PICK_OP_SEL_MODE_VALUE_LENGTH_MAX) == 0)
309 pBuf = appsvc_get_data(msg.GetBundle(), PICK_OP_RET_KEY_RET_TYPE);
312 SysLog(NID_APP, "returnType has not been set");
313 return E_INVALID_ARG;
316 if (strncmp(pBuf, PICK_OP_RET_VALUE_PHONE, PICK_OP_RET_VALUE_LENGTH_MAX) == 0)
318 msg.AddData(CORE_OP_KEY_TYPE, CORE_OP_VALUE_PICK_NUMBER);
320 else if (strncmp(pBuf, PICK_OP_RET_VALUE_EMAIL, PICK_OP_RET_VALUE_LENGTH_MAX) == 0)
322 msg.AddData(CORE_OP_KEY_TYPE, CORE_OP_VALUE_PICK_EMAIL);
324 else if (strncmp(pBuf, PICK_OP_RET_VALUE_VCARD, PICK_OP_RET_VALUE_LENGTH_MAX) == 0)
326 msg.AddData(CORE_OP_KEY_TYPE, CORE_OP_VALUE_PICK_VCARD);
328 else if (strncmp(pBuf, PICK_OP_RET_VALUE_CONTACT_ID, PICK_OP_RET_VALUE_LENGTH_MAX) == 0)
330 msg.AddData(CORE_OP_KEY_TYPE, CORE_OP_VALUE_PICK_PERSON_ID);
334 SysLog(NID_APP, "returnType must be phone, email, contactId, or vcard.");
335 return E_INVALID_ARG;
338 else if (strncmp(pBuf, PICK_OP_SEL_MODE_VALUE_MULTIPLE, PICK_OP_SEL_MODE_VALUE_LENGTH_MAX) == 0)
340 pBuf = appsvc_get_data(msg.GetBundle(), PICK_OP_RET_KEY_RET_TYPE);
343 SysLog(NID_APP, "returnType has not been set");
344 return E_INVALID_ARG;
347 if (strncmp(pBuf, PICK_OP_RET_VALUE_PHONE, PICK_OP_RET_VALUE_LENGTH_MAX) == 0)
349 msg.AddData(CORE_OP_KEY_TYPE, CORE_OP_VALUE_PICK_NUMBER_LIST);
351 else if (strncmp(pBuf, PICK_OP_RET_VALUE_EMAIL, PICK_OP_RET_VALUE_LENGTH_MAX) == 0)
353 msg.AddData(CORE_OP_KEY_TYPE, CORE_OP_VALUE_PICK_EMAIL_LIST);
355 else if (strncmp(pBuf, PICK_OP_RET_VALUE_CONTACT_ID, PICK_OP_RET_VALUE_LENGTH_MAX) == 0)
357 msg.AddData(CORE_OP_KEY_TYPE, CORE_OP_VALUE_PICK_PERSON_ID_LIST);
361 SysLog(NID_APP, "returnType must be phone, email, or contactId.");
362 return E_INVALID_ARG;
367 SysLog(NID_APP, "selectionMode must be either single or multiple.");
368 return E_INVALID_ARG;
371 __processId = _AppControlManager::GetInstance()->Launch(msg, "contacts-list-efl", NULL, NULL, NULL, OnAppControlResult, 0);
373 SysTryReturnResult(NID_APP, __processId >= 0, E_SYSTEM, "StartAppControl: Launching Contacts List AppControl is failed.");
379 StartAppControlForAdd(const String* pUri, const String* pMime, const IMap* pMap)
384 msg.AddData(CORE_OP_KEY_TYPE, CORE_OP_VALUE_ADD_CONTACT);
386 const char* pBuf = appsvc_get_data(msg.GetBundle(), ADD_OP_KEY_NUMBER);
389 msg.AddData(CORE_OP_KEY_NUMBER, String(pBuf));
392 pBuf = appsvc_get_data(msg.GetBundle(), ADD_OP_KEY_EMAIL);
395 msg.AddData(CORE_OP_KEY_EMAIL, String(pBuf));
398 pBuf = appsvc_get_data(msg.GetBundle(), ADD_OP_KEY_URL);
401 msg.AddData(CORE_OP_KEY_URL, String(pBuf));
404 __processId = _AppControlManager::GetInstance()->Launch(msg, "contacts-details-efl", NULL, NULL, NULL, NULL, 0);
406 SysTryReturnResult(NID_APP, __processId >= 0, E_SYSTEM, "StartAppControl: Launching Contacts Details AppControl is failed.");
412 StartAppControlForEdit(const String* pUri, const String* pMime, const IMap* pMap)
417 const char* pBuf = appsvc_get_data(msg.GetBundle(), EDIT_OP_KEY_CONTACT_ID);
420 int contactId = atoi(pBuf);
423 ScopedConnection conn;
424 if (conn.IsConnected())
426 contacts_record_h contactHandle = null;
427 int ret = contacts_db_get_record(_contacts_simple_contact._uri, contactId, &contactHandle);
428 if (ret == CONTACTS_ERROR_NONE)
430 contacts_record_get_int(contactHandle, _contacts_simple_contact.person_id, &personId);
431 contacts_record_destroy(contactHandle, true);
434 SysLog(NID_APP, "contact ID(%s) -> person ID(%d).", pBuf, personId);
437 msg.AddData(CORE_OP_KEY_TYPE, CORE_OP_VALUE_EDIT_PERSON);
438 msg.AddData(CORE_OP_KEY_PERSON_ID, Integer::ToString(personId));
440 pBuf = appsvc_get_data(msg.GetBundle(), EDIT_OP_KEY_PHONE);
443 msg.AddData(CORE_OP_KEY_NUMBER, String(pBuf));
446 pBuf = appsvc_get_data(msg.GetBundle(), EDIT_OP_KEY_EMAIL);
449 msg.AddData(CORE_OP_KEY_EMAIL, String(pBuf));
452 pBuf = appsvc_get_data(msg.GetBundle(), EDIT_OP_KEY_URL);
455 msg.AddData(CORE_OP_KEY_URL, String(pBuf));
458 __processId = _AppControlManager::GetInstance()->Launch(msg, "contacts-details-efl", NULL, NULL, NULL, NULL, 0);
460 SysTryReturnResult(NID_APP, __processId >= 0, E_SYSTEM, "StartAppControl: Launching Contacts Details AppControl is failed.");
464 msg.AddData(CORE_OP_KEY_TYPE, CORE_OP_VALUE_EDIT_PERSON_BY_SEL);
466 pBuf = appsvc_get_data(msg.GetBundle(), EDIT_OP_KEY_PHONE);
469 msg.AddData(CORE_OP_KEY_NUMBER, String(pBuf));
472 pBuf = appsvc_get_data(msg.GetBundle(), EDIT_OP_KEY_EMAIL);
475 msg.AddData(CORE_OP_KEY_EMAIL, String(pBuf));
478 pBuf = appsvc_get_data(msg.GetBundle(), EDIT_OP_KEY_URL);
481 msg.AddData(CORE_OP_KEY_URL, String(pBuf));
484 __processId = _AppControlManager::GetInstance()->Launch(msg, "contacts-list-efl", NULL, NULL, NULL, NULL, 0);
486 SysTryReturnResult(NID_APP, __processId >= 0, E_SYSTEM, "StartAppControl: Launching Contacts List AppControl is failed.");
493 StartAppControlForView( const String* pUri, const String* pMime, const IMap* pMap)
499 msg.AddData(CORE_OP_KEY_TYPE, CORE_OP_VALUE_VIEW_PERSON);
501 const char* pBuf = appsvc_get_data(msg.GetBundle(), VIEW_OP_KEY_VIEW_TYPE);
504 SysLog(NID_APP, "viewType has not been set");
508 if (strncmp(pBuf, VIEW_OP_VALUE_CONTACT, VIEW_OP_VALUE_LENGTH_MAX) == 0)
513 ScopedConnection conn;
515 pBuf = appsvc_get_data(msg.GetBundle(), VIEW_OP_KEY_CONTACT_ID);
518 contactId = atoi(pBuf);
520 if (conn.IsConnected())
522 contacts_record_h contactHandle = null;
523 int ret = contacts_db_get_record(_contacts_simple_contact._uri, contactId, &contactHandle);
524 if (ret == CONTACTS_ERROR_NONE)
526 contacts_record_get_int(contactHandle, _contacts_simple_contact.person_id, &personId);
527 contacts_record_destroy(contactHandle, true);
534 SysLog(NID_APP, "The value for contactId is not set.");
538 msg.AddData(CORE_OP_KEY_PERSON_ID, Integer::ToString(personId));
540 else if (strncmp(pBuf, VIEW_OP_VALUE_VCARD, VIEW_OP_VALUE_LENGTH_MAX) == 0)
542 pBuf = appsvc_get_data(msg.GetBundle(), VIEW_OP_KEY_VCARD_PATH);
545 msg.AddData(CORE_OP_KEY_VCARD, pBuf);
549 SysLog(NID_APP, "The value for path is not set.");
556 SysLog(NID_APP, "viewType must be either vcf or contact.");
560 __processId = _AppControlManager::GetInstance()->Launch(msg, "contacts-details-efl", NULL, NULL, NULL, NULL, 0);
562 SysTryReturnResult(NID_APP, __processId >= 0, E_SYSTEM, "StartAppControl: Launching Contacts Details AppControl is failed.");
568 StartAppControl(int req, const String& aId, const String& oId, const String* pUri, const String* pMime, const IMap* pMap)
570 SysLog(NID_APP, "StartAppControl: Entry to Contact AppControl");
572 result r = E_SUCCESS;
574 const bool isContactPick = _AppControlManager::IsAllowedAppControl(__allowedAppControlPickTable, 4, aId, oId);
575 const bool isContactAdd = _AppControlManager::IsAllowedAppControl(__allowedAppControlAddTable, 4, aId, oId);
576 const bool isContactEdit = _AppControlManager::IsAllowedAppControl(__allowedAppControlEditTable, 4, aId, oId);
577 const bool isContactView = _AppControlManager::IsAllowedAppControl(__allowedAppControlViewTable, 4, aId, oId);
579 SysTryReturnResult(NID_APP, isContactPick || isContactAdd || isContactEdit || isContactView, E_SYSTEM, "Invalid AppControl entry for (%ls, %ls).", aId.GetPointer(), oId.GetPointer());
581 SysLog(NID_APP, "Contact AppControl : %ls operation.", oId.GetPointer());
585 SysLog(NID_APP, "Contact AppControl : PICK operation.");
589 r = StartAppControlForPick(pUri, pMime, pMap);
590 if (r == E_INVALID_ARG)
592 SysLog(NID_APP, "Finish pick operation.");
593 _AppControlManager::GetInstance()->FinishAppControl(__req, APP_CTRL_RESULT_FAILED, null);
599 SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] System error.", GetErrorMessage(r));
601 SysLog(NID_APP, "StartAppControl: Launching Contact AppControl succeeded");
603 else if (isContactAdd)
605 SysLog(NID_APP, "Contact AppControl : ADD operation.");
607 r = StartAppControlForAdd(pUri, pMime, pMap);
608 SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] System error.", GetErrorMessage(r));
610 SysLog(NID_APP, "StartAppControl: Launching Contact AppControl succeeded");
612 else if (isContactEdit)
614 SysLog(NID_APP, "Contact AppControl : EDIT operation.");
616 r = StartAppControlForEdit(pUri, pMime, pMap);
617 SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] System error.", GetErrorMessage(r));
619 SysLog(NID_APP, "StartAppControl: Launching Contact AppControl succeeded");
621 else if (isContactView)
623 SysLog(NID_APP, "Contact AppControl : VIEW operation.");
625 r = StartAppControlForView(pUri, pMime, pMap);
626 SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] System error.", GetErrorMessage(r));
628 SysLog(NID_APP, "StartAppControl: Launching Contact AppControl succeeded");
639 TerminateAppControl(int req)
641 if (__processId >= 0)
643 _Aul::TerminateApplicationByPid(__processId);
649 OnAppControlResultForPickNumber(const char* pRawData, HashMap* pResult)
651 ScopedConnection conn;
652 if (!conn.IsConnected())
657 int numberId = atoi(pRawData);
658 char* pPhoneNumber = null;
660 contacts_record_h recordHandle = null;
662 int ret = contacts_db_get_record(_contacts_number._uri, numberId, &recordHandle);
663 if (ret == CONTACTS_ERROR_NONE)
665 ScopedHandle numberHandle(recordHandle);
666 contacts_record_get_str_p(numberHandle.Get(), _contacts_number.number, &pPhoneNumber);
668 pResult->Add(new (std::nothrow) String(PICK_OP_RET_KEY_RET_TYPE), new (std::nothrow) String(PICK_OP_RET_VALUE_PHONE));
669 pResult->Add(new (std::nothrow) String(PICK_OP_RET_KEY_VALUE), new (std::nothrow) String(pPhoneNumber));
674 OnAppControlResultForPickNumberList(const char* pRawData, HashMap* pResult)
676 ScopedConnection conn;
677 if (!conn.IsConnected())
685 String encodedString(pRawData);
686 std::unique_ptr<ByteBuffer> pDecodeByteBuffer(StringUtil::DecodeBase64StringN(encodedString));
688 while (pDecodeByteBuffer->GetInt(id) == E_SUCCESS)
690 char* pNumber = null;
691 contacts_record_h recordHandle = null;
692 int ret = contacts_db_get_record(_contacts_number._uri, id, &recordHandle);
693 if (ret != CONTACTS_ERROR_NONE)
698 ScopedHandle numberHandle(recordHandle);
700 contacts_record_get_str_p(numberHandle.Get(), _contacts_number.number, &pNumber);
704 numbers.Append(L";");
711 numbers.Append(pNumber);
714 pResult->Add(new (std::nothrow) String(PICK_OP_RET_KEY_RET_TYPE), new (std::nothrow) String(L"phone"));
715 pResult->Add(new (std::nothrow) String(PICK_OP_RET_KEY_VALUE), new (std::nothrow) String(numbers));
720 OnAppControlResultForPickEmail(const char* pRawData, HashMap* pResult)
722 ScopedConnection conn;
723 if (!conn.IsConnected())
729 int emailId = atoi(pRawData);
730 contacts_record_h recordHandle = null;
732 int ret = contacts_db_get_record(_contacts_email._uri, emailId, &recordHandle);
733 if (ret != CONTACTS_ERROR_NONE)
738 ScopedHandle emailHandle(recordHandle);
740 contacts_record_get_str_p(emailHandle.Get(), _contacts_email.email, &pEmail);
742 pResult->Add(new (std::nothrow) String(PICK_OP_RET_KEY_RET_TYPE), new (std::nothrow) String(PICK_OP_RET_VALUE_EMAIL));
743 pResult->Add(new (std::nothrow) String(PICK_OP_RET_KEY_VALUE), new (std::nothrow) String(pEmail));
747 OnAppControlResultForPickEmailList(const char* pRawData, HashMap* pResult)
749 ScopedConnection conn;
750 if (!conn.IsConnected())
758 String encodedString(pRawData);
759 std::unique_ptr<ByteBuffer> pDecodeByteBuffer(StringUtil::DecodeBase64StringN(encodedString));
761 while (pDecodeByteBuffer->GetInt(id) == E_SUCCESS)
764 contacts_record_h recordHandle = null;
765 int ret = contacts_db_get_record(_contacts_email._uri, id, &recordHandle);
766 if (ret != CONTACTS_ERROR_NONE)
771 ScopedHandle emailHandle(recordHandle);
772 contacts_record_get_str_p(emailHandle.Get(), _contacts_email.email, &pEmail);
776 emailIds.Append(L";");
783 emailIds.Append(pEmail);
786 pResult->Add(new (std::nothrow) String(PICK_OP_RET_KEY_RET_TYPE), new (std::nothrow) String(L"email"));
787 pResult->Add(new (std::nothrow) String(PICK_OP_RET_KEY_VALUE), new (std::nothrow) String(emailIds));
791 OnAppControlResultForPickContact(const char* pRawData, HashMap* pResult)
793 ScopedConnection conn;
794 if (!conn.IsConnected())
799 int personId = atoi(pRawData);
802 unsigned int simple_contact_projection[] = {
803 _contacts_simple_contact.id,
804 _contacts_simple_contact.address_book_id,
807 contacts_filter_h filterHandle = null;
808 int ret = contacts_filter_create(_contacts_simple_contact._uri, &filterHandle);
809 if (ret != CONTACTS_ERROR_NONE)
814 ScopedFilter filter(filterHandle);
815 contacts_filter_add_int(filter.Get(), _contacts_simple_contact.person_id, CONTACTS_MATCH_EQUAL, personId);
817 contacts_query_h queryHandle = null;
818 ret = contacts_query_create(_contacts_simple_contact._uri, &queryHandle);
819 if (ret != CONTACTS_ERROR_NONE)
824 ScopedQuery query(queryHandle);
825 ret = contacts_query_set_filter(query.Get(), filter.Get());
826 if (ret != CONTACTS_ERROR_NONE)
831 ret = contacts_query_set_projection(query.Get(), simple_contact_projection, sizeof(simple_contact_projection)/sizeof(unsigned int));
832 if (ret != CONTACTS_ERROR_NONE)
837 ret = contacts_query_set_sort(query.Get(), _contacts_simple_contact.address_book_id, true);
838 if (ret != CONTACTS_ERROR_NONE)
844 contacts_list_h listHandle = null;
845 ret = contacts_db_get_records_with_query(query.Get(), 0, 0, &listHandle);
846 if (ret != CONTACTS_ERROR_NONE)
851 ScopedList contactList(listHandle);
853 unsigned int count = 0;
854 contacts_list_get_count(contactList.Get(), &count);
860 contacts_record_h contactHandle = null;
861 contacts_list_get_current_record_p(contactList.Get(), &contactHandle);
862 contacts_record_get_int(contactHandle, _contacts_simple_contact.id, &contactId);
864 pResult->Add(new (std::nothrow) String(PICK_OP_RET_KEY_RET_TYPE), new (std::nothrow) String(PICK_OP_RET_VALUE_CONTACT_ID));
865 pResult->Add(new (std::nothrow) String(PICK_OP_RET_KEY_VALUE), new (std::nothrow) String(Integer::ToString(contactId)));
869 OnAppControlResultForPickContactList(const char* pRawData, HashMap* pResult)
871 ScopedConnection conn;
872 if (!conn.IsConnected())
881 String encodedString(pRawData);
882 std::unique_ptr<ByteBuffer> pDecodeByteBuffer(StringUtil::DecodeBase64StringN(encodedString));
884 while (pDecodeByteBuffer->GetInt(id) == E_SUCCESS)
886 unsigned int simple_contact_projection[] = {
887 _contacts_simple_contact.id,
888 _contacts_simple_contact.address_book_id,
891 contacts_record_h contactHandle = null;
893 contacts_filter_h filterHandle = null;
894 int ret = contacts_filter_create(_contacts_simple_contact._uri, &filterHandle);
895 if (ret != CONTACTS_ERROR_NONE)
900 ScopedFilter filter(filterHandle);
903 contacts_filter_add_int(filter.Get(), _contacts_simple_contact.person_id, CONTACTS_MATCH_EQUAL, id);
905 contacts_query_h queryHandle = null;
906 ret = contacts_query_create(_contacts_simple_contact._uri, &queryHandle);
907 if (ret != CONTACTS_ERROR_NONE)
912 ScopedQuery query(queryHandle);
914 ret = contacts_query_set_filter(query.Get(), filter.Get());
915 if (ret != CONTACTS_ERROR_NONE)
920 ret = contacts_query_set_projection(query.Get(), simple_contact_projection, sizeof(simple_contact_projection)/sizeof(unsigned int));
921 if (ret != CONTACTS_ERROR_NONE)
926 ret = contacts_query_set_sort(query.Get(), _contacts_simple_contact.address_book_id, true);
927 if (ret != CONTACTS_ERROR_NONE)
933 contacts_list_h listHandle = null;
934 ret = contacts_db_get_records_with_query(query.Get(), 0, 0, &listHandle);
935 if (ret != CONTACTS_ERROR_NONE)
940 ScopedList contactList(listHandle);
941 unsigned int count = 0;
942 contacts_list_get_count(contactList.Get(), &count);
945 contacts_list_get_current_record_p(contactList.Get(), &contactHandle);
946 contacts_record_get_int(contactHandle, _contacts_simple_contact.id, &contactId);
949 personIds.Append(L";");
956 personIds.Append(id);
961 pResult->Add(new (std::nothrow) String(PICK_OP_RET_KEY_RET_TYPE), new (std::nothrow) String(PICK_OP_RET_VALUE_CONTACT_ID));
962 pResult->Add(new (std::nothrow) String(PICK_OP_RET_KEY_VALUE), new (std::nothrow) String(personIds));
964 contacts_disconnect2();
969 OnAppControlResultForPickVcard(const char* pRawData, HashMap* pResult)
971 pResult->Add(new (std::nothrow) String(PICK_OP_RET_KEY_RET_TYPE), new (std::nothrow) String(PICK_OP_RET_VALUE_VCARD));
972 pResult->Add(new (std::nothrow) String(PICK_OP_RET_KEY_VALUE), new (std::nothrow) String(pRawData));
976 OnAppControlResult(void* b, int requestCode, service_result_e res, void* userData)
979 bundle* pBundle = static_cast<bundle*>(b);
980 AppCtrlResult appControlResult = APP_CTRL_RESULT_SUCCEEDED;
981 std::unique_ptr<HashMap, AllElementsDeleter> pResult(null);
985 case SERVICE_RESULT_SUCCEEDED:
987 pResult.reset(new (std::nothrow) HashMap());
988 SysTryCatch(NID_APP, pResult != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
990 r = pResult->Construct();
991 SysTryCatch(NID_APP, !IsFailed(r), , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
993 const char* pBuf = appsvc_get_data(pBundle, CORE_RESULT_TYPE_KEY_NUMBER);
996 OnAppControlResultForPickNumber(pBuf, pResult.get());
1000 pBuf = appsvc_get_data(pBundle, CORE_RESULT_TYPE_KEY_EMAIL);
1003 OnAppControlResultForPickEmail(pBuf, pResult.get());
1007 pBuf = appsvc_get_data(pBundle, CORE_RESULT_TYPE_KEY_PERSON);
1010 OnAppControlResultForPickContact(pBuf, pResult.get());
1014 pBuf = appsvc_get_data(pBundle, CORE_RESULT_TYPE_KEY_VCARD);
1017 OnAppControlResultForPickVcard(pBuf, pResult.get());
1021 pBuf = appsvc_get_data(pBundle, CORE_RESULT_TYPE_KEY_NUMBER_LIST);
1024 OnAppControlResultForPickNumberList(pBuf, pResult.get());
1028 pBuf = appsvc_get_data(pBundle, CORE_RESULT_TYPE_KEY_EMAIL_LIST);
1031 OnAppControlResultForPickEmailList(pBuf, pResult.get());
1035 pBuf = appsvc_get_data(pBundle, CORE_RESULT_TYPE_KEY_PERSON_LIST);
1038 OnAppControlResultForPickContactList(pBuf, pResult.get());
1044 case SERVICE_RESULT_FAILED:
1045 case SERVICE_RESULT_CANCELED:
1047 appControlResult = APP_CTRL_RESULT_FAILED;
1051 _AppControlManager::GetInstance()->FinishAppControl(__req, appControlResult, pResult.release());