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_PackageManagerImpl.h>
30 #include <FAppPkg_PackageInfoImpl.h>
31 #include <FAppPkg_PackageAppInfoImpl.h>
33 #include "InstallationContext.h"
34 #include "UninstallStep.h"
35 #include "InstallerUtil.h"
37 using namespace Tizen::Base;
38 using namespace Tizen::Base::Collection;
39 using namespace Tizen::App;
40 using namespace Tizen::App::Package;
41 using namespace Tizen::Io;
43 UninstallStep::UninstallStep(void)
44 :__state(STATE_GET_PACKAGEINFO)
49 UninstallStep::~UninstallStep(void)
54 UninstallStep::Run(InstallationContext* pContext)
56 InstallerError error = INSTALLER_ERROR_NONE;
57 AppLog(" UninstallStep - START");
59 __pContext = pContext;
65 case STATE_GET_PACKAGEINFO:
66 AppLog("[STATE_GET_PACKAGEINFO]");
67 error = OnStateGetPackageInfo();
70 case STATE_CHECK_APP_RUNNING:
71 AppLog("[STATE_CHECK_APP_RUNNING]");
72 error = OnStateCheckAppRunning();
75 case STATE_TERMINATE_APP:
76 AppLog("[STATE_TERMINATE_APP]");
77 error = OnStateTerminateApp();
80 case STATE_START_TIMER:
81 AppLog("[STATE_START_TIMER]");
82 error = OnStateStartTimer();
85 case STATE_DELETE_DIR:
86 AppLog("[STATE_DELETE_DIR]");
87 error = OnStateRemoveDir();
91 AppLog("[STATE_DONE]");
92 error = OnStateDone();
99 if (error != INSTALLER_ERROR_NONE)
104 if (__state > STATE_DONE)
106 AppLog(" UninstallStep - END");
115 UninstallStep::GoNextState(void)
121 UninstallStep::OnStateGetPackageInfo(void)
123 InstallerError error = INSTALLER_ERROR_NONE;
124 PackageId packageId = __pContext->__packageId;
126 std::unique_ptr< _PackageInfoImpl > pPackageInfoImpl(new (std::nothrow) _PackageInfoImpl());
127 TryReturn(pPackageInfoImpl, INSTALLER_ERROR_OUT_OF_MEMORY, "pPackageInfoImpl is null.");
129 AppLog("package = %ls", packageId.GetPointer());
131 result r = pPackageInfoImpl->Construct(packageId);
132 TryReturn(r == E_SUCCESS, INSTALLER_ERROR_INTERNAL_STATE, "pPackageInfoImpl->Construct(%ls) failed.", packageId.GetPointer());
134 // bool isUninstallable = pPackageInfoImpl->IsUninstallable();
135 // if (isUninstallable == false)
137 // __pContext->__additionalErrorString = L"Thrown when the application cannot be uninstalled because the application was preloaded.";
139 // TryReturn(isUninstallable == true, INSTALLER_ERROR_PACKAGE_INVALID, "preload app cannot be uninstalled.");
140 String filePath = PATH_USR_APPS;
142 filePath += __pContext->__packageId;
143 if (File::IsFileExist(filePath) == true)
145 AppLog("This is a preload app=[%ls]", filePath.GetPointer());
146 __pContext->__isPreloaded = true;
149 __pContext->__rootPath = pPackageInfoImpl->GetAppRootPath();
150 // if (__pContext->__rootPath.StartsWith(PATH_USR_APPS, 0) == true)
152 // __pContext->__isPreloaded = true;
155 if (__pContext->__isHybridService == true)
157 AppLog("Uninstallation for HybridService");
158 __state = STATE_DELETE_DIR;
162 if (pPackageInfoImpl->IsInstalledInExternalStorage() == true)
165 app2ext_handle* pHandle = null;
167 std::unique_ptr<char[]> pPackageId(_StringConverter::CopyToCharArrayN(packageId));
168 TryReturn(pPackageId, INSTALLER_ERROR_INTERNAL_STATE, "pAppId is null");
170 pHandle = app2ext_init(APP2EXT_SD_CARD);
171 TryReturn(pHandle, INSTALLER_ERROR_INTERNAL_STATE, "app2ext_init() failed");
173 res = pHandle->interface.pre_uninstall(pPackageId.get());
174 TryReturn(res == 0, INSTALLER_ERROR_INTERNAL_STATE, "pHandle->interface.pre_uninstall() failed [%d]", res);
176 __pContext->__pApp2ExtHandle = (void*)pHandle;
178 AppLog("[app2sd] pre_uninstall(%s)", pPackageId.get());
181 ArrayList* pList = pPackageInfoImpl->GetAppInfoListN();
182 TryReturn(pList, INSTALLER_ERROR_DATABASE, "pList is null.");
184 for (int i = 0; i < pList->GetCount(); i++)
186 _PackageAppInfoImpl* pAppInfoImpl = dynamic_cast<_PackageAppInfoImpl*>(pList->GetAt(i));
189 AppData* pAppData = new (std::nothrow) AppData;
190 TryReturn(pAppData, INSTALLER_ERROR_OUT_OF_MEMORY, "pAppData is null");
192 error = pAppData->Construct();
193 TryReturn(error == INSTALLER_ERROR_NONE, INSTALLER_ERROR_INTERNAL_STATE, "pAppData->Construct() failed.");
195 pAppData->__appId = pAppInfoImpl->GetPackageName();
196 pAppData->__feature = pAppInfoImpl->GetAppFeature();
198 __pContext->__pAppDataList->Add(pAppData);
203 __state = STATE_DELETE_DIR;
210 UninstallStep::OnStateCheckAppRunning(void)
212 InstallerError error = INSTALLER_ERROR_NONE;
219 UninstallStep::OnStateTerminateApp(void)
221 InstallerError error = INSTALLER_ERROR_NONE;
228 UninstallStep::OnStateStartTimer(void)
230 InstallerError error = INSTALLER_ERROR_NONE;
237 UninstallStep::OnStateRemoveDir(void)
239 InstallerError error = INSTALLER_ERROR_NONE;
242 rootPath = __pContext->__rootPath;
243 AppLog("rootPath = [%ls]", rootPath.GetPointer());
245 String compatPath(rootPath);
246 compatPath.Append(L"/info/compat.info");
247 bool ospCompat = File::IsFileExist(compatPath);
248 result r = GetLastResult();
249 if (r == E_SUCCESS && ospCompat == true)
251 if (_FileImpl::FinalizeDataCaging(rootPath) == false)
253 AppLog("[Tizen::Io] Failed to unmount directories for 2.0 application, appRootPath: %ls",
254 rootPath.GetPointer());
255 return INSTALLER_ERROR_UNMOUNT_FAILED;
258 else if (r != E_SUCCESS)
260 AppLog("[Tizen::Io] Failed to access %ls", compatPath.GetPointer());
261 return INSTALLER_ERROR_UNMOUNT_FAILED;
264 AppLog("Directory::Remove - START");
266 if (__pContext->__isHybridService == true)
268 AppLog("Uninstallation for HybridService - skip Remove");
274 if (InstallerUtil::IsSymlink(rootPath) == true)
276 if (InstallerUtil::GetRealPath(rootPath, realPath) == true)
278 InstallerUtil::Remove(realPath);
282 InstallerUtil::Remove(rootPath);
285 IListT<AppData*>* pAppDataList = __pContext->__pAppDataList;
286 TryReturn(pAppDataList, INSTALLER_ERROR_INTERNAL_STATE, "pAppDataList is null");
288 int count = pAppDataList->GetCount();
289 for (int i = 0; i < count; i++)
291 AppData* pAppData = null;
292 pAppDataList->GetAt(i, pAppData);
296 if (pAppData->__feature == CATEGORY_TYPE_IME)
299 symlinkPath.Format(1024, L"%s/%ls.so", IME_PATH, pAppData->__appId.GetPointer());
300 InstallerUtil::Remove(symlinkPath);
305 AppLog("Directory::Remove - END");
312 UninstallStep::OnStateDone(void)
314 InstallerError error = INSTALLER_ERROR_NONE;