Fix StepRecoverApplication 27/167327/3
authorSangyoon Jang <jeremy.jang@samsung.com>
Wed, 17 Jan 2018 05:38:59 +0000 (14:38 +0900)
committerSangyoon Jang <jeremy.jang@samsung.com>
Wed, 17 Jan 2018 08:45:07 +0000 (08:45 +0000)
When recover updated preloaded package, some attributes should be set
properly.

Change-Id: Id189bb3a238036cae812d8ba9cc933cbb8a021af
Signed-off-by: Sangyoon Jang <jeremy.jang@samsung.com>
src/common/step/pkgmgr/step_recover_application.cc
src/common/step/pkgmgr/step_recover_application.h

index 48e8226..9b14d53 100644 (file)
@@ -7,6 +7,7 @@
 #include <boost/filesystem.hpp>
 
 #include "common/paths.h"
+#include "common/pkgmgr_query.h"
 #include "common/pkgmgr_registration.h"
 
 namespace bf = boost::filesystem;
@@ -17,15 +18,7 @@ namespace pkgmgr {
 Step::Status StepRecoverApplication::RecoveryNew() {
   if (!SetXmlPaths())
     return Status::OK;
-  if (context_->manifest_data.get())
-    UnregisterAppInPkgmgr(context_->manifest_data.get(),
-                          context_->pkgid.get(),
-                          context_->uid.get(),
-                          context_->request_mode.get());
-  else
-    UnregisterAppInPkgmgrForPkgId(context_->pkgid.get(),
-                                  context_->uid.get(),
-                                  context_->request_mode.get());
+  UnregisterApplication();
   return Status::OK;
 }
 
@@ -34,17 +27,11 @@ Step::Status StepRecoverApplication::RecoveryUpdate() {
     LOG(ERROR) << "Some parameters are lacking";
     return Status::ERROR;
   }
-  UnregisterAppInPkgmgr(context_->manifest_data.get(),
-                        context_->pkgid.get(),
-                        context_->uid.get(),
-                        context_->request_mode.get());
-  if (!RegisterAppInPkgmgr(context_->manifest_data.get(),
-                           context_->pkgid.get(),
-                           context_->certificate_info.get(),
-                           context_->uid.get(),
-                           context_->storage.get(),
-                           context_->request_mode.get(),
-                           context_->tep_path.get())) {
+  PkgQueryInterface pkg_query(context_->pkgid.get(), context_->uid.get());
+  if (pkg_query.IsUpdatedPackage())
+    SetExtraAttributes(true);
+  UnregisterApplication();
+  if (!RegisterApplication()) {
     LOG(ERROR) << "Unsuccessful app registration";
     return Status::RECOVERY_ERROR;
   }
@@ -52,17 +39,17 @@ Step::Status StepRecoverApplication::RecoveryUpdate() {
 }
 
 Step::Status StepRecoverApplication::RecoveryReadonlyUpdateInstall() {
-  // Hmm... this is just-work solution...
-  manifest_x* manifest_data = context_->manifest_data.get();
-  free(manifest_data->system);
-  manifest_data->system = strdup("true");
-  free(manifest_data->preload);
-  manifest_data->preload = strdup("true");
-  free(manifest_data->readonly);
-  manifest_data->readonly = strdup("true");
-  free(manifest_data->removable);
-  manifest_data->removable = strdup("false");
-  return RecoveryUpdate();
+  if (!SetXmlPaths()) {
+    LOG(ERROR) << "Some parameters are lacking";
+    return Status::ERROR;
+  }
+  SetExtraAttributes(false);
+  UnregisterApplication();
+  if (!RegisterApplication()) {
+    LOG(ERROR) << "Unsuccessful app registration";
+    return Status::RECOVERY_ERROR;
+  }
+  return Status::OK;
 }
 
 bool StepRecoverApplication::SetXmlPaths() {
@@ -78,5 +65,41 @@ bool StepRecoverApplication::SetXmlPaths() {
   return true;
 }
 
+void StepRecoverApplication::SetExtraAttributes(bool is_updated) {
+  manifest_x* manifest_data = context_->manifest_data.get();
+  free(manifest_data->system);
+  manifest_data->system = strdup("true");
+  free(manifest_data->preload);
+  manifest_data->preload = strdup("true");
+  free(manifest_data->update);
+  manifest_data->update = strdup(is_updated ? "true" : "false");
+  free(manifest_data->readonly);
+  manifest_data->readonly = strdup(is_updated ? "false" : "true");
+  free(manifest_data->removable);
+  manifest_data->removable = strdup(is_updated ? "true" : "false");
+}
+
+bool StepRecoverApplication::UnregisterApplication() {
+  if (context_->manifest_data.get())
+    return UnregisterAppInPkgmgr(context_->manifest_data.get(),
+                                 context_->pkgid.get(),
+                                 context_->uid.get(),
+                                 context_->request_mode.get());
+  else
+    return UnregisterAppInPkgmgrForPkgId(context_->pkgid.get(),
+                                         context_->uid.get(),
+                                         context_->request_mode.get());
+}
+
+bool StepRecoverApplication::RegisterApplication() {
+  return RegisterAppInPkgmgr(context_->manifest_data.get(),
+                             context_->pkgid.get(),
+                             context_->certificate_info.get(),
+                             context_->uid.get(),
+                             context_->storage.get(),
+                             context_->request_mode.get(),
+                             context_->tep_path.get());
+}
+
 }  // namespace pkgmgr
 }  // namespace common_installer
index 23e678b..d9cc7fb 100644 (file)
@@ -29,6 +29,9 @@ class StepRecoverApplication : public recovery::StepRecovery {
 
  private:
   bool SetXmlPaths();
+  void SetExtraAttributes(bool is_updated);
+  bool UnregisterApplication();
+  bool RegisterApplication();
 
   STEP_NAME(RecoverApplication)
 };