#include "application_manager.h"
#include <glib.h>
+#include <sys/stat.h>
#include <unistd.h>
#include <type_traits>
void ApplicationManager::GetAppSharedUri(const std::string& app_id, picojson::object* out) {
ScopeLogger();
+ // this implementation assumes that shared/trusted path is the obligatory member of application
+ // and it is used to extract the parent directory 'shared'
+ char* path = nullptr;
+ int ret = app_manager_get_shared_trusted_path(app_id.c_str(), &path);
+ if (APP_MANAGER_ERROR_NONE != ret) {
+ // if the application does not exist, there is no need to check "res" directory
+ if (APP_MANAGER_ERROR_NO_SUCH_APP == ret) {
+ LogAndReportError(PlatformResult(ErrorCode::NOT_FOUND_ERR, "Failed to get shared URI."), out);
+ return;
+ }
- char* package_id = nullptr;
-
- package_id = GetPackageId(app_id);
- // automatically release the memory
- std::unique_ptr<char, void (*)(void*)> package_id_ptr(package_id, &std::free);
-
- if (!package_id) {
- LogAndReportError(PlatformResult(ErrorCode::NOT_FOUND_ERR, "Failed to get package."), out);
- return;
+ // if the shared_trusted directory is not properly returned, gathering the shared/res path,
+ // which is the obligatory member. The global path could be different then:
+ // e.g. instead of path: /opt/usr/home/owner/apps_rw/org.example.basic/shared/
+ // returned path is: /opt/usr/globalapps/org.example.basic/shared/
+ LoggerW(
+ "app_manager_get_shared_trusted_path failed(), trying "
+ "app_manager_get_shared_resource_path() to gather path");
+ int ret = app_manager_get_shared_resource_path(app_id.c_str(), &path);
+ if (APP_MANAGER_ERROR_NONE != ret) {
+ LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, "Failed to get shared URI."), out);
+ return;
+ }
}
- pkgmgrinfo_pkginfo_h pkg_info = nullptr;
-
- int ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(package_id, getuid(), &pkg_info);
- std::unique_ptr<std::remove_pointer<pkgmgrinfo_pkginfo_h>::type, int (*)(pkgmgrinfo_pkginfo_h)>
- pkg_info_ptr(pkg_info,
- &pkgmgrinfo_pkginfo_destroy_pkginfo); // automatically release the memory
-
- if (PMINFO_R_OK != ret) {
- LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, "Failed to get package info."), out,
- ("Failed to get package info: %d (%s)", ret, get_error_message(ret)));
- return;
- }
+ std::string path_str = path;
+ free(path);
- char* root_path = nullptr;
- ret = pkgmgrinfo_pkginfo_get_root_path(pkg_info, &root_path);
+ std::string shared_path = path_str.substr(0, path_str.rfind("/", path_str.length() - 2));
- if (PMINFO_R_OK != ret || nullptr == root_path) {
- LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, "Failed to get root path."), out,
- ("Failed to get root path: %d (%s)", ret, get_error_message(ret)));
+ // checking if path is valid
+ struct stat stat_res;
+ if (0 != stat(shared_path.c_str(), &stat_res)) {
+ LoggerW("Path %s does not exist", shared_path.c_str());
+ LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, "Failed to get shared URI."), out);
return;
}
- picojson::value result = picojson::value(kTizenApisFileScheme + root_path + kTizenApisAppSlash +
- kTizenApisAppShared + kTizenApisAppSlash);
+ picojson::value result = picojson::value(kTizenApisFileScheme + shared_path);
ReportSuccess(result, *out);
}