Skip the security registration if it is unnecessary
[platform/core/appfw/app-installers.git] / src / common / step / security / step_recover_security.cc
index 1a2ff5f..ae59eaa 100644 (file)
@@ -13,9 +13,9 @@ namespace common_installer {
 namespace security {
 
 bool StepRecoverSecurity::Check(bool is_update) {
-  if (context_->pkg_path.get().empty())
+  if (context_->GetPkgPath().empty())
     return false;
-  if (!boost::filesystem::exists(context_->pkg_path.get()) && is_update)
+  if (!boost::filesystem::exists(context_->GetPkgPath()) && is_update)
     return false;
   if (context_->pkgid.get().empty())
     return false;
@@ -25,10 +25,16 @@ bool StepRecoverSecurity::Check(bool is_update) {
 Step::Status StepRecoverSecurity::RecoveryNew() {
   if (!Check(false))
     return Status::OK;
+  recovery::RecoveryFile* recovery_file =
+      context_->recovery_info.get().recovery_file.get();
+  if (!recovery_file->security_operation_done()) {
+    LOG(DEBUG) << "security_operation_done false skip recover security";
+    return Status::OK;
+  }
   std::string error_message;
   if (!context_->manifest_data.get()) {
     if (!UnregisterSecurityContextForPkgId(context_->pkgid.get(),
-        context_->uid.get(), &error_message, true)) {
+        context_->pkg_type.get(), context_->uid.get(), &error_message, true)) {
       LOG(ERROR) << "Unsuccessful install";
       if (!error_message.empty()) {
         LOG(ERROR) << "error_message: " << error_message;
@@ -37,7 +43,7 @@ Step::Status StepRecoverSecurity::RecoveryNew() {
       return Status::RECOVERY_ERROR;
     }
   } else if (!UnregisterSecurityContextForManifest(
-      context_->pkgid.get(), context_->uid.get(),
+      context_->pkgid.get(), context_->pkg_type.get(), context_->uid.get(),
       context_->manifest_data.get(), &error_message)) {
     LOG(ERROR) << "Unsuccessful install";
     if (!error_message.empty()) {
@@ -54,11 +60,14 @@ Step::Status StepRecoverSecurity::RecoveryUpdate() {
     LOG(ERROR) << "Invalid parameters";
     return Status::INVALID_VALUE;
   }
+  recovery::RecoveryFile* recovery_file =
+      context_->recovery_info.get().recovery_file.get();
+  if (!recovery_file->security_operation_done()) {
+    LOG(DEBUG) << "security_operation_done false skip recover security";
+    return Status::OK;
+  }
   std::string error_message;
-  if (!RegisterSecurityContextForManifest(
-      context_->pkgid.get(), context_->pkg_path.get(), context_->uid.get(),
-      &context_->certificate_info.get(), context_->manifest_data.get(),
-      context_->cross_app_rules.get(), &error_message)) {
+  if (!RegisterSecurityContextForManifest(context_, &error_message)) {
     LOG(ERROR) << "Unsuccessful update";
     if (!error_message.empty()) {
       LOG(ERROR) << "error_message: " << error_message;
@@ -67,11 +76,34 @@ Step::Status StepRecoverSecurity::RecoveryUpdate() {
     return Status::RECOVERY_ERROR;
   }
   if (!RegisterSecurityContextForPath(
-      context_->pkgid.get(), context_->pkg_path.get(), context_->uid.get(),
+      context_->pkgid.get(), context_->GetPkgPath(), context_->uid.get(),
       context_->is_readonly_package.get(), &error_message)) {
     if (!error_message.empty()) {
       LOG(ERROR) << "error_message: " << error_message;
-      on_error(Status::SECURITY_ERROR, error_message);
+      on_error(Status::RECOVERY_ERROR, error_message);
+    }
+    return Status::RECOVERY_ERROR;
+  }
+  return Status::OK;
+}
+
+Step::Status StepRecoverSecurity::RecoveryReadonlyUpdateInstall() {
+  if (!Check(false)) {
+    LOG(ERROR) << "Invalid parameters";
+    return Status::INVALID_VALUE;
+  }
+  recovery::RecoveryFile* recovery_file =
+      context_->recovery_info.get().recovery_file.get();
+  if (!recovery_file->security_operation_done()) {
+    LOG(DEBUG) << "security_operation_done false skip recover security";
+    return Status::OK;
+  }
+  std::string error_message;
+  if (!RegisterSecurityContextForManifest(context_, &error_message)) {
+    LOG(ERROR) << "Unsuccessful update";
+    if (!error_message.empty()) {
+      LOG(ERROR) << "error_message: " << error_message;
+      on_error(Status::RECOVERY_ERROR, error_message);
     }
     return Status::RECOVERY_ERROR;
   }