Fix coding style and warnings 20/63020/3
authorTomasz Iwanek <t.iwanek@samsung.com>
Mon, 21 Mar 2016 12:45:24 +0000 (13:45 +0100)
committerTomasz Iwanek <t.iwanek@samsung.com>
Tue, 5 Apr 2016 09:26:20 +0000 (11:26 +0200)
To verify, run smoke tests.

Change-Id: I8385063372281fe26d67a558bf2f54e48394de3b

12 files changed:
src/common/app_installer.cc
src/common/pkgmgr_interface.cc
src/common/pkgmgr_interface.h
src/common/security_registration.cc
src/common/shared_dirs.cc
src/common/shared_dirs.h
src/common/step/filesystem/step_create_per_user_storage_directories.cc
src/common/step/pkgmgr/step_kill_apps.cc
src/common/step/rds/step_rds_modify.h
src/common/step/rds/step_rds_parse.h
src/pkgdir_tool/pkgdir_tool.cc
src/unit_tests/signature_unittest.cc

index 34fb6ea..5d58c66 100644 (file)
@@ -25,13 +25,10 @@ AppInstaller::AppInstaller(const char* package_type, PkgMgrPtr pkgmgr)
   context_->pkg_type.set(package_type);
   context_->installation_mode.set(pkgmgr->GetInstallationMode());
 
-  if (pkgmgr->ShouldCreateSignal()) {
-    if (context_->installation_mode.get() == InstallationMode::ONLINE) {
-      // pkgmgr signal should work only for online mode
-      // there is no one to receive it in offline mode
-      pi_.reset(new PkgmgrSignal(pkgmgr.get()->GetRawPi(),
-                                 pkgmgr->GetRequestType()));
-    }
+  // pkgmgr signal should work only for online mode
+  // there is no one to receive it in offline mode
+  if (context_->installation_mode.get() == InstallationMode::ONLINE) {
+    pi_ = pkgmgr->CreatePkgmgrSignal();
   }
 }
 
index 925eb53..4bdeea8 100644 (file)
@@ -14,6 +14,7 @@
 #include <fstream>
 
 #include "common/app_query_interface.h"
+#include "common/pkgmgr_signal.h"
 
 namespace bf = boost::filesystem;
 
@@ -154,6 +155,12 @@ bool PkgMgrInterface::GetIsPreloadRequest() {
       true:false;
 }
 
