Implement lightuser feature 87/274287/3
authorIlho Kim <ilho159.kim@samsung.com>
Tue, 26 Apr 2022 01:47:00 +0000 (10:47 +0900)
committerHwanKyu Jhun <h.jhun@samsung.com>
Wed, 27 Apr 2022 01:12:23 +0000 (01:12 +0000)
Apps that declared light user whose switch mode is not 'default'
should get appropriate directory of light user

Change-Id: I9818bfa4cab1be5acf7d1fec7fdec7d4fad3f3d7
Signed-off-by: Ilho Kim <ilho159.kim@samsung.com>
CMakeLists.txt
aul/app_info/app_info.cc
aul/app_info/app_info.hh
aul/app_info/directory_info.cc
packaging/aul.spec

index 53e701c..f2a12f3 100644 (file)
@@ -57,6 +57,7 @@ PKG_CHECK_MODULES(TTRACE_DEPS REQUIRED ttrace)
 PKG_CHECK_MODULES(UUID_DEPS REQUIRED uuid)
 PKG_CHECK_MODULES(VCONF_DEPS REQUIRED vconf)
 PKG_CHECK_MODULES(XDGMIME_DEPS REQUIRED xdgmime)
+PKG_CHECK_MODULES(LIBSESSIOND_DEPS REQUIRED libsessiond)
 
 ## Target sources
 AUX_SOURCE_DIRECTORY(src SRCS)
@@ -115,6 +116,7 @@ APPLY_PKG_CONFIG(${TARGET_AUL} PUBLIC
   UUID_DEPS
   VCONF_DEPS
   XDGMIME_DEPS
+  LIBSESSIOND_DEPS
 )
 
 INSTALL(TARGETS ${TARGET_AUL} DESTINATION ${LIB_INSTALL_DIR} COMPONENT RuntimeLibraries)
index fe3dd9e..493c5c1 100644 (file)
@@ -44,8 +44,14 @@ AppInfo::Builder& AppInfo::Builder::SetRootPath(std::string root_path) {
   return *this;
 }
 
+AppInfo::Builder& AppInfo::Builder::SetLightUserSwitchMode(std::string mode) {
+  light_user_switch_mode_ = std::move(mode);
+  return *this;
+}
+
 AppInfo::Builder::operator AppInfo*() const {
-  return new (std::nothrow) AppInfo(app_id_, pkg_id_, root_path_);
+  return new (std::nothrow) AppInfo(app_id_, pkg_id_,
+      root_path_, light_user_switch_mode_);
 }
 
 AppInfo* AppInfo::Get(const std::string& app_id, uid_t uid) {
@@ -75,7 +81,15 @@ AppInfo* AppInfo::Get(const std::string& app_id, uid_t uid) {
     return nullptr;
   }
 
-  return Builder().SetAppId(app_id).SetPkgId(pkg_id).SetRootPath(root_path);
+  char* mode;
+  ret = pkgmgrinfo_appinfo_get_light_user_switch_mode(handle, &mode);
+  if (ret != PMINFO_R_OK) {
+    _E("Failed to get light user switch mode. error(%d)", ret);
+    return nullptr;
+  }
+
+  return Builder().SetAppId(app_id).SetPkgId(pkg_id)
+      .SetRootPath(root_path).SetLightUserSwitchMode(mode);
 }
 
 AppInfo* AppInfo::Get(int pid) {
@@ -99,10 +113,12 @@ AppInfo* AppInfo::Get(int pid) {
   return Builder().SetAppId(app_id).SetPkgId(pkg_id).SetRootPath(root_path);
 }
 
-AppInfo::AppInfo(std::string app_id, std::string pkg_id, std::string root_path)
+AppInfo::AppInfo(std::string app_id, std::string pkg_id,
+    std::string root_path, std::string light_user_switch_mode)
     : app_id_(std::move(app_id)),
       pkg_id_(std::move(pkg_id)),
-      root_path_(std::move(root_path)) {
+      root_path_(std::move(root_path)),
+      light_user_switch_mode_(std::move(light_user_switch_mode)) {
 }
 
 const std::string& AppInfo::GetAppId() const {
@@ -117,4 +133,8 @@ const std::string& AppInfo::GetRootPath() const {
   return root_path_;
 }
 
+const std::string& AppInfo::GetLightUserSwitchMode() const {
+  return light_user_switch_mode_;
+}
+
 }  // namespace aul
index 3139487..1ee9a6e 100644 (file)
@@ -32,12 +32,14 @@ class AppInfo {
     Builder& SetAppId(std::string app_id);
     Builder& SetPkgId(std::string pkg_id);
     Builder& SetRootPath(std::string root_path);
+    Builder& SetLightUserSwitchMode(std::string mode);
     operator AppInfo*() const;
 
    private:
     std::string app_id_;
     std::string pkg_id_;
     std::string root_path_;
+    std::string light_user_switch_mode_;
   };
 
   static AppInfo* Get(const std::string& app_id, uid_t uid);
@@ -45,16 +47,19 @@ class AppInfo {
 
   AppInfo(std::string app_id,
       std::string pkg_id,
-      std::string root_path);
+      std::string root_path,
+      std::string light_user_switch_mode);
 
   const std::string& GetAppId() const;
   const std::string& GetPkgId() const;
   const std::string& GetRootPath() const;
+  const std::string& GetLightUserSwitchMode() const;
 
  private:
   std::string app_id_;
   std::string pkg_id_;
   std::string root_path_;
+  std::string light_user_switch_mode_;
 };
 
 }  // namespace aul
