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 MediaAppControlDllEntry.cpp
20 * @brief This is the implementation for the MediaAppControlDllEntry.cpp class.
23 #include <appsvc/appsvc.h>
25 #include <FBaseSysLog.h>
26 #include <FAppAppControl.h>
27 #include <FBaseColHashMap.h>
29 #include <FBase_StringConverter.h>
30 #include <FApp_AppControlManager.h>
31 #include <FApp_AppMessageImpl.h>
34 #include "ParseUtil.h"
36 using namespace Tizen::App;
37 using namespace Tizen::Base;
38 using namespace Tizen::Base::Collection;
39 using namespace Tizen::Base::Utility;
41 #define _DUMMY_APPCONTROL
47 result _OSP_EXPORT_ StartAppControl(int req, const String&, const String&, const String*, const String*, const IMap*);
48 result _OSP_EXPORT_ TerminateAppControl(int req);
49 void OnAppControlResult(void*, int, service_result_e, void*);
50 void OnAppControlResultGallery(void*, int, service_result_e, void*);
52 static int __req = -1;
53 static int __processId = -1;
55 static const wchar_t __allowedAppControlImageTable[][2][64] =
57 {L"osp.appcontrol.IMAGE", L"osp.appcontrol.operation.VIEW"},
58 {L"osp.appcontrol.provider.image", L"osp.appcontrol.operation.view"},
59 {L"http://tizen.org/appcontrol/provider/image", L"http://tizen.org/appcontrol/operation/view"},
60 {L"tizen.imageviewer", L"http://tizen.org/appcontrol/operation/view"},
63 static const wchar_t __allowedAppControlVideoTable[][2][64] =
65 {L"osp.appcontrol.VIDEO", L"osp.appcontrol.operation.PLAY"},
66 {L"osp.appcontrol.provider.video", L"osp.appcontrol.operation.play"},
67 {L"http://tizen.org/appcontrol/provider/video", L"http://tizen.org/appcontrol/operation/play"},
68 {L"tizen.videoplayer", L"http://tizen.org/appcontrol/operation/view"},
71 static const wchar_t __allowedAppControlAudioTable[][2][64] =
73 {L"osp.appcontrol.AUDIO", L"osp.appcontrol.operation.PLAY"},
74 {L"osp.appcontrol.provider.audio", L"osp.appcontrol.operation.play"},
75 {L"http://tizen.org/appcontrol/provider/audio", L"http://tizen.org/appcontrol/operation/play"},
76 {L"tizen.musicplayer", L"http://tizen.org/appcontrol/operation/view"},
79 static const wchar_t __allowedAppControlMediaTable[][2][64] =
81 {L"osp.appcontrol.MEDIA", L"osp.appcontrol.operation.PICK"},
82 {L"osp.appcontrol.provider.media", L"osp.appcontrol.operation.pick"},
83 {L"http://tizen.org/appcontrol/provider/media", L"http://tizen.org/appcontrol/operation/pick"},
84 {L"tizen.filemanager", L"http://tizen.org/appcontrol/operation/pick"},
89 StartAppControl(int req, const String& aId, const String& oId, const String* pUriData, const String* pMime, const IMap* pMap)
92 SysLog(NID_APP, "StartAppControl: Entry to Media AppControl");
94 const bool isImage = _AppControlManager::IsAllowedAppControl(__allowedAppControlImageTable, 4, aId, oId);
95 const bool isVideo = _AppControlManager::IsAllowedAppControl(__allowedAppControlVideoTable, 4, aId, oId);
96 const bool isAudio = _AppControlManager::IsAllowedAppControl(__allowedAppControlAudioTable, 4, aId, oId);
97 const bool isMedia = _AppControlManager::IsAllowedAppControl(__allowedAppControlMediaTable, 4, aId, oId);
102 SysTryCatch(NID_APP, pMap != null, r = E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The parameter is empty");
107 const String& type = msg.GetValue(KEY_TYPE);
108 String value = msg.GetValue(KEY_PATH);
110 if (!value.IsEmpty())
112 if (!value.StartsWith(L"file://", 0))
114 SysLog(NID_APP, "Inserting file scheme for %ls.", value.GetPointer());
115 value.Insert(L"file://", 0);
117 pPath = _StringConverter::CopyToCharArrayN(value); // Store the path
120 SysLog(NID_APP, "type(%ls), path(%ls)", type.GetPointer(), value.GetPointer());
122 __processId = _AppControlManager::GetInstance()->Launch(msg, "image-viewer-efl", APPSVC_OPERATION_VIEW, NULL, pPath, NULL, 0);
125 SysTryReturnResult(NID_APP, __processId >= 0, E_SYSTEM, "StartAppControl: Launching Image AppControl is failed.");
132 SysTryCatch(NID_APP, pMap != null, r = E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The parameter is empty");
137 String tmp = msg.GetValue(L"path");
140 if (tmp.StartsWith(L"http://", 0)
141 || tmp.StartsWith(L"rtsp://", 0)
142 || tmp.StartsWith(L"https://", 0))
145 pUri = _StringConverter::CopyToCharArrayN(tmp);
147 r = tmp.LastIndexOf(L'.', tmp.GetLength() - 1, i);
151 tmp.SubString(i + 1, extension);
154 r = _AppControlManager::GetMimeFromExt(extension, mime);
157 if (mime.Equals(L"video/3gpp", true))
159 SysLog(NID_APP, "Fix-up for audio appcontrol with [video/3gpp].");
160 mime = L"audio/3gpp";
162 pPath = _StringConverter::CopyToCharArrayN(mime);
163 SysLog(NID_APP, "URI(%s), MIME(%s) for music player", pUri, pPath);
170 pUri = _StringConverter::CopyToCharArrayN(tmp); // Store the path
174 // Check the exit on back option.
175 const String& exit = msg.GetValue(L"ExitOnBack");
178 bundle_del(msg.GetBundle(), "__APP_SVC_K_WIN_ID__");
181 __processId = _AppControlManager::GetInstance()->Launch(msg, "org.tizen.sound-player", APPSVC_OPERATION_VIEW, pPath, pUri, NULL, 0);
182 if (__processId <= 0)
184 __processId = _AppControlManager::GetInstance()->Launch(msg, "com.samsung.sound-player", APPSVC_OPERATION_VIEW, pPath, pUri, NULL, 0);
189 SysTryReturnResult(NID_APP, __processId >= 0, E_SYSTEM, "StartAppControl: Launching Audio AppControl is failed.");
195 SysTryCatch(NID_APP, pMap != null, r = E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The parameter is empty");
200 String tmp = msg.GetValue(L"path");
203 if (tmp.StartsWith(L"http://", 0)
204 || tmp.StartsWith(L"rtsp://", 0)
205 || tmp.StartsWith(L"file://", 0)
206 || tmp.StartsWith(L"https://", 0))
208 SysLog(NID_APP, "URI input");
212 // [INFO] path should be absolute path
213 tmp.Insert(L"file://", 0);
215 pPath = _StringConverter::CopyToCharArrayN(tmp); // Store the path
218 __processId = _AppControlManager::GetInstance()->Launch(msg, "org.tizen.video-player", APPSVC_OPERATION_VIEW, NULL, pPath, NULL, 0);
219 if (__processId <= 0)
221 __processId = _AppControlManager::GetInstance()->Launch(msg, "com.samsung.video-player", APPSVC_OPERATION_VIEW, NULL, pPath, NULL, 0);
225 SysTryReturnResult(NID_APP, __processId >= 0, E_SYSTEM, "StartAppControl: Launching Video AppControl is failed.");
230 const int TYPE_ALL = 0;
231 const int TYPE_AUDIO = 1;
232 const int TYPE_VIDEO = 2;
233 const int TYPE_IMAGE = 3;
235 bool singleSelection = true;
238 SysTryCatch(NID_APP, pMap != null, r = E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The parameter is empty");
243 const char* pBuf = appsvc_get_data(msg.GetBundle(), "selectionType");
246 singleSelection = !(strncmp(pBuf, "multiple", 9) == 0);
249 pBuf = appsvc_get_data(msg.GetBundle(), "type");
252 if (strncmp(pBuf, "all", sizeof("all")) == 0)
256 else if (strncmp(pBuf, "image", sizeof("image")) == 0)
260 else if (strncmp(pBuf, "video", sizeof("video")) == 0)
264 else if (strncmp(pBuf, "audio", sizeof("audio")) == 0)
273 msg.AddData(L"file_type", L"ALL");
275 msg.AddData(L"select_type", (singleSelection) ? "SINGLE_FILE" : "MULTI_FILE");
276 __processId = _AppControlManager::GetInstance()->Launch(msg, "myfile-efl", APPSVC_OPERATION_PICK, NULL, NULL, OnAppControlResult, 0);
281 msg.AddData(L"file_type", L"SOUND");
283 msg.AddData(L"select_type", (singleSelection) ? "SINGLE_FILE" : "MULTI_FILE");
284 __processId = _AppControlManager::GetInstance()->Launch(msg, "myfile-efl", APPSVC_OPERATION_PICK, NULL, NULL, OnAppControlResult, 0);
289 msg.AddData(L"file-type", L"image");
291 msg.AddData(L"launch-type", (singleSelection) ? "select-one" : "select-multiple");
292 __processId = _AppControlManager::GetInstance()->Launch(msg, "gallery-efl", APPSVC_OPERATION_PICK, NULL, NULL, OnAppControlResultGallery, 0);
297 msg.AddData(L"file-type", L"video");
299 msg.AddData(L"launch-type", (singleSelection) ? "select-one" : "select-multiple");
300 __processId = _AppControlManager::GetInstance()->Launch(msg, "gallery-efl", APPSVC_OPERATION_PICK, NULL, NULL, OnAppControlResultGallery, 0);
305 SysLog(NID_APP, "Wrong type or no type information.");
309 SysTryReturnResult(NID_APP, __processId >= 0, E_SYSTEM, "StartAppControl: Launching Media AppControl is failed.");
312 else if (aId == L"osp.appcontrol.provider.imageeditor")
314 #if defined (_DUMMY_APPCONTROL)
315 SysLogException(NID_MEDIA, E_SUCCESS, "NOT IMPLEMENTED");
316 HashMap* pResult = null;
317 pResult = new (std::nothrow) HashMap();
318 SysTryCatch(NID_APP, pResult != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Allocation failure.");
320 r = pResult->Construct();
322 pResult->Add(new (std::nothrow) String(L"path"), new (std::nothrow) String(L"/opt/media/Images/image2.jpg"));
323 _AppControlManager::GetInstance()->FinishAppControl(req, 0, pResult);
336 TerminateAppControl(int req)
338 if (__processId >= 0)
340 _Aul::TerminateApplicationByPid(__processId);
346 OnAppControlResult(void* b, int requestCode, service_result_e res, void* userData)
348 SysLog(NID_APP, "@@@@@@ OnAppControlResult for myfiles");
351 bundle* pBundle = static_cast<bundle*>(b);
353 HashMap* pResult = new (std::nothrow) HashMap();
354 SysTryCatch(NID_APP, pResult != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Allocation failure.");
356 r = pResult->Construct();
360 case SERVICE_RESULT_SUCCEEDED:
362 const char* const pData = appsvc_get_data(pBundle, "result");
365 SysLog(NID_APP, "Received data is [%s].", pData);
367 // [INFO] '?' delimiter for multifile files
369 tmp.Replace(L'?', L';');
370 SysLog(NID_APP, "Converted string is [%ls].", tmp.GetPointer());
371 pResult->Add(new (std::nothrow) String(L"path"), new (std::nothrow) String(tmp));
375 case SERVICE_RESULT_FAILED:
378 case SERVICE_RESULT_CANCELED:
385 _AppControlManager::GetInstance()->FinishAppControl(__req, res, pResult);
392 OnAppControlResultGallery(void* b, int requestCode, service_result_e res, void* userData)
394 SysLog(NID_APP, "@@@@@@ OnAppControlResult for gallery");
396 // the result from ug does not follow service protocol
397 // success -> ("path", value)
398 // cancel -> ("ug-quit", "normal")
401 bundle* pBundle = static_cast<bundle*>(b);
403 const char* pData = appsvc_get_data(pBundle, "path");
407 HashMap* pResult = new (std::nothrow) HashMap();
408 SysTryCatch(NID_APP, pResult != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Allocation failure.");
410 r = pResult->Construct();
412 SysLog(NID_APP, "Received data is [%s].", pData);
413 pResult->Add(new (std::nothrow) String(L"path"), new (std::nothrow) String(pData));
414 _AppControlManager::GetInstance()->FinishAppControl(__req, APP_CTRL_RESULT_SUCCEEDED, pResult);
418 pData = appsvc_get_data(pBundle, "ug-quit");
419 SysLog(NID_APP, "The operation cancled or finished (%s)", (pData) ? pData : "no-data");
420 _AppControlManager::GetInstance()->FinishAppControl(__req, APP_CTRL_RESULT_CANCELED, null);