+//
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Flora License, Version 1.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://floralicense.org/license/
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an AS IS BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+/**
+ * @file CallAppControlRequestMgr.cpp
+ * @brief Manages AppControl Request to other apps.
+ */
+#include <FApp.h>
+#include "CallAppControlRequestMgr.h"
+#include "CallTypes.h"
+
+using namespace Tizen::App;
+using namespace Tizen::Base;
+using namespace Tizen::Base::Collection;
+
+CallAppControlRequestMgr* CallAppControlRequestMgr::__pInstance = null;
+
+CallAppControlRequestMgr::CallAppControlRequestMgr(void)
+{
+ __pOpenedAppControl = null;
+}
+
+CallAppControlRequestMgr::~CallAppControlRequestMgr(void)
+{
+ if (__pOpenedAppControl != null)
+ {
+ delete __pOpenedAppControl;
+ __pOpenedAppControl = null;
+ }
+}
+
+void
+CallAppControlRequestMgr::CreateInstance(void)
+{
+ __pInstance = new (std::nothrow) CallAppControlRequestMgr();
+ result r = __pInstance->Construct();
+ if(IsFailed(r))
+ {
+ delete __pInstance;
+ __pInstance = null;
+ return;
+ }
+
+ std::atexit(DestroyInstance);
+}
+
+CallAppControlRequestMgr*
+CallAppControlRequestMgr::GetInstance(void)
+{
+ if (__pInstance == null)
+ {
+ CreateInstance();
+ }
+ return __pInstance;
+}
+
+void
+CallAppControlRequestMgr::DestroyInstance(void)
+{
+ if (__pInstance != null)
+ {
+ delete __pInstance;
+ __pInstance = null;
+ }
+}
+
+result
+CallAppControlRequestMgr::Construct(void)
+{
+ return E_SUCCESS;
+}
+
+bool
+CallAppControlRequestMgr::IsAppControlRunning(void)
+{
+ AppLog("ENTER");
+ return (__pOpenedAppControl != null);
+}
+
+void
+CallAppControlRequestMgr::AbortAppControlRequest(void)
+{
+ AppLog("ENTER");
+ if (__pOpenedAppControl != null)
+ {
+ result r = __pOpenedAppControl->Stop();
+ AppLog("Abort failed with r=%d", r);
+ delete __pOpenedAppControl;
+ __pOpenedAppControl = null;
+ }
+ AppLog("ENTER");
+}
+
+void
+CallAppControlRequestMgr::AppControlRequestCompleted(void)
+{
+ AppLog("ENTER");
+ if (__pOpenedAppControl != null)
+ {
+ delete __pOpenedAppControl;
+ __pOpenedAppControl = null;
+ }
+}
+
+bool
+CallAppControlRequestMgr::LaunchComposeMessageAppControl(String& contactNumber, IAppControlResponseListener* pListener)
+{
+ if (__pOpenedAppControl != null)
+ {
+ //An AppControl is already running.
+ String provider = __pOpenedAppControl->GetAppControlProviderId();
+ String operation = __pOpenedAppControl->GetOperationId();
+ AppLog( "Error:- AppControl is already running for provider id = %ls, operation id = %ls",
+ provider.GetPointer(), operation.GetPointer());
+ return false;
+ }
+
+ result r = E_FAILURE;
+ //request parameters
+ HashMap extraData;
+ extraData.Construct();
+ extraData.Add(new (std::nothrow) String(MESSAGE_TYPE), new (std::nothrow) String(MESSAGE_SMS_TYPE));
+ extraData.Add(new (std::nothrow) String(MESSAGE_TO), new (std::nothrow) String(contactNumber));
+
+ __pOpenedAppControl = AppManager::FindAppControlN(PROVIDER_ID_MESSAGE, OPERATION_ID_COMPOSE);
+ if (__pOpenedAppControl != null)
+ {
+ r = __pOpenedAppControl->Start(null, null, &extraData, pListener);
+ }
+ extraData.RemoveAll(true);
+
+ if(r != E_SUCCESS)
+ {
+ //AppControl request failed, delete AppControl.
+ delete __pOpenedAppControl;
+ __pOpenedAppControl = null;
+ return false;
+ }
+ else
+ {
+ //AppControl request was successful.
+ return true;
+ }
+}
+
+bool
+CallAppControlRequestMgr::LaunchViewContactAppControl(String& contactId, IAppControlResponseListener* pListener)
+{
+ AppLogDebug("ENTER");
+ if (__pOpenedAppControl != null)
+ {
+ //An AppControl is already running.
+ String provider = __pOpenedAppControl->GetAppControlProviderId();
+ String operation = __pOpenedAppControl->GetOperationId();
+ AppLog( "Error:- AppControl is already running for provider id = %ls, operation id = %ls",
+ provider.GetPointer(), operation.GetPointer());
+ return false;
+ }
+
+ result r = E_FAILURE;
+ //request parameters
+ HashMap extraData;
+ extraData.Construct();
+ extraData.Add(new (std::nothrow) String(CONTACTS_VIEW_TYPE), new (std::nothrow) String(CONTACTS_VIEW_TYPE_CONTACT));
+ extraData.Add(new (std::nothrow) String(CONTACTS_VIEW_TYPE_CONTACT), new (std::nothrow) String(CONTACTS_VIEW_TYPE_CONTACT));
+ extraData.Add(new (std::nothrow) String(CONTACT_KEY_ITEM_ID), new (std::nothrow) String(contactId));
+ extraData.Add(new (std::nothrow) String(CONTACTS_ID_KEY), new (std::nothrow) String(contactId));
+ extraData.Add(new (std::nothrow) String(CONTACT_KEY_ITEM_TYPE), new (std::nothrow) String(ITEM_TYPE_PERSON));
+
+ __pOpenedAppControl = AppManager::FindAppControlN(PROVIDER_ID_CONTACTS, OPERATION_ID_VIEW);
+ if (__pOpenedAppControl != null)
+ {
+ r = __pOpenedAppControl->Start(null, null, &extraData, pListener);
+ }
+ extraData.RemoveAll(true);
+
+ if(r != E_SUCCESS)
+ {
+ //AppControl request failed, delete AppControl.
+ delete __pOpenedAppControl;
+ __pOpenedAppControl = null;
+ return false;
+ }
+ else
+ {
+ //AppControl request was successful.
+ return true;
+ }
+}
+
+bool
+CallAppControlRequestMgr::LaunchAddContactAppControl(String& contactNumber, IAppControlResponseListener* pListener)
+{
+ AppLogDebug("ENTER");
+ if (__pOpenedAppControl != null)
+ {
+ //An AppControl is already running.
+ String provider = __pOpenedAppControl->GetAppControlProviderId();
+ String operation = __pOpenedAppControl->GetOperationId();
+ AppLog( "Error:- AppControl is already running for provider id = %ls, operation id = %ls",
+ provider.GetPointer(), operation.GetPointer());
+ return false;
+ }
+
+ result r = E_FAILURE;
+ //request parameters
+ HashMap extraData;
+ extraData.Construct();
+ extraData.Add(new (std::nothrow) String(INPUT_TYPE_PHONE), new (std::nothrow) String(contactNumber));
+ extraData.Add(new (std::nothrow) String(CONTACT_KEY_ITEM_TYPE), new (std::nothrow) String(ITEM_TYPE_CONTACT));
+
+ __pOpenedAppControl = AppManager::FindAppControlN(PROVIDER_ID_CONTACTS, OPERATION_ID_ADD);
+ if (__pOpenedAppControl != null)
+ {
+ r = __pOpenedAppControl->Start(null, null, &extraData, pListener);
+ }
+ extraData.RemoveAll(true);
+
+ if(r != E_SUCCESS)
+ {
+ //AppControl request failed, delete AppControl.
+ delete __pOpenedAppControl;
+ __pOpenedAppControl = null;
+ return false;
+ }
+ else
+ {
+ //AppControl request was successful.
+ return true;
+ }
+}
+
+bool
+CallAppControlRequestMgr::LaunchDialerAppControl(IAppControlResponseListener* pListener)
+{
+ AppLogDebug("ENTER");
+ if (__pOpenedAppControl != null)
+ {
+ //An AppControl is already running.
+ String provider = __pOpenedAppControl->GetAppControlProviderId();
+ String operation = __pOpenedAppControl->GetOperationId();
+ AppLog( "Error:- AppControl is already running for provider id = %ls, operation id = %ls",
+ provider.GetPointer(), operation.GetPointer());
+ return false;
+ }
+
+ result r = E_FAILURE;
+ HashMap extraData;
+ extraData.Construct();
+ extraData.Add(new (std::nothrow) String(PARAM_PHONE_NUMBER), new (std::nothrow) String(L""));
+
+ __pOpenedAppControl = AppManager::FindAppControlN(PROVIDER_ID_PHONE, OPERATION_ID_DIAL);
+ if (__pOpenedAppControl != null)
+ {
+ r = __pOpenedAppControl->Start(null, null, &extraData, pListener);
+ }
+ extraData.RemoveAll(true);
+
+ if(r != E_SUCCESS)
+ {
+ //AppControl request failed, delete AppControl.
+ delete __pOpenedAppControl;
+ __pOpenedAppControl = null;
+ return false;
+ }
+ else
+ {
+ //AppControl request was successful.
+ return true;
+ }
+}