+std::unique_ptr<PkgmgrSignal> PkgMgrInterface::CreatePkgmgrSignal() const {
+  if (!pkgmgr_installer_interface_->ShouldCreateSignal())
+    return nullptr;
+  return std::unique_ptr<PkgmgrSignal>(new PkgmgrSignal(pi_, GetRequestType()));
+}
+
 bool PkgMgrInterface::GetIsForceRemoval() {
   // root only
   return (getuid() == 0 && pkgmgr_installer_get_force_removal(pi_) == 1);
index 8da3a5c..cb91c54 100644 (file)
@@ -21,6 +21,7 @@ enum class InstallationMode {
   OFFLINE
 };
 
+class PkgmgrSignal;
 class PkgMgrInterface;
 typedef std::shared_ptr<PkgMgrInterface> PkgMgrPtr;
 
@@ -49,8 +50,8 @@ class PkgmgrInstallerInterface {
 class PkgmgrInstaller : public PkgmgrInstallerInterface {
  public:
   bool CreatePkgMgrInstaller(pkgmgr_installer** installer,
-                             InstallationMode* mode);
-  bool ShouldCreateSignal() const;
+                             InstallationMode* mode) override;
+  bool ShouldCreateSignal() const override;
 };
 
 /**
@@ -132,14 +133,11 @@ class PkgMgrInterface {
   InstallationMode GetInstallationMode() const { return install_mode_; }
 
   /**
-   * @brief ShouldCreateSignal
+   * @brief CreatePkgmgrSignal
    *
-   *
-   * @return true if pkgmgr signal should be created
+   * @return creates pkgmgr signal
    */
-  bool ShouldCreateSignal() const {
-    return pkgmgr_installer_interface_->ShouldCreateSignal();
-  }
+  std::unique_ptr<PkgmgrSignal> CreatePkgmgrSignal() const;
 
   /** PkgMgrInstance destructor. */
   ~PkgMgrInterface();
index f24bcb0..4834ff4 100644 (file)
@@ -97,7 +97,7 @@ bool PrepareRequest(const std::string& app_id, const std::string& pkg_id,
   }
 
   if (sec_install_type != ci::SecurityAppInstallType::None) {
-    app_install_type type;
+    app_install_type type = SM_APP_INSTALL_NONE;
 
     switch (sec_install_type) {
       case ci::SecurityAppInstallType::Local:
@@ -109,6 +109,10 @@ bool PrepareRequest(const std::string& app_id, const std::string& pkg_id,
       case ci::SecurityAppInstallType::Global:
         type = SM_APP_INSTALL_GLOBAL;
         break;
+      case ci::SecurityAppInstallType::None:
+        break;
+      default:
+        break;
     }
 
     LOG(INFO) << "install_type(" << type << ")";
index b5202c1..9f3880a 100644 (file)
@@ -195,7 +195,6 @@ bool SetPackageDirectoryOwnerAndPermissions(const bf::path& subpath, uid_t uid,
 
 bool CreateDirectories(const bf::path& app_dir, const std::string& pkgid,
                        const std::string& author_id,
-                       const std::string& api_version,
                        uid_t uid, gid_t gid, const bool set_permissions) {
   bf::path base_dir = app_dir / pkgid;
   if (bf::exists(base_dir)) {
@@ -241,7 +240,7 @@ bf::path GetDirectoryPathForStorage(uid_t user, std::string apps_prefix) {
 }
 
 bool CreateUserDirectories(uid_t user, const std::string& pkgid,
-    const std::string& author_id, const std::string& api_version,
+    const std::string& author_id,
     const std::string& apps_prefix, const bool set_permissions) {
 
   struct passwd* pwd = getpwuid(user);  // NOLINT
@@ -258,7 +257,7 @@ bool CreateUserDirectories(uid_t user, const std::string& pkgid,
              << pwd->pw_gid;
 
   bf::path apps_rw = GetDirectoryPathForStorage(user, apps_prefix);
-  if (!CreateDirectories(apps_rw, pkgid, author_id, api_version,
+  if (!CreateDirectories(apps_rw, pkgid, author_id,
       pwd->pw_uid, pwd->pw_gid, set_permissions)) {
     return false;
   }
@@ -382,11 +381,10 @@ std::string GetDirectoryPathForExternalStorage() {
 
 bool PerformInternalDirectoryCreationForUser(uid_t user,
                                              const std::string& pkgid,
-                                             const std::string& author_id,
-                                             const std::string& api_version) {
+                                             const std::string& author_id) {
   const char* internal_storage_prefix = tzplatform_getenv(TZ_SYS_HOME);
   const bool set_permissions = true;
-  if (!CreateUserDirectories(user, pkgid, author_id, api_version,
+  if (!CreateUserDirectories(user, pkgid, author_id,
                              internal_storage_prefix, set_permissions))
     return false;
   return true;
@@ -394,8 +392,7 @@ bool PerformInternalDirectoryCreationForUser(uid_t user,
 
 bool PerformExternalDirectoryCreationForUser(uid_t user,
                                              const std::string& pkgid,
-                                             const std::string& author_id,
-                                             const std::string& api_version) {
+                                             const std::string& author_id) {
   const char* storage_path = tzplatform_mkpath(TZ_SYS_MEDIA,
                                                kExternalStorageDirPrefix);
   const bool set_permissions = false;
@@ -404,15 +401,14 @@ bool PerformExternalDirectoryCreationForUser(uid_t user,
     return false;
   }
 
-  if (CreateUserDirectories(user, pkgid, author_id, api_version,
+  if (CreateUserDirectories(user, pkgid, author_id,
                             storage_path, set_permissions)) {
   }
   return true;
 }
 
 bool PerformInternalDirectoryCreationForAllUsers(const std::string& pkgid,
-                                                 const std::string& author_id,
-                                                 const std::string& api_ver) {
+                                                 const std::string& author_id) {
   for (bf::directory_iterator iter(tzplatform_getenv(TZ_SYS_HOME));
       iter != bf::directory_iterator();
          ++iter) {
@@ -431,8 +427,7 @@ bool PerformInternalDirectoryCreationForAllUsers(const std::string& pkgid,
 
     if (!PerformInternalDirectoryCreationForUser(pwd->pw_uid,
                                                  pkgid,
-                                                 author_id,
-                                                 api_ver))
+                                                 author_id))
       LOG(ERROR) << "Could not create internal storage directories for user: "
         << user.c_str();
   }
@@ -440,12 +435,10 @@ bool PerformInternalDirectoryCreationForAllUsers(const std::string& pkgid,
 }
 
 bool PerformExternalDirectoryCreationForAllUsers(const std::string& pkgid,
-                                                 const std::string& author_id,
-                                                 const std::string& api_ver) {
+                                                 const std::string& author_id) {
   for (bf::directory_iterator iter(tzplatform_getenv(TZ_SYS_HOME));
       iter != bf::directory_iterator();
          ++iter) {
-
     try {
       if (!bf::is_directory(iter->path())) continue;
     }
@@ -466,8 +459,7 @@ bool PerformExternalDirectoryCreationForAllUsers(const std::string& pkgid,
 
     if (!PerformExternalDirectoryCreationForUser(pwd->pw_uid,
                                                  pkgid,
-                                                 author_id,
-                                                 api_ver))
+                                                 author_id))
       LOG(WARNING) << "Could not create external storage directories for user: "
         << user.c_str();
   }
index 6cdd803..7904c1f 100644 (file)
@@ -30,7 +30,6 @@ using PkgList = std::vector<PkgInfo>;
  *
  * \param pkgid id of package
  * \param author_id id of author
- * \param api_version api version
  * \param create_skel_directories flag
  *
  * \return true if succeed, false otherwise
@@ -38,15 +37,13 @@ using PkgList = std::vector<PkgInfo>;
  */
 bool PerformInternalDirectoryCreationForUser(uid_t uid,
                                              const std::string& pkgid,
-                                             const std::string& author_id,
-                                             const std::string& api_version);
+                                             const std::string& author_id);
 
 /**
  * \brief Performs a creation of directories for specific user in external storage
  *
  * \param pkgid id of package
  * \param author_id id of author
- * \param api_version api version
  * \param create_skel_directories flag
  *
  * \return true if succeed, false otherwise
@@ -54,38 +51,33 @@ bool PerformInternalDirectoryCreationForUser(uid_t uid,
  */
 bool PerformExternalDirectoryCreationForUser(uid_t uid,
                                              const std::string& pkgid,
-                                             const std::string& author_id,
-                                             const std::string& api_version);
+                                             const std::string& author_id);
 
 /**
  * \brief Performs a creation of directories in internal storage
  *
  * \param pkgid id of package
  * \param author_id id of author
- * \param api_version api version
  * \param create_skel_directories flag
  *
  * \return true if succeed, false otherwise
  *
  */
 bool PerformInternalDirectoryCreationForAllUsers(const std::string& pkgid,
-                                                 const std::string& author_id,
-                                                 const std::string& apiversion);
+                                                 const std::string& author_id);
 
 /**
  * \brief Performs a creation of directories in external storage (eg. SD card)
  *
  * \param pkgid id of package
  * \param author_id id of author
- * \param api_version api version
  * \param create_skel_directories flag
  *
  * \return true if succeed, false otherwise
  *
  */
 bool PerformExternalDirectoryCreationForAllUsers(const std::string& pkgid,
-                                                 const std::string& author_id,
-                                                 const std::string& apiversion);
+                                                 const std::string& author_id);
 
 /**
  * \brief Performs deletion of directories
index 268d602..327a051 100644 (file)
@@ -61,17 +61,15 @@ bool StepCreatePerUserStorageDirectories::CreateExternalStorageDir() {
       case RequestMode::GLOBAL: {
         LOG(DEBUG) << "Creating external directories for all users";
         PerformExternalDirectoryCreationForAllUsers(pkg.pkg_id,
-                                                         pkg.author_id,
-                                                         pkg.api_version);
+                                                    pkg.author_id);
       }
       break;
       case RequestMode::USER: {
         LOG(DEBUG) << "Creating external directories for user: "
             << context_->uid.get();
         PerformExternalDirectoryCreationForUser(context_->uid.get(),
-                                                     pkg.pkg_id,
-                                                     pkg.author_id,
-                                                     pkg.api_version);
+                                                pkg.pkg_id,
+                                                pkg.author_id);
       }
       break;
     }
index 53a00db..2eca3ae 100644 (file)
@@ -6,9 +6,9 @@
 
 #include <app_manager.h>
 #include <app_manager_extension.h>
+#include <sys/time.h>
 
 #include <string>
-#include <sys/time.h>
 
 #include "common/utils/glist_range.h"
 
@@ -47,7 +47,7 @@ bool KillApp(const std::string& appid) {
       LOG(DEBUG) << "kill waiting count (" << i << ")";
       break;
     }
-    usleep(100000); // 100msec
+    usleep(100000);  // 100msec
     if (i == 10)
       LOG(ERROR) << "kill timeout";
   }
index 8c42b8c..26e3581 100644 (file)
@@ -2,8 +2,8 @@
 // Use of this source code is governed by a apache 2.0 license that can be
 // found in the LICENSE file.
 
-#ifndef COMMON_RDS_STEP_RDS_MODIFY_H_
-#define COMMON_RDS_STEP_RDS_MODIFY_H_
+#ifndef COMMON_STEP_RDS_STEP_RDS_MODIFY_H_
+#define COMMON_STEP_RDS_STEP_RDS_MODIFY_H_
 
 #include <boost/filesystem.hpp>
 #include <common/step/step.h>
@@ -93,4 +93,4 @@ class StepRDSModify : public Step {
 }  // namespace rds
 }  // namespace common_installer
 
-#endif  // COMMON_RDS_STEP_RDS_MODIFY_H_
+#endif  // COMMON_STEP_RDS_STEP_RDS_MODIFY_H_
index d60774d..8bbdf49 100644 (file)
@@ -2,8 +2,8 @@
 // Use of this source code is governed by a apache 2.0 license that can be
 // found in the LICENSE file.
 
-#ifndef COMMON_RDS_STEP_RDS_PARSE_H_
-#define COMMON_RDS_STEP_RDS_PARSE_H_
+#ifndef COMMON_STEP_RDS_STEP_RDS_PARSE_H_
+#define COMMON_STEP_RDS_STEP_RDS_PARSE_H_
 
 #include <common/step/step.h>
 
@@ -52,4 +52,4 @@ class StepRDSParse : public Step {
 }  // namespace rds
 }  // namespace common_installer
 
-#endif  // COMMON_RDS_STEP_RDS_PARSE_H_
+#endif  // COMMON_STEP_RDS_STEP_RDS_PARSE_H_
index 6f28ca4..55aed4a 100644 (file)
@@ -134,14 +134,12 @@ int main(int argc, char** argv) {
 
   auto dir_operation = ParseDirectoryOptions(opt_map);
   auto pkgs = GetPackageListFromArgs(opt_map);
-  auto create_skel_dirs = true;
 
   for (auto& p : pkgs) {
     switch (dir_operation) {
       case DirectoryOperation::CREATE_INTERNAL: {
         LOG(DEBUG) << "Running directory creation for package id: " << p.pkg_id;
         ci::PerformInternalDirectoryCreationForAllUsers(p.pkg_id,
-                                                        p.api_version,
                                                         p.author_id);
         const std::string pkg_path = ci::GetDirectoryPathForInternalStorage();
         ci::SetPackageDirectorySmackRulesForAllUsers(pkg_path,
index cdc21ed..68df0eb 100644 (file)
@@ -26,8 +26,8 @@ TEST_F(SignatureValidatorTest, HandlesInitializedSignatureDir) {
   PrivilegeLevel level = PrivilegeLevel::UNTRUSTED;
   common_installer::CertificateInfo cert_info;
   std::string error;
-  EXPECT_EQ(ValidateSignatures(*signature_file, &level, &cert_info, true, &error),
-            Step::Status::OK);
+  EXPECT_EQ(ValidateSignatures(*signature_file, &level, &cert_info, true,
+                               &error), Step::Status::OK);
 }
 
 // Tests signature verifier with signature directory containing bad signatures
@@ -37,8 +37,8 @@ TEST_F(SignatureValidatorTest, HandlesBadSignatureDir) {
   PrivilegeLevel level = PrivilegeLevel::UNTRUSTED;
   common_installer::CertificateInfo cert_info;
   std::string error;
-  EXPECT_EQ(ValidateSignatures(*signature_file, &level, &cert_info, true, &error),
-            Step::Status::ERROR);
+  EXPECT_EQ(ValidateSignatures(*signature_file, &level, &cert_info, true,
+                               &error), Step::Status::ERROR);
 }
 
 }  // namespace security