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 FShellLiveboxManager.cpp
20 * @brief This is the implementation for the LiveboxManager class.
23 #include <unique_ptr.h>
26 #include <livebox-service/livebox-service.h>
28 #include <FBaseSysLog.h>
30 #include <FGraphics.h>
32 #include <FAppPkgPackageInfo.h>
33 #include <FApp_Types.h>
34 #include <FApp_AppInfo.h>
35 #include <FAppPkg_PackageManagerImpl.h>
36 #include <FBase_StringConverter.h>
38 #include <FShellLiveboxManager.h>
39 #include <FShellLiveboxProviderInfo.h>
40 #include "FShell_LiveboxManagerImpl.h"
43 using namespace Tizen::App;
44 using namespace Tizen::App::Package;
45 using namespace Tizen::Base;
46 using namespace Tizen::Base::Collection;
47 using namespace Tizen::Graphics;
50 namespace Tizen { namespace Shell
53 LiveboxManager::LiveboxManager()
54 :__pLiveboxManagerImpl(null)
59 LiveboxManager::~LiveboxManager()
64 LiveboxManager::GetInstance()
66 static LiveboxManager* pLiveboxManager = null;
67 if( pLiveboxManager == null)
69 pLiveboxManager = new LiveboxManager;
70 SysTryReturn(NID_APP, pLiveboxManager, null, E_OUT_OF_MEMORY, "E_OUT_OF_MEMORY" );
72 result r = pLiveboxManager->Construct();
73 // SysTryReturn(NID_APP, !IsFailed(r), null, r, "[%s] Propagating.", GetErrorMessage(r));
74 SysAssertf(!IsFailed(r), "Failed to construct LiveboxManager!!");
75 SysLog(NID_APP, "LiveboxManager instance is created.");
78 return pLiveboxManager;
82 LiveboxManager::Construct()
84 SysAssert(__pLiveboxManagerImpl == null);
86 SysLog(NID_APP, "Enter.");
87 __pLiveboxManagerImpl = _LiveboxManagerImpl::GetInstance();
88 SysAssertf(__pLiveboxManagerImpl, "Failed to construct _LiveboxManagerImpl!!");
90 SysLog(NID_APP, "Exit.");
96 LiveboxManager::SetLiveboxProviderFactory(ILiveboxProviderFactory& factory)
98 return __pLiveboxManagerImpl->SetLiveboxProviderFactory(factory);
102 LiveboxManager::SetLiveboxPopupProviderFactory(ILiveboxPopupProviderFactory& factory)
104 return __pLiveboxManagerImpl->SetLiveboxPopupProviderFactory(factory);
108 //LiveboxManager::HandleRequest(const Tizen::Base::String& operationId, Tizen::Base::String* pCategory, Tizen::Base::Collection::IList* pArgs)
110 // return __pLiveboxManagerImpl->HandleRequest(operationId, pCategory, pArgs);
113 Tizen::Base::Collection::IList*
114 LiveboxManager::GetLiveboxProviderInfosN()
116 return __pLiveboxManagerImpl->GetLiveboxProviderInfosN();
120 LiveboxManager::GetLiveboxProviderInfoN(const Tizen::App::AppId& appId, const Tizen::Base::String& providerName)
122 // TODO : set configurationAppcontrolAppId
123 return new LiveboxProviderInfo(appId, providerName);
129 LiveboxManager::RequestUpdate()
131 Tizen::App::AppId appId(Tizen::App::_AppInfo::GetAppId());
133 std::unique_ptr<char[]> pPackageId(_StringConverter::CopyToCharArrayN(appId));
134 int ret = livebox_service_trigger_update(pPackageId.get(), "user,created", "default");
135 SysTryReturnResult(NID_APP, ret == 0, E_SYSTEM, "[E_SYSTEM] Failed to invoke livebox_service_trigger_update, ret (%d)", ret);
142 LiveboxManager::RequestUpdate(const Tizen::App::AppId& appId, const Tizen::Base::String& providerName, const Tizen::Base::String& argument)
144 __pLiveboxManagerImpl->RequestUpdate(appId, providerName);
150 //LiveboxManager::TerminateAppIfInvalidState()
152 // __pLiveboxManagerImpl->TerminateAppIfInvalidState();
158 int AddLiveboxCallback(int ret, int pid, void *data)
162 SysLog(NID_APP, "Error.(%d)", ret);
171 LiveboxManager::AddLivebox(const Tizen::App::AppId& targetAppId, const Tizen::Base::String& providerAppId, const Tizen::Base::String& providerName, const Tizen::Base::String& text, const Tizen::Base::String& userInfo)
173 SysTryReturnResult(NID_APP, providerAppId.IsEmpty()==false, E_INVALID_ARG, "The providerAppId is empty.");
174 SysTryReturnResult(NID_APP, providerAppId.GetLength() < NATIVE_APP_MAX_APPID_LENGTH, E_INVALID_ARG, "The providerAppId is too long (Maximum %d bytes).", NATIVE_APP_MAX_APPID_LENGTH);
175 SysTryReturnResult(NID_APP, _PackageManagerImpl::IsAppInstalled(providerAppId) == true, E_APP_NOT_INSTALLED, "The application(%ls) is not installed.", providerAppId.GetPointer());
177 //TODO :: check privilege
179 if( providerAppId.StartsWith(L"com.samsung", 0) == true )
181 SysLog(NID_APP, "[E_INVALID_OPERATION] but allowed to test");
182 //TODO:return E_INVALID_OPERATION
183 providerId = providerAppId;
187 String localPackageId = _PackageManagerImpl::GetPackageIdByAppId(Tizen::App::App::GetInstance()->GetAppId());
188 String liveboxProviderPackageId = _PackageManagerImpl::GetPackageIdByAppId(providerAppId);
189 if( localPackageId != liveboxProviderPackageId)
191 SysLog(NID_APP, "[E_INVALID_OPERATION] but allowed to test");
192 //TODO:return E_INVALID_OPERATION
194 providerId = providerAppId + "." + providerName;
197 PackageInfo* pPackageInfo = null;
198 result r = E_SUCCESS;
200 pPackageInfo = _PackageManagerImpl::GetInstance()->GetPackageInfoN(providerAppId);
201 SysTryReturn(NID_APP, pPackageInfo != null, r, r, "[%s] Propagating.", GetErrorMessage(r));
203 String iconPath; //= packageInfo.GetAppIconPath();
207 std::unique_ptr<char[]> pProviderId(_StringConverter::CopyToCharArrayN(providerId));
208 std::unique_ptr<char[]> pName(_StringConverter::CopyToCharArrayN(text));
209 std::unique_ptr<char[]> pContent(_StringConverter::CopyToCharArrayN(userInfo));
210 std::unique_ptr<char[]> pIcon(_StringConverter::CopyToCharArrayN(iconPath));
212 int ret = add_to_home_livebox(pProviderId.get(), pName.get(), LAUNCH_BY_PACKAGE, pContent.get(), pIcon.get(), -1.0l, AddLiveboxCallback, this);
213 SysTryReturnResult(NID_APP, ret == 0, E_SYSTEM, "[E_SYSTEM] failed to add_to_home_livebox (%d)", ret);
218 // c style callback for shortcut_set_request_cb
219 int LiveboxRequestEventHandler(const char* providerId, const char* text, int type, const char* content_info, const char* icon, int pid, double period, void *data)
221 SysTryReturn(NID_APP, providerId, 0, E_SYSTEM, "[E_SYSTEM] providerId is null!");
223 LiveboxManager* pLiveboxManager = static_cast<LiveboxManager*>(data);
224 SysTryReturn(NID_APP, pLiveboxManager, 0, E_SYSTEM, "[E_SYSTEM] pLiveboxManager is null!");
228 _LiveboxManagerImpl::ExtractAppIdAndProviderName(providerId, appId, providerName);
230 //OnLiveboxAddRequested(const Tizen::Base::AppId& appId, const const Tizen::Base::String& providerName, const Tizen::Base::String& userInfo, const const Tizen::Base::String& text, const Tizen::Base::String& iconPath)
231 pLiveboxManager->__pLiveboxRequestEventListener->OnLiveboxAddRequested(appId, providerName, content_info, text );
237 LiveboxManager::SetLiveboxRequestEventHandler(ILiveboxRequestEventListener& listener)
239 int ret = shortcut_set_request_cb(LiveboxRequestEventHandler, this );
240 SysTryReturnResult(NID_APP, ret == 0, E_SYSTEM, "failed to shortcut_set_request_cb (%d)", ret);
242 __pLiveboxRequestEventListener = &listener;