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_POLICY_CHECK:
70 AppLog("[STATE_POLICY_CHECK]");
71 error = OnStatePolicyCheck();
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)
123 result r = E_SUCCESS;
124 InstallerError error = INSTALLER_ERROR_NONE;
125 PackageId packageId = __pContext->__packageId;
127 std::unique_ptr< _PackageInfoImpl > pPackageInfoImpl(new (std::nothrow) _PackageInfoImpl());
128 TryReturn(pPackageInfoImpl, INSTALLER_ERROR_OUT_OF_MEMORY, "pPackageInfoImpl is null.");
130 AppLog("package = %ls", packageId.GetPointer());
132 r = pPackageInfoImpl->Construct(packageId);
133 TryReturn(r == E_SUCCESS, INSTALLER_ERROR_INTERNAL_STATE, "pPackageInfoImpl->Construct(%ls) failed.", packageId.GetPointer());
135 // bool isUninstallable = pPackageInfoImpl->IsUninstallable();
136 // if (isUninstallable == false)
138 // __pContext->__additionalErrorString = L"Thrown when the application cannot be uninstalled because the application was preloaded.";
140 // TryReturn(isUninstallable == true, INSTALLER_ERROR_PACKAGE_INVALID, "preload app cannot be uninstalled.");
143 rwXmlPath.Format(1024, DIR_RW_PACKAGE_SYSTEM_MANIFEST, packageId.GetPointer());
144 if (File::IsFileExist(rwXmlPath) == false)
146 AppLog("This is a preload app = [%ls]", rwXmlPath.GetPointer());
147 __pContext->__isPreloaded = true;
150 //res = IsAvailableUninstall();
151 //TryReturn(res == true, INSTALLER_ERROR_DISABLED, "IsAvailableUninstall(%ls) failed.", packageId.GetPointer());
153 __pContext->__rootPath = pPackageInfoImpl->GetAppRootPath();
155 if (pPackageInfoImpl->IsInstalledInExternalStorage() == true)
158 app2ext_handle* pHandle = null;
160 std::unique_ptr<char[]> pPackageId(_StringConverter::CopyToCharArrayN(packageId));
161 TryReturn(pPackageId, INSTALLER_ERROR_INTERNAL_STATE, "pAppId is null");
163 pHandle = app2ext_init(APP2EXT_SD_CARD);
164 TryReturn(pHandle, INSTALLER_ERROR_INTERNAL_STATE, "app2ext_init() failed");
166 res = pHandle->interface.pre_uninstall(pPackageId.get());
167 TryReturn(res == 0, INSTALLER_ERROR_INTERNAL_STATE, "pHandle->interface.pre_uninstall() failed [%d]", res);
169 __pContext->__pApp2ExtHandle = (void*)pHandle;
171 AppLog("[app2sd] pre_uninstall(%s)", pPackageId.get());
174 std::unique_ptr< ArrayList > pList(pPackageInfoImpl->GetAppInfoListN());
175 TryReturn(pList, INSTALLER_ERROR_DATABASE, "pList is null.");
177 for (int i = 0; i < pList.get()->GetCount(); i++)
179 _PackageAppInfoImpl* pAppInfoImpl = dynamic_cast<_PackageAppInfoImpl*>(pList.get()->GetAt(i));
182 std::unique_ptr< AppData > pAppData(new (std::nothrow) AppData);
183 TryReturn(pAppData, INSTALLER_ERROR_OUT_OF_MEMORY, "pAppData is null.");
185 error = pAppData.get()->Construct();
186 TryReturn(error == INSTALLER_ERROR_NONE, INSTALLER_ERROR_INTERNAL_STATE, "pAppData.get()->Construct() failed.");
188 pAppData.get()->__appId = pAppInfoImpl->GetPackageName();
189 pAppData.get()->__feature = pAppInfoImpl->GetAppFeature();
191 __pContext->__pAppDataList->Add(pAppData.release());
200 UninstallStep::OnStatePolicyCheck(void)
202 InstallerError error = INSTALLER_ERROR_NONE;
209 UninstallStep::OnStateTerminateApp(void)
211 InstallerError error = INSTALLER_ERROR_NONE;
213 InstallerUtil::TerminateApps(__pContext->__packageId, true);
220 UninstallStep::OnStateStartTimer(void)
222 InstallerError error = INSTALLER_ERROR_NONE;
229 UninstallStep::OnStateRemoveDir(void)
231 InstallerError error = INSTALLER_ERROR_NONE;
234 CompatibilityManager compatibilityManager;
235 compatibilityManager.Construct(__pContext);
238 rootPath = __pContext->__rootPath;
239 AppLog("rootPath = [%ls]", rootPath.GetPointer());
241 String compatPath(rootPath);
242 compatPath.Append(L"/info/compat.info");
243 bool ospCompat = File::IsFileExist(compatPath);
244 result r = GetLastResult();
245 if (r == E_SUCCESS && ospCompat == true)
247 if (compatibilityManager.FinalizeDataCaging(rootPath) == false)
249 AppLog("[Tizen::Io] Failed to unmount directories for 2.0 application, appRootPath: %ls",
250 rootPath.GetPointer());
251 return INSTALLER_ERROR_UNMOUNT_FAILED;
254 else if (r != E_SUCCESS)
256 AppLog("[Tizen::Io] Failed to access %ls", compatPath.GetPointer());
257 return INSTALLER_ERROR_UNMOUNT_FAILED;
260 compatibilityManager.CleanDirectories(rootPath, __pContext->__packageId);
263 String virtualRootInfoFile = rootPath + VIRTUAL_ROOT_INFO_FILE;
264 if (File::IsFileExist(virtualRootInfoFile) == true)
266 res = compatibilityManager.FinalizeVirtualRoot(rootPath, __pContext->__packageId);
267 TryReturn(res == true, INSTALLER_ERROR_UNMOUNT_FAILED, "compatibilityManager.FinalizeVirtualRoot(%ls) failed.", rootPath.GetPointer());
270 AppLog("Directory::Remove - START");
273 if (InstallerUtil::IsSymlink(rootPath) == true)
275 if (InstallerUtil::GetRealPath(rootPath, realPath) == true)
277 InstallerUtil::Remove(realPath);
281 InstallerUtil::Remove(rootPath);
284 IListT<AppData*>* pAppDataList = __pContext->__pAppDataList;
285 TryReturn(pAppDataList, INSTALLER_ERROR_INTERNAL_STATE, "pAppDataList is null");
287 int count = pAppDataList->GetCount();
288 for (int i = 0; i < count; i++)
290 AppData* pAppData = null;
291 pAppDataList->GetAt(i, pAppData);
295 if (pAppData->__feature == CATEGORY_TYPE_IME)
298 symlinkPath.Format(1024, L"%s/%ls.so", IME_PATH, pAppData->__appId.GetPointer());
299 InstallerUtil::Remove(symlinkPath);
304 AppLog("Directory::Remove - END");
311 UninstallStep::OnStateDone(void)
313 InstallerError error = INSTALLER_ERROR_NONE;