Tizen 2.1 base
[platform/framework/native/app-controls.git] / src / call-app-control / AppControlDLLEntry.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
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
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
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.
16 //
17
18 /**
19  * @file         AppControlDllEntry.cpp
20  * @brief       This is the implementation for the AppControlDllEntry.cpp class.
21  */
22
23 #include <appsvc/appsvc.h>
24
25 #include <FBaseSysLog.h>
26 #include <FAppAppControl.h>
27
28 #include <FBase_StringConverter.h>
29 #include <FApp_AppControlManager.h>
30 #include <FApp_AppMessageImpl.h>
31
32
33 using namespace Tizen::App;
34 using namespace Tizen::Base;
35 using namespace Tizen::Base::Collection;
36
37
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41
42
43 result _OSP_EXPORT_ StartAppControl(int req, const String&, const String&, const String*, const String*, const IMap*);
44 result _OSP_EXPORT_ TerminateAppControl(int req);
45
46 static const wchar_t __allowedAppControlCallTable[][2][64] =
47 {
48         {L"osp.appcontrol.CALL", L"osp.appcontrol.operation.DEFAULT"},
49         {L"osp.appcontrol.provider.call", L"osp.appcontrol.operation.call"},
50         {L"http://tizen.org/appcontrol/provider/call", L"http://tizen.org/appcontrol/operation/call"},
51         {L"tizen.phone", L"http://tizen.org/appcontrol/operation/call"},
52 };
53
54 static const wchar_t __allowedAppControlDialTable[][2][64] =
55 {
56         {L"osp.appcontrol.DIAL", L"osp.appcontrol.operation.DEFAULT"},
57         {L"osp.appcontrol.provider.call", L"osp.appcontrol.operation.dial"},
58         {L"http://tizen.org/appcontrol/provider/call", L"http://tizen.org/appcontrol/operation/dial"},
59         {L"tizen.phone", L"http://tizen.org/appcontrol/operation/dial"},
60 };
61
62
63 result
64 StartAppControl(int req, const String& providerId, const String& operationId, const String* pUri, const String* pMime, const IMap* pMap)
65 {
66         SysLog(NID_APP, "StartAppControl: Entry to Call AppControl");
67
68         result r = E_SUCCESS;
69         const char* pParam = null;
70         bool callMode = true;
71
72         static const char CALL_PKG_NAME[] = "org.tizen.call";
73         static const char DIAL_PKG_NAME[] = "org.tizen.phone";
74         static const char CALL_PKG_NAME_COMMERCIAL[] = "com.samsung.call";
75         static const char DIAL_PKG_NAME_COMMERCIAL[] = "com.samsung.phone";
76
77         const bool isCall = _AppControlManager::IsAllowedAppControl(__allowedAppControlCallTable, 4, providerId, operationId);
78         const bool isDial = _AppControlManager::IsAllowedAppControl(__allowedAppControlDialTable, 4, providerId, operationId);
79
80         SysTryReturnResult(NID_APP, isCall || isDial, E_SYSTEM, "Invalid AppControl entry for (%ls, %ls).", providerId.GetPointer(), operationId.GetPointer());
81
82         callMode = isCall;
83
84         if (pMap)
85         {
86                 _AppMessageImpl msg;
87                 msg.AddData(pMap);
88
89                 String phoneNumber = appsvc_get_data(msg.GetBundle(), "tel");
90                 if (!phoneNumber.IsEmpty())
91                 {
92                         phoneNumber.Insert(L"tel:", 0);
93
94                         pParam = _StringConverter::CopyToCharArrayN(phoneNumber);
95                         SysTryCatch(NID_APP, pParam != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] String conversion failure.");
96
97                         if (callMode)
98                         {
99                                 r = _AppControlManager::GetInstance()->LaunchPkg(CALL_PKG_NAME, APPSVC_OPERATION_CALL, NULL, pParam, NULL, 0);
100                                 if (IsFailed(r))
101                                 {
102                                         r = _AppControlManager::GetInstance()->LaunchPkg(CALL_PKG_NAME_COMMERCIAL, APPSVC_OPERATION_CALL, NULL, pParam, NULL, 0);
103                                 }
104                         }
105                         else
106                         {
107                                 r = _AppControlManager::GetInstance()->LaunchPkg(DIAL_PKG_NAME, APPSVC_OPERATION_DIAL, NULL, pParam, NULL, 0);
108                                 if (IsFailed(r))
109                                 {
110                                         r = _AppControlManager::GetInstance()->LaunchPkg(DIAL_PKG_NAME_COMMERCIAL, APPSVC_OPERATION_DIAL, NULL, pParam, NULL, 0);
111                                 }
112                         }
113
114                         SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] System error.", GetErrorMessage(r));
115
116                         SysLog(NID_APP, "StartAppControl: Launching Call AppControl succeeded");
117                 }
118         }
119 CATCH:
120         delete[] pParam;
121
122         return r;
123 }
124
125 result
126 TerminateAppControl(int req)
127 {
128         return E_SUCCESS;
129 }
130
131
132 #ifdef __cplusplus
133 }
134 #endif