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.
18 * @file UninstallStep.cpp
19 * @brief This is the implementation file for %UninstallStep class.
22 #include <unique_ptr.h>
24 #include <app2ext_interface.h>
26 #include <FIoDirectory.h>
27 #include <FIo_FileImpl.h>
28 #include <FBase_StringConverter.h>
29 #include <FAppPkg_PackageInfoImpl.h>
31 #include "InstallationContext.h"
32 #include "UninstallStep.h"
33 #include "InstallerUtil.h"
34 #include "CompatibilityManager.h"
36 using namespace Tizen::Base;
37 using namespace Tizen::Base::Collection;
38 using namespace Tizen::App;
39 using namespace Tizen::App::Package;
40 using namespace Tizen::Io;
42 UninstallStep::UninstallStep(void)
43 :__state(STATE_GET_PACKAGEINFO)
48 UninstallStep::~UninstallStep(void)
53 UninstallStep::Run(InstallationContext* pContext)
55 InstallerError error = INSTALLER_ERROR_NONE;
56 AppLog(" UninstallStep - START");
58 __pContext = pContext;
64 case STATE_GET_PACKAGEINFO:
65 AppLog("[STATE_GET_PACKAGEINFO]");
66 error = OnStateGetPackageInfo();
69 case STATE_CHECK_APP_RUNNING:
70 AppLog("[STATE_CHECK_APP_RUNNING]");
71 error = OnStateCheckAppRunning();
74 case STATE_TERMINATE_APP:
75 AppLog("[STATE_TERMINATE_APP]");
76 error = OnStateTerminateApp();
79 case STATE_START_TIMER:
80 AppLog("[STATE_START_TIMER]");
81 error = OnStateStartTimer();
84 case STATE_DELETE_DIR:
85 AppLog("[STATE_DELETE_DIR]");
86 error = OnStateRemoveDir();
90 AppLog("[STATE_DONE]");
91 error = OnStateDone();
98 if (error != INSTALLER_ERROR_NONE)
103 if (__state > STATE_DONE)
105 AppLog(" UninstallStep - END");
114 UninstallStep::GoNextState(void)
120 UninstallStep::OnStateGetPackageInfo(void)
122 InstallerError error = INSTALLER_ERROR_NONE;
123 PackageId packageId = __pContext->__packageId;
125 std::unique_ptr< _PackageInfoImpl > pPackageInfoImpl(new (std::nothrow) _PackageInfoImpl());
126 TryReturn(pPackageInfoImpl, INSTALLER_ERROR_OUT_OF_MEMORY, "pPackageInfoImpl is null.");
128 AppLog("package = %ls", packageId.GetPointer());
130 result r = pPackageInfoImpl->Construct(packageId);
131 TryReturn(r == E_SUCCESS, INSTALLER_ERROR_INTERNAL_STATE, "pPackageInfoImpl->Construct(%ls) failed.", packageId.GetPointer());
133 // bool isUninstallable = pPackageInfoImpl->IsUninstallable();
134 // if (isUninstallable == false)
136 // __pContext->__additionalErrorString = L"Thrown when the application cannot be uninstalled because the application was preloaded.";
138 // TryReturn(isUninstallable == true, INSTALLER_ERROR_PACKAGE_INVALID, "preload app cannot be uninstalled.");
141 rwXmlPath.Format(1024, DIR_RW_PACKAGE_SYSTEM_MANIFEST, packageId.GetPointer());
142 if (File::IsFileExist(rwXmlPath) == false)
144 AppLog("This is a preload app = [%ls]", rwXmlPath.GetPointer());
145 __pContext->__isPreloaded = true;
148 __pContext->__rootPath = pPackageInfoImpl->GetAppRootPath();
150 if (__pContext->__isHybridService == true)
152 AppLog("Uninstallation for HybridService");
153 __state = STATE_TERMINATE_APP;
157 if (pPackageInfoImpl->IsInstalledInExternalStorage() == true)
160 app2ext_handle* pHandle = null;
162 std::unique_ptr<char[]> pPackageId(_StringConverter::CopyToCharArrayN(packageId));
163 TryReturn(pPackageId, INSTALLER_ERROR_INTERNAL_STATE, "pAppId is null");
165 pHandle = app2ext_init(APP2EXT_SD_CARD);
166 TryReturn(pHandle, INSTALLER_ERROR_INTERNAL_STATE, "app2ext_init() failed");
168 res = pHandle->interface.pre_uninstall(pPackageId.get());
169 TryReturn(res == 0, INSTALLER_ERROR_INTERNAL_STATE, "pHandle->interface.pre_uninstall() failed [%d]", res);
171 __pContext->__pApp2ExtHandle = (void*)pHandle;
173 AppLog("[app2sd] pre_uninstall(%s)", pPackageId.get());
176 ArrayList* pList = pPackageInfoImpl->GetAppInfoListN();
177 TryReturn(pList, INSTALLER_ERROR_DATABASE, "pList is null.");
179 for (int i = 0; i < pList->GetCount(); i++)
181 _PackageAppInfoImpl* pAppInfoImpl = dynamic_cast<_PackageAppInfoImpl*>(pList->GetAt(i));
184 AppData* pAppData = new (std::nothrow) AppData;
185 TryReturn(pAppData, INSTALLER_ERROR_OUT_OF_MEMORY, "pAppData is null");
187 error = pAppData->Construct();
188 TryReturn(error == INSTALLER_ERROR_NONE, INSTALLER_ERROR_INTERNAL_STATE, "pAppData->Construct() failed.");
190 pAppData->__appId = pAppInfoImpl->GetPackageName();
191 pAppData->__feature = pAppInfoImpl->GetAppFeature();
193 __pContext->__pAppDataList->Add(pAppData);
198 __state = STATE_TERMINATE_APP;
205 UninstallStep::OnStateCheckAppRunning(void)
207 InstallerError error = INSTALLER_ERROR_NONE;
214 UninstallStep::OnStateTerminateApp(void)
216 InstallerError error = INSTALLER_ERROR_NONE;
218 InstallerUtil::TerminateApps(__pContext->__packageId);
225 UninstallStep::OnStateStartTimer(void)
227 InstallerError error = INSTALLER_ERROR_NONE;
234 UninstallStep::OnStateRemoveDir(void)
236 InstallerError error = INSTALLER_ERROR_NONE;
240 rootPath = __pContext->__rootPath;
241 AppLog("rootPath = [%ls]", rootPath.GetPointer());
243 String compatPath(rootPath);
244 compatPath.Append(L"/info/compat.info");
245 bool ospCompat = File::IsFileExist(compatPath);
246 result r = GetLastResult();
247 if (r == E_SUCCESS && ospCompat == true)
249 if (CompatibilityManager::FinalizeDataCaging(rootPath) == false)
251 AppLog("[Tizen::Io] Failed to unmount directories for 2.0 application, appRootPath: %ls",
252 rootPath.GetPointer());
253 return INSTALLER_ERROR_UNMOUNT_FAILED;
256 else if (r != E_SUCCESS)
258 AppLog("[Tizen::Io] Failed to access %ls", compatPath.GetPointer());
259 return INSTALLER_ERROR_UNMOUNT_FAILED;
262 CompatibilityManager::CleanDirectories(rootPath, __pContext->__packageId);
264 String virtualRoot = rootPath + DIR_VIRTUAL_ROOT;
265 if (File::IsFileExist(virtualRoot) == true)
267 res = CompatibilityManager::FinalizeVirtualRoot(rootPath);
268 TryReturn(res == true, INSTALLER_ERROR_UNMOUNT_FAILED, "CompatibilityManager::FinalizeVirtualRoot(%ls) failed.", rootPath.GetPointer());
271 AppLog("Directory::Remove - START");
273 if (__pContext->__isHybridService == true)
275 AppLog("Uninstallation for HybridService - skip Remove");
281 if (InstallerUtil::IsSymlink(rootPath) == true)
283 if (InstallerUtil::GetRealPath(rootPath, realPath) == true)
285 InstallerUtil::Remove(realPath);
289 InstallerUtil::Remove(rootPath);
292 IListT<AppData*>* pAppDataList = __pContext->__pAppDataList;
293 TryReturn(pAppDataList, INSTALLER_ERROR_INTERNAL_STATE, "pAppDataList is null");
295 int count = pAppDataList->GetCount();
296 for (int i = 0; i < count; i++)
298 AppData* pAppData = null;
299 pAppDataList->GetAt(i, pAppData);
303 if (pAppData->__feature == CATEGORY_TYPE_IME)
306 symlinkPath.Format(1024, L"%s/%ls.so", IME_PATH, pAppData->__appId.GetPointer());
307 InstallerUtil::Remove(symlinkPath);
312 AppLog("Directory::Remove - END");
319 UninstallStep::OnStateDone(void)
321 InstallerError error = INSTALLER_ERROR_NONE;