--- /dev/null
+// Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef COMMON_APP_QUERY_INTERFACE_H_
+#define COMMON_APP_QUERY_INTERFACE_H_
+
+namespace common_installer {
+
+class AppQueryInterface {
+ public:
+ virtual ~AppQueryInterface() { }
+ virtual bool IsAppInstalledByArgv(int argc, char** argv) = 0;
+};
+
+} // namespace common_installer
+
+#endif // COMMON_APP_QUERY_INTERFACE_H_
#include <memory>
+#include "common/app_query_interface.h"
+
namespace common_installer {
PkgMgrPtr PkgMgrInterface::instance_;
return instance_;
}
-int PkgMgrInterface::Init(int argc, char** argv) {
+int PkgMgrInterface::Init(int argc, char** argv, AppQueryInterface* interface) {
if (instance_)
return 0;
- PkgMgrPtr tmp(new PkgMgrInterface());
+ PkgMgrPtr tmp(new PkgMgrInterface(interface));
int result = tmp->InitInternal(argc, argv);
instance_ = tmp;
LOG(ERROR) << "Cannot receive request. Invalid arguments?";
// no need to free pkgmgr_installer here. it will be freed in DTOR.
}
+
+ is_app_installed_ = false;
+ if (query_interface_)
+ is_app_installed_ = query_interface_->IsAppInstalledByArgv(argc, argv);
+
return result;
}
PkgMgrInterface::Type PkgMgrInterface::GetRequestType() const {
switch (pkgmgr_installer_get_request_type(pi_)) {
case PKGMGR_REQ_INSTALL:
- return PkgMgrInterface::Type::Install;
- case PKGMGR_REQ_UPGRADE:
- return PkgMgrInterface::Type::Update;
+ if (!is_app_installed_) {
+ return PkgMgrInterface::Type::Install;
+ } else {
+ return PkgMgrInterface::Type::Update;
+ }
case PKGMGR_REQ_UNINSTALL:
return PkgMgrInterface::Type::Uninstall;
case PKGMGR_REQ_REINSTALL:
#include <memory>
+#include "common/app_query_interface.h"
#include "utils/macros.h"
#include "utils/logging.h"
/** Initialize PkgMgrInterface.
*/
- static int Init(int argc, char** argv);
+ static int Init(int argc, char** argv,
+ AppQueryInterface* interface = nullptr);
/** Get Raw pointer to pkgmgr_installer object
*
~PkgMgrInterface();
private:
- PkgMgrInterface() :pi_(nullptr) {}
+ explicit PkgMgrInterface(AppQueryInterface* interface)
+ : pi_(nullptr),
+ query_interface_(interface) {}
int InitInternal(int argc, char** argv);
pkgmgr_installer* pi_;
+ bool is_app_installed_;
+ AppQueryInterface* query_interface_;
static PkgMgrPtr instance_;
SCOPE_LOG_TAG(PkgMgrInterface)
SET(SRCS
step/step_create_symbolic_link.cc
step/step_parse.cc
- update_workaround.cc
+ wgt_app_query_interface.cc
wgt_backend.cc
wgt_backend_data.cc
)
+++ /dev/null
-// Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
-// Use of this source code is governed by an apache 2.0 license that can be
-// found in the LICENSE file.
-
-#ifndef WGT_UPDATE_WORKAROUND_H_
-#define WGT_UPDATE_WORKAROUND_H_
-
-namespace workaround {
-
-void OverwriteArgvIfNeeded(int argc, char** argv);
-
-} // namespace workaround
-
-#endif // WGT_UPDATE_WORKAROUND_H_
// Use of this source code is governed by an apache 2.0 license that can be
// found in the LICENSE file.
-#include "wgt/update_workaround.h"
+#include "wgt/wgt_app_query_interface.h"
#include <unistd.h>
#include <sys/types.h>
namespace {
-std::pair<std::string, int> GetInstallationPackagePath(int argc, char** argv) {
- int index = -1;
+std::string GetInstallationPackagePath(int argc, char** argv) {
std::string path;
- for (unsigned i = 0; i < argc; ++i) {
+ for (int i = 0; i < argc; ++i) {
if (!strcmp(argv[i], "-i")) {
- index = i;
if (i + 1 < argc) {
path = argv[i + 1];
+ break;
}
- break;
}
}
- return std::make_pair(path, index);
+ return path;
}
std::string GetAppIdFromPath(const std::string& path) {
return true;
}
-void OverwriteArgvForUpdate(int index, char** argv) {
- // overwriting argv to fake update
- argv[index][1] = 'a';
-}
-
} // namespace
-namespace workaround {
+namespace wgt {
-void OverwriteArgvIfNeeded(int argc, char** argv) {
- std::string path;
- int index;
- std::tie(path, index) =
- GetInstallationPackagePath(argc, argv);
+bool WgtAppQueryInterface::IsAppInstalledByArgv(int argc, char** argv) {
+ std::string path = GetInstallationPackagePath(argc, argv);
if (path.empty()) {
// not the installaton
- return;
+ return false;
}
std::string pkg_id = GetAppIdFromPath(path);
if (pkg_id.empty())
- return;
- bool should_hack = IsPackageInstalled(pkg_id);
- if (should_hack) {
- LOG(INFO) << "Update detected - hacking argv to update installation";
- OverwriteArgvForUpdate(index, argv);
- }
+ return false;
+ return IsPackageInstalled(pkg_id);
}
-} // namespace workaround
+} // namespace wgt
--- /dev/null
+// Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by an apache 2.0 license that can be
+// found in the LICENSE file.
+
+#ifndef WGT_WGT_APP_QUERY_INTERFACE_H_
+#define WGT_WGT_APP_QUERY_INTERFACE_H_
+
+#include "common/app_query_interface.h"
+
+namespace wgt {
+
+class WgtAppQueryInterface : public common_installer::AppQueryInterface {
+ public:
+ bool IsAppInstalledByArgv(int argc, char** argv) override;
+};
+
+} // namespace wgt
+
+#endif // WGT_WGT_APP_QUERY_INTERFACE_H_
#include "common/step/step_update_app.h"
#include "common/step/step_update_security.h"
-#include "wgt/update_workaround.h"
-
#include "wgt/step/step_create_symbolic_link.h"
#include "wgt/step/step_parse.h"
+#include "wgt/wgt_app_query_interface.h"
namespace ci = common_installer;
int main(int argc, char** argv) {
- // TODO(t.iwanek): remove this when update installation detection is ready
- workaround::OverwriteArgvIfNeeded(argc, argv);
-
- int result = ci::PkgMgrInterface::Init(argc, argv);
+ wgt::WgtAppQueryInterface query_interface;
+ int result = ci::PkgMgrInterface::Init(argc, argv, &query_interface);
if (result) {
LOG(ERROR) << "Cannot connect to PkgMgrInstaller";
return -result;