index 67346e6..d5932eb 100644 (file)
@@ -15,6 +15,7 @@
  *
  */
 
+#include <sessiond.h>
 #include <sys/types.h>
 #include <tzplatform_config.h>
 #include <unistd.h>
@@ -37,10 +38,49 @@ constexpr const char kTepResourceDir[] = "tep/mount/";
 constexpr const char kSharedDataDir[] = "shared/data/";
 constexpr const char kSharedTrustedDir[] = "shared/trusted/";
 constexpr const char kSharedResourceDir[] = "shared/res/";
-
-std::string GetRWPath(const std::string& pkg_id, uid_t uid) {
+constexpr const char kSubssesionDir[] = "subsessions/";
+constexpr const char kAppRWDir[] = "apps_rw/";
+constexpr const char kLightUserSwitchModeDefault[] = "default";
+
+std::string GetCurrentLightUser(uid_t uid) {
+  int user = 0;
+  int supported = 0;
+  int ret = subsession_is_supported(&supported);
+  if (ret != TIZEN_ERROR_NONE) {
+    _E("Failed to get subsession supported. error(%d)", ret);
+    return "";
+  }
+
+  if (!supported) {
+    _D("subsession is not supported");
+    return "";
+  }
+
+  ret = subsession_get_current_user(uid, &user);
+  if (ret != TIZEN_ERROR_NONE) {
+    _E("Failed to get subsession current user. error(%d)", ret);
+    return "";
+  }
+
+  return std::to_string(user);
+}
+
+std::string GetRWPath(const std::string& pkg_id,
+    const std::string& light_user_switch_mode, uid_t uid) {
+  std::string path;
   tzplatform_set_user(uid);
-  std::string path = std::string(tzplatform_getenv(TZ_USER_APP)) + "/" + pkg_id;
+
+  if (light_user_switch_mode != kLightUserSwitchModeDefault) {
+    std::string current_user = GetCurrentLightUser(uid);
+    if (!current_user.empty()) {
+      path = std::string(tzplatform_getenv(TZ_USER_HOME)) + "/" + kSubssesionDir
+          + current_user + "/" + kAppRWDir + pkg_id;
+    }
+  }
+
+  if (path.empty())
+    path = std::string(tzplatform_getenv(TZ_USER_APP)) + "/" + pkg_id;
+
   tzplatform_reset_user();
   return path;
 }
@@ -113,7 +153,8 @@ DirectoryInfo* DirectoryInfo::Get(const std::string app_id,
     return nullptr;
 
   std::string root_path = info->GetRootPath();
-  std::string rw_path = GetRWPath(info->GetPkgId(), uid);
+  std::string rw_path = GetRWPath(info->GetPkgId(),
+      info->GetLightUserSwitchMode(), uid);
   return Builder().SetRootPath(info->GetRootPath())
       .SetDataPath(GetPath(rw_path, kDataDir))
       .SetCachePath(GetPath(rw_path, kCacheDir))
index 9e69ddd..05cb72b 100644 (file)
@@ -37,6 +37,7 @@ BuildRequires:  pkgconfig(uuid)
 BuildRequires:  pkgconfig(libsmack)
 BuildRequires:  pkgconfig(gmock)
 BuildRequires:  pkgconfig(parcel)
+BuildRequires:  pkgconfig(libsessiond)
 
 %if 0%{?gcov:1}
 BuildRequires:  lcov