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 MessageAppControlDllEntry.cpp
20 * @brief This is the implementation for the MessageAppControlDllEntry.cpp class.
23 #include <appsvc/appsvc.h>
25 #include <FBaseSysLog.h>
26 #include <FBaseUtilStringTokenizer.h>
27 #include <FBaseColHashMap.h>
28 #include <FAppAppControl.h>
30 #include <FBase_StringConverter.h>
31 #include <FApp_AppControlManager.h>
32 #include <FApp_AppMessageImpl.h>
34 #include <FApp_AppArg.h>
36 using namespace Tizen::App;
37 using namespace Tizen::Base;
38 using namespace Tizen::Base::Collection;
39 using namespace Tizen::Base::Utility;
46 static const wchar_t APP_CONTROL_ATTACH_PATH[] = L"http://tizen.org/appcontrol/data/path";
47 static const wchar_t APP_CONTROL_MESSAGE_TYPE[] = L"http://tizen.org/appcontrol/data/message/type";
50 result _OSP_EXPORT_ StartAppControl(int req, const String&, const String&, const String*, const String*, const IMap*);
51 result _OSP_EXPORT_ TerminateAppControl(int req);
52 static void OnAppControlResult(void*, int, service_result_e, void*);
54 static int __processId = -1;
56 static const char __allowedAppControlMessageTable[][2][96] =
58 {"osp.appcontrol.MESSAGE", "osp.appcontrol.operation.EDIT"},
59 {"osp.appcontrol.provider.message", "osp.appcontrol.operation.compose"},
60 {"tizen.messages", "http://tizen.org/appcontrol/operation/compose"},
61 {"tizen.smsmessages", "http://tizen.org/appcontrol/operation/compose"},
62 {"tizen.mmsmessages", "http://tizen.org/appcontrol/operation/compose"},
65 static const char __allowedAppControlEmailTable[][2][96] =
67 {"osp.appcontrol.EMAIL", "osp.appcontrol.operation.EDIT"},
68 {"osp.appcontrol.provider.email", "osp.appcontrol.operation.compose"},
69 {"tizen.email", "http://tizen.org/appcontrol/operation/compose"},
74 StartAppControl(int req, const String& aId, const String& oId, const String* pUri, const String* pMime, const IMap* pMap)
76 SysLog(NID_APP, "StartAppControl: Entry to Message AppControl");
80 SysLog(NID_APP, "aId : %ls, oId : %ls", aId.GetPointer(), oId.GetPointer());
82 const bool isMessage = _AppControlManager::IsAllowedAppControl(__allowedAppControlMessageTable, 5, aId, oId);
83 const bool isEmail = _AppControlManager::IsAllowedAppControl(__allowedAppControlEmailTable, 3, aId, oId);
85 SysTryReturnResult(NID_APP, isMessage || isEmail, E_SYSTEM, "Invalid AppControl entry for (%ls, %ls).", aId.GetPointer(), oId.GetPointer());
89 SysLog(NID_APP, "Message AppControl starts..");
95 const String& type = msg.GetValue(APP_CONTROL_MESSAGE_TYPE);
98 String legacyType = msg.GetValue(L"type");
99 if (!legacyType.IsEmpty())
101 legacyType.ToLowerCase();
103 msg.AddData(APP_CONTROL_MESSAGE_TYPE, legacyType);
108 String tmp = msg.GetValue(L"to");
112 String tmpCc = msg.GetValue(L"cc");
113 if (!tmpCc.IsEmpty())
115 tmp.Append(L';' + tmpCc);
119 String tmpBcc = msg.GetValue(L"bcc");
120 if (!tmpBcc.IsEmpty())
122 tmp.Append(L';' + tmpBcc);
125 tmp.Replace(L';', L',');
126 msg.AddData(SERVICE_DATA_TO, tmp);
130 tmp = msg.GetValue(L"subject");
133 SysLog(NID_APP, "subject: [%ls]", tmp.GetPointer());
134 msg.AddData(SERVICE_DATA_SUBJECT, tmp);
138 tmp = msg.GetValue(L"text");
141 SysLog(NID_APP, "text: [%ls]", tmp.GetPointer());
142 msg.AddData(SERVICE_DATA_TEXT, tmp);
145 const String& path = msg.GetValue(APP_CONTROL_ATTACH_PATH);
152 const String& tmpVcard = msg.GetValue(L"attachVcard");
153 if (!tmpVcard.IsEmpty())
159 const String& tmpVcal = msg.GetValue(L"attachVcalendar");
160 if (!tmpVcal.IsEmpty())
166 const String& tmpVideo = msg.GetValue(L"attachVideo");
167 if (!tmpVideo.IsEmpty())
173 const String& tmpImage = msg.GetValue(L"attachImage");
174 if (!tmpImage.IsEmpty())
180 const String& tmpAudio = msg.GetValue(L"attachAudio");
181 if (!tmpAudio.IsEmpty())
186 if (list.GetCount() != 0)
188 SysLog(NID_APP, "Attaching %d items.", list.GetCount());
190 _AppMessageImpl::AddValueArray(msg.GetBundle(), APP_CONTROL_ATTACH_PATH, &list);
191 //msg.AddValueArray(APP_CONTROL_ATTACH_PATH, &list);
195 const String& package = _AppControlManager::GetAliasAppId(aId);
196 __processId = _AppControlManager::GetInstance()->Launch(msg, package, oId, pUri, pMime, NULL, reinterpret_cast<void*>(req));
198 SysTryReturnResult(NID_APP, __processId >= 0, E_SYSTEM, "StartAppControl: Launching Email AppControl is failed.");
199 SysLog(NID_APP, "StartAppControl: Launching Message AppControl succeeded.");
204 SysLog(NID_APP, "Email AppControl starts..");
209 String tmp = msg.GetValue(L"to");
212 msg.AddData(SERVICE_DATA_TO, tmp);
215 tmp = msg.GetValue(L"cc");
218 msg.AddData(SERVICE_DATA_CC, tmp);
221 tmp = msg.GetValue(L"bcc");
224 msg.AddData(SERVICE_DATA_BCC, tmp);
227 tmp = msg.GetValue(L"subject");
230 msg.AddData(SERVICE_DATA_SUBJECT, tmp);
233 tmp = msg.GetValue(L"text");
236 msg.AddData(SERVICE_DATA_TEXT, tmp);
239 tmp = msg.GetValue(L"attachments");
242 const String& path = msg.GetValue(APP_CONTROL_ATTACH_PATH);
243 // if path is delivered, then ignore "attachments" data
246 const String delim = L";";
247 StringTokenizer strTok(tmp, delim);
249 const int count = strTok.GetTokenCount();
252 ArrayList list(SingleObjectDeleter);
256 while (strTok.HasMoreTokens())
258 strTok.GetNextToken(token);
259 list.Add(new (std::nothrow) String(token));
262 _AppMessageImpl::AddValueArray(msg.GetBundle(), APP_CONTROL_ATTACH_PATH, &list);
263 //msg.AddValueArray(APP_CONTROL_ATTACH_PATH, &list);
268 const String& package = _AppControlManager::GetAliasAppId(aId);
269 __processId = _AppControlManager::GetInstance()->Launch(msg, package, oId, pUri, pMime, OnAppControlResult, reinterpret_cast<void*>(req));
271 SysTryReturnResult(NID_APP, __processId >= 0, E_SYSTEM, "StartAppControl: Launching Email AppControl is failed.");
272 SysLog(NID_APP, "StartAppControl: Launching Email AppControl succeeded.");
279 TerminateAppControl(int req)
281 if (__processId >= 0)
283 _Aul::TerminateApplicationByPid(__processId);
289 OnAppControlResult(void* b, int requestCode, service_result_e res, void* userData)
291 SysLog(NID_APP, "OnAppControlResult with %d.", res);
295 bundle* pBundle = static_cast<bundle*>(b);
297 HashMap* pResult = new (std::nothrow) HashMap();
298 SysTryCatch(NID_APP, pResult != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Allocation failure.");
300 r = pResult->Construct();
302 _AppArg::SetArgMap(pBundle, pResult);
304 req = reinterpret_cast<int>(userData);
305 _AppControlManager::GetInstance()->FinishAppControl(req, res, pResult);