2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.1 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://floralicense.org/license/
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an AS IS BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
18 * @file InstallerService.cpp
19 * @brief This file contains the declaration of InstallerService Class,
20 * which provides basic features necessary to define an ServiceApp.
24 #include <FGraphics.h>
29 #include "AppResourceId.h"
30 #include "InstallerService.h"
32 using namespace Tizen::App::Package;
33 using namespace Tizen::Base;
34 using namespace Tizen::Base::Collection;
35 using namespace Tizen::Graphics;
36 using namespace Tizen::Shell;
37 using namespace Tizen::System;
38 using namespace Tizen::Ui::Controls;
40 InstallerServiceApp::InstallerServiceApp(void)
42 , __pDegreeLabel(null)
46 , __filePathList(SingleObjectDeleter)
47 , __pDateTimeFormatter(null)
52 InstallerServiceApp::~InstallerServiceApp(void)
56 Tizen::App::ServiceApp*
57 InstallerServiceApp::CreateInstance(void)
59 return new (std::nothrow) InstallerServiceApp();
63 InstallerServiceApp::OnAppInitializing(Tizen::App::AppRegistry& appRegistry)
66 Tizen::App::AppControlProviderManager::GetInstance()->SetAppControlProviderEventListener(this);
68 __filePathList.Construct();
70 __pFrame = new (std::nothrow) QuickPanelFrame();
71 __pFrame->Construct(IDL_QUICK_INSTALLATION);
77 InstallerServiceApp::OnAppInitialized(void)
80 TryReturn(__filePathList.GetCount() != 0, false, "The filePath is not exist.");
82 __pDateTimeFormatter = Tizen::Locales::DateTimeFormatter::CreateTimeFormatterN(Tizen::Locales::DATE_TIME_STYLE_NONE);
84 SettingInfo::GetValue(L"http://tizen.org/setting/locale.time.format", pattern);
85 if (pattern.Contains(L":ss"))
87 pattern.Replace(L":ss", L"");
89 else if (pattern.Contains(L":SS"))
91 pattern.Replace(L":SS", L"");
93 else if (pattern.Contains(L".ss"))
95 pattern.Replace(L".ss", L"");
97 else if (pattern.Contains(L".SS"))
99 pattern.Replace(L".SS", L"");
101 else if (pattern.Contains(L"-ss"))
103 pattern.Replace(L"-ss", L"");
105 else if (pattern.Contains(L"-SS"))
107 pattern.Replace(L"-SS", L"");
109 __pDateTimeFormatter->ApplyPattern(pattern);
111 __pCountLabel = static_cast<Label*>(__pFrame->GetControl(IDC_LABEL_COUNT));
112 __pDegreeLabel = static_cast<Label*>(__pFrame->GetControl(IDC_LABEL_DEGREE));
113 __pProgress = static_cast<Progress*>(__pFrame->GetControl(IDC_PROGRESS));
115 result r = Install(*static_cast<String*>(__filePathList.GetAt(__index)));
125 InstallerServiceApp::OnAppTerminating(Tizen::App::AppRegistry& appRegistry, bool forcedTermination)
127 AppLogDebug("Enter");
130 delete __pDateTimeFormatter;
135 InstallerServiceApp::OnAppControlRequestReceived(RequestId reqId, const Tizen::Base::String& operationId,
136 const Tizen::Base::String* pUriData, const Tizen::Base::String* pMimeType, const Tizen::Base::Collection::IMap* pExtraData)
138 AppLogDebug("Enter");
139 Tizen::App::AppId clientAppId = Tizen::App::AppControlProviderManager::GetInstance()->GetClientAppId(reqId);
140 TryReturnVoid(clientAppId == L"D7eOJquGtL.Installer", "[%ls] This application is not allowed.", clientAppId.GetPointer());
141 TryReturnVoid(pUriData && pUriData->StartsWith(L"file://", 0), "There isn't URI data.");
143 String filePath = *pUriData;
144 filePath.Replace(L"file://", L"");
145 __filePathList.Add(new (std::nothrow) String(filePath));
147 if (__pFrame->IsVisible())
150 count.Format(10, L"%d/%d", __index+1, __filePathList.GetCount());
152 __pCountLabel->SetText(count);
153 __pCountLabel->Invalidate(false);
158 InstallerServiceApp::OnPackageInstallationCompleted(const Tizen::App::PackageId& packageId,
159 Tizen::App::Package::PackageInstallationResult installationResult)
161 AppLogDebug("Enter");
162 TryReturnVoid(packageId == __packageId, "PackageId: %ls", packageId.GetPointer());
163 PackageManager::GetInstance()->RemovePackageInstallationEventListener(*this);
165 Tizen::App::AppId mainAppId = __pInfo->GetMainAppId();
166 PackageAppInfo* pMainAppInfo = __pInfo->GetPackageAppInfoN(mainAppId);
167 String appName = __pInfo->GetDisplayName();
169 NotificationManager notificationManager;
170 notificationManager.Construct();
172 NotificationRequest request;
173 result r = request.SetIconFilePath(pMainAppInfo->GetAppMenuIconPath());
174 AppLogDebugIf(IsFailed(r), "[%s] Failed to set app icon.", GetErrorMessage(r));
176 if (!pMainAppInfo->IsMenuIconVisible())
178 AppLogDebug("This app hasn't a menu icon.");
186 SystemTime::GetCurrentTime(TIME_MODE_WALL, curTime);
187 __pDateTimeFormatter->Format(curTime, installTime);
188 installTime.Insert(L"\n", 0);
189 installTime.Insert(appName, 0);
191 request.SetAlertText(installTime);
195 switch (installationResult)
197 case PACKAGE_INSTALLATION_RESULT_SUCCESS:
198 AppLogDebug("PACKAGE_INSTALLATION_RESULT_SUCCESS");
199 Tizen::App::AppResource::GetInstance()->GetString(L"IDS_APINST_POP_INSTALLED", titleText);
201 case PACKAGE_INSTALLATION_RESULT_STORAGE_FULL:
202 AppLogDebug("PACKAGE_INSTALLATION_RESULT_STORAGE_FULL");
203 Tizen::App::AppResource::GetInstance()->GetString(L"IDS_APINST_BODY_UNABLE_TO_INSTALL_NOT_ENOUGH_MEMORY_ABB", titleText);
205 case PACKAGE_INSTALLATION_RESULT_INVALID_PACKAGE:
206 AppLogDebug("PACKAGE_INSTALLATION_RESULT_INVALID_PACKAGE");
207 Tizen::App::AppResource::GetInstance()->GetString(L"IDS_APINST_POP_FAILED", titleText);
211 request.SetTitleText(titleText);
213 if (installationResult != PACKAGE_INSTALLATION_RESULT_SUCCESS)
215 String* pFilePath = dynamic_cast<String*>(__filePathList.GetAt(__index));
218 request.SetAppMessage(*pFilePath);
220 mainAppId = L"D7eOJquGtL.Installer";
223 if (mainAppId.IsEmpty())
225 r = notificationManager.Notify(request);
226 AppLogExceptionIf(IsFailed(r), "[%s] Failed to notify message.", GetErrorMessage(r));
230 r = notificationManager.NotifyByAppId(mainAppId, request);
231 AppLogExceptionIf(IsFailed(r), "[%s] Failed to notify message.", GetErrorMessage(r));
234 String* pFilePath = null;
237 pFilePath = dynamic_cast<String*>(__filePathList.GetAt(++__index));
240 r = Install(*pFilePath);
248 __pFrame->SetShowState(false);
253 InstallerServiceApp::OnPackageInstallationInProgress(const Tizen::App::PackageId& packageId, int progress)
255 AppLogDebug("progress: %d", progress);
256 TryReturnVoid(packageId == __packageId, "PackageId: %ls", packageId.GetPointer());
258 if (__pProgress->GetValue() != progress)
260 __pProgress->SetValue(progress);
261 __pProgress->Invalidate(false);
262 __pDegreeLabel->SetText(Integer::ToString(progress) + L"%");
263 __pDegreeLabel->Invalidate(false);
268 InstallerServiceApp::OnPackageUninstallationCompleted(const Tizen::App::PackageId& packageId, bool uninstallationResult)
270 AppLogDebug("Enter");
271 TryReturnVoid(packageId == __packageId, "PackageId: %ls", packageId.GetPointer());
275 InstallerServiceApp::Install(const Tizen::Base::String& filePath)
277 AppLogDebug("Enter");
278 NotificationManager notificationManager;
282 __pInfo = PackageManager::GetInstance()->GetPackageInfoFromFileN(filePath);
283 TryReturn(__pInfo, GetLastResult(), "[%s] Failed to get the packageInfo. - %ls", GetErrorMessage(GetLastResult()), filePath.GetPointer());
284 __packageId = __pInfo->GetId();
286 PackageAppInfo* pMainAppInfo = __pInfo->GetPackageAppInfoN(__pInfo->GetMainAppId());
287 Bitmap* pAppIcon = pMainAppInfo->GetAppMenuIconN();
290 String appName = __pInfo->GetDisplayName();
294 Label* pIconLabel = static_cast<Label*>(__pFrame->GetControl(IDC_LABEL_ICON));
295 pIconLabel->SetBackgroundBitmap(*pAppIcon);
299 Label* pNameLabel = static_cast<Label*>(__pFrame->GetControl(IDC_LABEL_NAME));
300 pNameLabel->SetText(appName);
302 String notifyTextMsg;
303 Tizen::App::AppResource::GetInstance()->GetString(L"IDS_APINST_BODY_INSTALLING_PS_ING", notifyTextMsg);
304 notifyTextMsg.Format(notifyTextMsg.GetLength() + appName.GetLength(), notifyTextMsg.GetPointer(), appName.GetPointer());
306 PackageManager::GetInstance()->AddPackageInstallationEventListener(*this);
307 result r = PackageManager::GetInstance()->InstallPackage(__packageId, filePath, null);
308 TryCatch(r == E_SUCCESS, , "[%s] Failed to install package.", GetErrorMessage(r));
310 notificationManager.Construct();
311 notificationManager.NotifyTextMessage(notifyTextMsg);
313 count.Format(10, L"%d/%d", __index+1, __filePathList.GetCount());
314 __pCountLabel->SetText(count);
315 __pCountLabel->Invalidate(false);
317 __pProgress->SetValue(0);
318 __pDegreeLabel->SetText(L"0%");
320 __pFrame->Invalidate(true);
321 __pFrame->SetShowState(true);