From: Piotr Kosko/Native/Web API (PLT) /SRPOL/Professional/삼성전자
Date: Mon, 22 Jul 2019 09:21:02 +0000 (+0200)
Subject: [Application] Fixed path of getAppSharedURI
X-Git-Tag: accepted/tizen/4.0/unified/20200611.103152~14
X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F69%2F210569%2F1;p=platform%2Fcore%2Fapi%2Fwebapi-plugins.git
[Application] Fixed path of getAppSharedURI
Application should return path to the 'shared' directory which follows
the description of 'shared' directory content available here:
https://developer.tizen.org/development/training/native-application/understanding-tizen-programming/file-system-directory-hierarchy
New application returns the path like:
sh-3.2# ls -al /opt/usr/home/owner/apps_rw/org.example.basic/shared/
total 20
drwxr-xr-x 4 owner users 4096 Jul 18 13:06 .
drwxr-xr-x 5 owner users 4096 Jul 18 13:06 ..
drwxrwsr-x 2 owner system_share 4096 Jul 18 13:06 data
lrwxrwxrwx 1 app_fw app_fw 58 Jul 18 13:06 res -> /opt/usr/globalapps/org.example.basic/shared/res
drwxr-xr-x 2 owner users 4096 Jul 18 13:06 trusted
Instead of the previous result:
sh-3.2# ls -al /opt/usr/globalapps/org.example.basic/shared/
total 12
drwxr-xr-x 3 tizenglobalapp root 4096 Jul 18 13:06 .
drwxr-xr-x 6 tizenglobalapp root 4096 Jul 18 13:06 ..
drwxr-xr-x 2 tizenglobalapp root 4096 Jul 18 13:06 res
[Verification] Checked manually in chrome console
TCT Application 100% passrate
Change-Id: I0032c10bf2d98487117cd0049103767f9c7f1d09
---
diff --git a/src/application/application_manager.cc b/src/application/application_manager.cc
index 7f84698..69e2a55 100644
--- a/src/application/application_manager.cc
+++ b/src/application/application_manager.cc
@@ -16,6 +16,7 @@
#include "application_manager.h"
+#include
#include
#include
@@ -1107,42 +1108,45 @@ void ApplicationManager::GetAppCerts(const std::string& app_id, picojson::object
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 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::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);
}