Support UID Sandbox feature 06/319606/7
authorJihoi Kim <jihoi.kim@samsung.com>
Thu, 13 Feb 2025 10:49:41 +0000 (19:49 +0900)
committerJihoi Kim <jihoi.kim@samsung.com>
Wed, 26 Feb 2025 02:03:13 +0000 (11:03 +0900)
- Retrieve app socket path using aul_sock api
- Change request builder to convert app uid into user uid
- Change app status manager to check each uid in request

Change-Id: I5155d592c48267be6edcd2f6444e06075beb9026
Signed-off-by: Jihoi Kim <jihoi.kim@samsung.com>
src/lib/amd_app_status.cc
src/lib/api/amd_api_app_request_broker.cc
src/lib/app_com/app_com_broker.cc
src/lib/app_status/app_status_manager.cc
src/lib/app_status/app_status_manager.hh
src/lib/launchpad/launchpad.cc
src/lib/request/request.cc

index 2c49c284f7a0436cecf1e6b296da67b0fa5c929b..bef2c36a781c0a0e89d808a08c8db608763dcf8c 100644 (file)
@@ -47,8 +47,10 @@ namespace fs = std::filesystem;
 std::string GetAppIdFromFile(pid_t pid, uid_t uid) {
   std::string appid;
   try {
-    fs::path path =
-        fs::path("/run/aul/apps") / std::to_string(uid) / std::to_string(pid);
+    char app_aul_path[AUL_SOCKET_PATH_MAX];
+    aul_sock_get_socket_directory(pid, uid, app_aul_path, AUL_SOCKET_PATH_MAX);
+
+    fs::path path = fs::path(app_aul_path);
     for (const auto& entry : fs::directory_iterator(path)) {
       if (entry.is_directory() || entry.path().filename().string()[0] == '.')
         continue;
index 22bb179e3cc198f9998089444d3ef6cea3348745..c1d1e28c3d81e68e44ae7d177c46dd99241aa07b 100644 (file)
@@ -37,8 +37,6 @@
 
 namespace {
 
-constexpr const char PATH_AUL_APPS[] = "/run/aul/apps";
-
 class ResultCb {
  public:
   class IEvent {
@@ -219,9 +217,11 @@ class AppRequestBroker {
   std::shared_ptr<ClientChannel> CreateClientChannel(pid_t pid, uid_t uid,
       bool once = false) {
     try {
+      char socket_path[AUL_SOCKET_PATH_MAX];
       auto client_channel = std::make_shared<ClientChannel>(pid, uid, once);
-      std::string endpoint = std::string(PATH_AUL_APPS) + "/" +
-          std::to_string(uid) + "/" + std::to_string(pid) + "/.app-sock";
+      aul_sock_get_socket_path(pid, uid, socket_path, AUL_SOCKET_PATH_MAX);
+      std::string endpoint(socket_path);
+
       client_channel->Connect(endpoint);
       client_channel->SetSendBufferSize(AUL_SOCK_MAXBUFF);
       client_channel->SetReceiveBufferSize(AUL_SOCK_MAXBUFF);
index 2ebbc3dfa40925cef133e868663947cd1a4c1bc4..a0a3584b3a8c9ab4dad4db78a1bceea093931b88 100644 (file)
 #include "lib/common/log_private.hh"
 
 namespace amd {
-namespace {
-
-constexpr const char PATH_AUL_APPS[] = "/run/aul/apps";
-constexpr const char PATH_AUL_DAEMONS[] = "/run/aul/daemons";
-
-std::string GetEndpoint(pid_t pid, uid_t uid) {
-  char path[108];
-  if (uid < REGULAR_UID_MIN) {
-    snprintf(path, sizeof(path), "%s/%u/.app-sock-%d",
-        PATH_AUL_DAEMONS, uid, pid);
-  } else {
-    snprintf(path, sizeof(path), "%s/%u/%d/.app-sock",
-        PATH_AUL_APPS, uid, pid);
-  }
-
-  return std::string(path);
-}
-
-}  // namespace
 
 AppComBroker::~AppComBroker() {
   if (!disposed_)
@@ -299,7 +280,10 @@ std::shared_ptr<AppComSocket> AppComBroker::CreateAppComSocket(pid_t pid,
     uid_t uid) {
   try {
     auto app_com_socket = std::make_shared<AppComSocket>(pid, uid, this);
-    std::string endpoint = GetEndpoint(pid, uid);
+
+    char appsock_path[AUL_SOCKET_PATH_MAX];
+    aul_sock_get_socket_path(pid, uid, appsock_path, AUL_SOCKET_PATH_MAX);
+    std::string endpoint(appsock_path);
 
     // NOTE: If a directory in endpoint path has 700 permission, access() fail.
     std::filesystem::path path(endpoint);
index 5fec7d00429b0230a4c18a128993902cc7a71d9d..4752271f284356fd336b207f91f1e52853b11f04 100644 (file)
@@ -62,6 +62,15 @@ namespace {
 
 constexpr const char PATH_AUL_APPS[] = "/run/aul/apps/";
 
+uid_t GetAppUserUidByUid(uid_t uid) {
+  constexpr uid_t REGULAR_APP_UID_MIN = 10000;
+  static const uid_t DEFAULT_USER_ID = tzplatform_getuid(TZ_SYS_DEFAULT_USER);
+
+  if(uid >= REGULAR_APP_UID_MIN) return DEFAULT_USER_ID;
+
+  return uid;
+}
+
 pid_t ProcGetPPIDByPID(pid_t pid) {
   std::string path = "/proc/" + std::to_string(pid) + "/status";
   std::ifstream is;
@@ -110,11 +119,14 @@ tizen_base::Bundle CreateAppStatusBundle(const AppStatusPtr& app_status) {
   return b;
 }
 
-void DeleteSocketPath(pid_t pid, uid_t uid) {
-  std::string path =
-      PATH_AUL_APPS + std::to_string(uid) + "/" + std::to_string(pid);
-  if (_util_unlink(path.c_str()) != 0)
-    _W("Failed to delete socket path(%s)", path.c_str());
+void DeleteSocketDirectory(pid_t pid, uid_t uid) {
+  char socket_dir[AUL_SOCKET_PATH_MAX];
+  aul_sock_get_socket_directory(pid, uid, socket_dir, AUL_SOCKET_PATH_MAX);
+
+  if (_util_unlink(socket_dir) != 0)
+    _W("Failed to delete socket path(%s)", socket_dir);
+
+  return;
 }
 
 bool InotifySocketMonitorCallback(const char* event_name, void* data) {
@@ -296,7 +308,8 @@ AppStatusPtr AppStatusManager::Find(pid_t pid) const {
 
 AppStatusPtr AppStatusManager::FindByAppID(const std::string& appid,
     uid_t uid) const {
-  auto it = appid_map_.find({uid, appid});
+  uid_t app_user_uid = GetAppUserUidByUid(uid);
+  auto it = appid_map_.find({app_user_uid, appid});
   if (it == appid_map_.end())
     return nullptr;
 
@@ -305,9 +318,10 @@ AppStatusPtr AppStatusManager::FindByAppID(const std::string& appid,
 
 AppStatusPtr AppStatusManager::FindByAppIDv2(const std::string& appid,
     uid_t uid) const {
+  uid_t app_user_uid = GetAppUserUidByUid(uid);
   auto it = std::find_if(app_status_list_.begin(), app_status_list_.end(),
       [&](const AppStatusPtr& app_status) -> bool {
-        return app_status->GetUID() == uid && app_status->GetAppID() == appid;
+        return app_status->GetUID() == app_user_uid && app_status->GetAppID() == appid;
       });
   if (it == app_status_list_.end())
     return nullptr;
@@ -317,9 +331,10 @@ AppStatusPtr AppStatusManager::FindByAppIDv2(const std::string& appid,
 
 AppStatusPtr AppStatusManager::FindWithOriginalCaller(const std::string& appid,
     uid_t uid, pid_t caller_pid) const {
+  uid_t app_user_uid = GetAppUserUidByUid(uid);
   auto it = std::find_if(app_status_list_.begin(), app_status_list_.end(),
       [&](const AppStatusPtr& app_status) -> bool {
-        return app_status->GetUID() == uid &&
+        return app_status->GetUID() == app_user_uid &&
             app_status->GetOriginalCallerPID() == caller_pid &&
             app_status->GetAppID() == appid;
       });
@@ -345,7 +360,7 @@ void AppStatusManager::FindServiceApp(AppStatus* app_status, int status,
     return;
   }
 
-  uid_t uid = app_status->GetUID();
+  uid_t app_user_uid = app_status->GetUID();
   auto it = pkg_status_map_.find(app_status->GetPackageID());
   if (it == pkg_status_map_.end()) {
     _E("Not found package status (%s)", app_status->GetPackageID().c_str());
@@ -354,13 +369,13 @@ void AppStatusManager::FindServiceApp(AppStatus* app_status, int status,
 
   auto& pkg_status = it->second;
   for (auto& app_status : pkg_status->GetServiceAppList()) {
-    if (app_status->GetUID() == uid) {
+    if (app_status->GetUID() == app_user_uid) {
       auto* app_info = app_status->GetAppInfo();
       bool bg_allowed = _suspend_is_allowed_background(
           static_cast<appinfo_h>(const_cast<AppInfo*>(app_info)));
       bool excluded = _suspend_is_excluded(app_status->GetPID());
       if (!excluded && !bg_allowed) {
-        send_event_to_svc_core(app_status->GetPID(), uid);
+        send_event_to_svc_core(app_status->GetPID(), app_user_uid);
         if (app_status->GetStatus() != STATUS_DYING && suspend)
           _suspend_add_timer(app_status->GetPID());
         else
@@ -416,8 +431,11 @@ int AppStatusManager::SendRunningAppStatus(const AppStatusPtr& app_status,
 
 int AppStatusManager::SendRunningAppinfo(int fd, int cmd, uid_t uid) {
   std::vector<tizen_base::Bundle> result;
+  uid_t app_user_uid = GetAppUserUidByUid(uid);
+
   for (auto& app_status : app_status_list_) {
-    if (app_status->GetUID() != uid || app_status->GetStatus() == STATUS_DYING)
+    if (app_status->GetUID() != app_user_uid
+        || app_status->GetStatus() == STATUS_DYING)
       continue;
     if (cmd != APP_ALL_RUNNING_INFO && cmd != APP_RUNNING_INSTANCE_INFO &&
         (app_status->GetAppType() == AT_UI_APP && app_status->IsSubapp()))
@@ -447,8 +465,9 @@ int AppStatusManager::ForeachRunningAppinfo(ForeachCb callback, void* data) {
 }
 
 int AppStatusManager::TerminateApps(const std::string& appid, uid_t uid) {
+  uid_t app_user_uid = GetAppUserUidByUid(uid);
   for (auto& app_status : app_status_list_) {
-    if (app_status->GetUID() == uid &&
+    if (app_status->GetUID() == app_user_uid &&
         app_status->GetStatus() != STATUS_DYING &&
         app_status->GetAppID() == appid) {
       int ret = _terminate_app_local(app_status->GetUID(),
@@ -463,8 +482,9 @@ int AppStatusManager::TerminateApps(const std::string& appid, uid_t uid) {
 
 int AppStatusManager::TerminateAppsByPkgId(const std::string& pkgid,
     uid_t uid) {
+  uid_t app_user_uid = GetAppUserUidByUid(uid);
   for (auto& app_status : app_status_list_) {
-    if (app_status->GetUID() == uid &&
+    if (app_status->GetUID() == app_user_uid &&
         app_status->GetStatus() != STATUS_DYING &&
         app_status->GetPackageID() == pkgid) {
       int ret = _terminate_app_local(app_status->GetUID(),
@@ -472,7 +492,7 @@ int AppStatusManager::TerminateAppsByPkgId(const std::string& pkgid,
       if (ret < 0)
         _E("Failed to terminate app_status(%d)", app_status->GetPID());
 
-      DeleteSocketPath(app_status->GetPID(), app_status->GetUID());
+      DeleteSocketDirectory(app_status->GetPID(), app_status->GetUID());
     }
   }
 
@@ -481,6 +501,7 @@ int AppStatusManager::TerminateAppsByPkgId(const std::string& pkgid,
 
 int AppStatusManager::TerminateAppsByResPackageID(const std::string& pkgid,
     uid_t uid) {
+  uid_t app_user_uid = GetAppUserUidByUid(uid);
   auto NeedToKillByResPackage = [&](const AppStatusPtr& app_status) -> bool {
     auto* res_package_table = static_cast<GHashTable*>(
         app_status->GetExtraData(APP_STATUS_RES_PACKAGE));
@@ -495,7 +516,7 @@ int AppStatusManager::TerminateAppsByResPackageID(const std::string& pkgid,
   };
 
   for (auto& app_status : app_status_list_) {
-    if (app_status->GetUID() == uid &&
+    if (app_status->GetUID() == app_user_uid &&
         app_status->GetStatus() != STATUS_DYING &&
         NeedToKillByResPackage(app_status)) {
       int ret = _terminate_app_local(app_status->GetUID(),
@@ -503,7 +524,7 @@ int AppStatusManager::TerminateAppsByResPackageID(const std::string& pkgid,
       if (ret < 0)
         _E("Failed to terminate app_status(%d)", app_status->GetPID());
 
-      DeleteSocketPath(app_status->GetPID(), app_status->GetUID());
+      DeleteSocketDirectory(app_status->GetPID(), app_status->GetUID());
     }
   }
 
@@ -511,8 +532,10 @@ int AppStatusManager::TerminateAppsByResPackageID(const std::string& pkgid,
 }
 
 int AppStatusManager::KillAppsByPkgId(const std::string& pkgid, uid_t uid) {
+  uid_t app_user_uid = GetAppUserUidByUid(uid);
   for (auto& app_status : app_status_list_) {
-    if (app_status->GetUID() == uid && app_status->GetPackageID() == pkgid) {
+    if (app_status->GetUID() == app_user_uid &&
+        app_status->GetPackageID() == pkgid) {
       int ret = _launch_send_sigkill(app_status->GetPID(),
           app_status->GetUID());
       if (ret < 0) {
@@ -521,7 +544,7 @@ int AppStatusManager::KillAppsByPkgId(const std::string& pkgid, uid_t uid) {
       }
 
       Update(app_status, STATUS_DYING, false, true);
-      DeleteSocketPath(app_status->GetPID(), app_status->GetUID());
+      DeleteSocketDirectory(app_status->GetPID(), app_status->GetUID());
     }
   }
 
@@ -535,12 +558,13 @@ int AppStatusManager::PublishStatus(int pid, int context_status) {
     return -1;
 
   auto& appid = app_status->GetAppID();
-  uid_t uid = app_status->GetUID();
+  uid_t app_user_uid = app_status->GetUID();
 
   std::string endpoint_user = APP_STATUS_EVENT + ":" + appid + ":" +
-      std::to_string(uid);
+      std::to_string(app_user_uid);
   std::string endpoint_system = APP_STATUS_EVENT + ":" + appid;
-  std::string endpoint_user2 = APP_STATUS_EVENT + ":" + std::to_string(uid);
+  std::string endpoint_user2 = APP_STATUS_EVENT + ":"+
+      std::to_string(app_user_uid);
   std::string endpoint_system2 = APP_STATUS_EVENT;
 
   bool endpoint_user_exists = _app_com_endpoint_exists(endpoint_user.c_str());
@@ -556,13 +580,13 @@ int AppStatusManager::PublishStatus(int pid, int context_status) {
   auto b = CreateAppStatusBundle(app_status);
   b.Add("__CONTEXT_STATUS__", std::to_string(context_status));
   if (endpoint_system_exists)
-    _app_com_send(endpoint_system.c_str(), pid, b.GetHandle(), uid);
+    _app_com_send(endpoint_system.c_str(), pid, b.GetHandle(), app_user_uid);
   if (endpoint_user_exists)
-    _app_com_send(endpoint_user.c_str(), pid, b.GetHandle(), uid);
+    _app_com_send(endpoint_user.c_str(), pid, b.GetHandle(), app_user_uid);
   if (endpoint_system2_exists)
-    _app_com_send(endpoint_system2.c_str(), pid, b.GetHandle(), uid);
+    _app_com_send(endpoint_system2.c_str(), pid, b.GetHandle(), app_user_uid);
   if (endpoint_user2_exists)
-    _app_com_send(endpoint_user2.c_str(), pid, b.GetHandle(), uid);
+    _app_com_send(endpoint_user2.c_str(), pid, b.GetHandle(), app_user_uid);
 
   return 0;
 }
@@ -598,6 +622,12 @@ void AppStatusManager::CleanUp(AppStatusPtr app_status) {
 }
 
 int AppStatusManager::UserInit(uid_t uid) {
+  constexpr uid_t REGULAR_APP_UID_MIN = 10000;
+  if(uid >= REGULAR_APP_UID_MIN) {
+    _E("UID %d cannot be user", uid);
+    return 0;
+  }
+
   auto it = wd_map_.find(uid);
   if (it != wd_map_.end()) {
     _D("Already exists. uid(%u)", uid);
@@ -606,7 +636,7 @@ int AppStatusManager::UserInit(uid_t uid) {
 
   LoadAppStatusFromDB(uid);
 
-  std::string path = PATH_AUL_APPS + std::to_string(uid);
+  std::string path = PATH_AUL_APPS;
   if (access(path.c_str(), F_OK) == 0) {
     auto* handle = amd_inotify_add_watch(path.c_str(), IN_CREATE,
         InotifySocketMonitorCallback, nullptr);
@@ -643,18 +673,19 @@ void AppStatusManager::UserFinish(uid_t uid) {
 
 int AppStatusManager::RegisterPID(int pid, const std::string& appid,
     uid_t uid, int caller_pid, unsigned int req_id) {
-  auto app_info = AppInfoManager::GetInst().FindAppInfo(uid, appid);
+  uid_t app_user_uid = GetAppUserUidByUid(uid);
+  auto app_info = AppInfoManager::GetInst().FindAppInfo(app_user_uid, appid);
   if (app_info == nullptr) {
-    _E("Failed to find appinfo. %s:%u", appid.c_str(), uid);
+    _E("Failed to find appinfo. %s:%u of %u", appid.c_str(), uid, app_user_uid);
     return -1;
   }
 
-  if (_login_monitor_get_launchpad_pid(uid) != caller_pid) {
+  if (_login_monitor_get_launchpad_pid(app_user_uid) != caller_pid) {
     if (VerifyAppProcess(pid, app_info->GetPkgId()) < 0)
       return -1;
   }
 
-  auto app_status = FindByAppID(appid, uid);
+  auto app_status = FindByAppID(appid, app_user_uid);
   if (app_status != nullptr && app_status->IsRunning()) {
     _W("status info is already exist: %s", appid.c_str());
     if (app_status->GetPID() == pid)
@@ -679,7 +710,7 @@ int AppStatusManager::RegisterPID(int pid, const std::string& appid,
   builder.SetAppId(app_info->GetAppId());
   builder.SetAppInfo(app_info);
   builder.SetPid(pid);
-  builder.SetUid(uid);
+  builder.SetUid(app_user_uid);
   builder.SetCallerPid(getpid());
   builder.SetEventListener(this);
 
@@ -847,8 +878,10 @@ void AppStatusManager::Insert(AppStatusPtr app_status) {
   app_status_list_.push_back(app_status);
   pid_map_[app_status->GetPID()] = app_status;
 
-  if (CheckMainApp(app_status))
-    appid_map_[{app_status->GetUID(), app_status->GetAppID()}] = app_status;
+  if (CheckMainApp(app_status)) {
+    uid_t app_user_uid = app_status->GetUID();
+    appid_map_[{app_user_uid, app_status->GetAppID()}] = app_status;
+  }
 
   if (!app_status->GetInstanceID().empty())
     instance_map_[app_status->GetInstanceID()] = app_status;
@@ -1154,39 +1187,6 @@ void AppStatusManager::SetRequestBrokerDisconnectedEventCb() {
       this);
 }
 
-int AppStatusManager::AddInotifyWatch() {
-  watch_handle_ = amd_inotify_add_watch(
-      PATH_AUL_APPS, IN_CREATE,
-      [](const char* event_name, void* data) -> bool {
-        if (event_name == nullptr) return true;
-
-        uid_t uid = strtol(event_name, NULL, 10);
-        auto it = GetInst().wd_map_.find(uid);
-        if (it == GetInst().wd_map_.end()) {
-          std::string path = PATH_AUL_APPS + std::to_string(uid);
-          auto handle = amd_inotify_add_watch(
-              path.c_str(), IN_CREATE, InotifySocketMonitorCallback, nullptr);
-          if (handle == nullptr) {
-            _E("Failed to add a watch - uid(%d)", uid);
-            return true;
-          }
-
-          GetInst().wd_map_[uid] =
-              std::shared_ptr<std::remove_pointer_t<amd_inotify_watch_info_h>>(
-                  handle, amd_inotify_rm_watch);
-        }
-
-        return true;
-      },
-      nullptr);
-  if (watch_handle_ == nullptr) {
-    _E("Failed to add watch(%s)", PATH_AUL_APPS);
-    return -1;
-  }
-
-  return 0;
-}
-
 void AppStatusManager::AddVconfInitTimer() {
   vconf_timer_ = g_timeout_add(
       500,
@@ -1208,7 +1208,6 @@ void AppStatusManager::AddVconfInitTimer() {
 int AppStatusManager::Init() {
   AddSignalReadyCb();
   SetRequestBrokerDisconnectedEventCb();
-  if (AddInotifyWatch() != 0) return -1;
 
   AddVconfInitTimer();
   _noti_listen(AMD_NOTI_MSG_LAUNCH_PREPARE_END, OnLaunchPrepareEnd);
index 5a459306e49a58ad8b9ac122f289055f020fdc65..9f585d7101aab0a0df87d6d2e3948ed80237aa62 100644 (file)
@@ -121,7 +121,6 @@ class AppStatusManager : public AppStatus::IEvent, public Launchpad::IEvent {
 
   void AddSignalReadyCb();
   void SetRequestBrokerDisconnectedEventCb();
-  int AddInotifyWatch();
   void AddVconfInitTimer();
 
   static int OnLaunchPrepareEnd(const char *msg, pid_t pid, int uid,
index e8a985ca8c4414e1a9e46b13114fce38b7ed25e3..402bf9803146b081afff3a675ac7bc97f7a023e3 100644 (file)
@@ -55,9 +55,9 @@ class GarbageCollector : public Worker::Job {
   void Do() override {
     _D("pid=%d, appid=%s", pid_, appid_.c_str());
     try {
-      std::string path =
-          "/run/aul/apps/" + std::to_string(uid_) + "/" + std::to_string(pid_);
-      DeleteSocketPath(fs::path(path));
+      char dir_path[AUL_SOCKET_PATH_MAX];
+      aul_sock_get_socket_directory(pid_, uid_, dir_path, AUL_SOCKET_PATH_MAX);
+      DeleteDirectory(fs::path(dir_path));
 
       DeleteUnusedFiles();
       SocketGarbadgeCollector();
@@ -71,7 +71,7 @@ class GarbageCollector : public Worker::Job {
   }
 
  private:
-  void DeleteSocketPath(const fs::path& path) {
+  void DeleteDirectory(const fs::path& path) {
     try {
       fs::remove_all(path);
     } catch (const fs::filesystem_error& e) {
@@ -80,12 +80,12 @@ class GarbageCollector : public Worker::Job {
   }
 
   void SocketGarbadgeCollector() {
-    std::string path = "/run/aul/apps/" + std::to_string(uid_);
+    std::string path = "/run/aul/apps/";
     for (const auto& entry : fs::directory_iterator(path)) {
       if (!isdigit(entry.path().filename().string()[0])) continue;
 
       std::string proc_path = "/proc/" + entry.path().filename().string();
-      if (!fs::exists(proc_path)) DeleteSocketPath(entry.path());
+      if (!fs::exists(proc_path)) DeleteDirectory(entry.path());
     }
   }
 
index fdea5a044b9e508226bde79fa48a049ee964f65d..eba1dbed34cd9748ae70945a06fe75f5fadbacf8 100644 (file)
 #include "lib/request/common.hh"
 
 namespace amd {
+namespace {
+
+uid_t GetAppUserUidByUid(uid_t uid) {
+  constexpr uid_t REGULAR_APP_UID_MIN = 10000;
+  static const uid_t DEFAULT_USER_ID = tzplatform_getuid(TZ_SYS_DEFAULT_USER);
+
+  if(uid >= REGULAR_APP_UID_MIN)
+    return DEFAULT_USER_ID;
+  else
+    return uid;
+}
+
+}
 
 unsigned int Request::GenerateRequestID() {
   static unsigned int id;
@@ -51,7 +64,10 @@ Request::Builder& Request::Builder::SetTargetPID(pid_t pid) {
 }
 
 Request::Builder& Request::Builder::SetUID(uid_t uid) {
-  uid_ = uid;
+  uid_ = GetAppUserUidByUid(uid);
+  if(uid_ != uid) {
+    _W("Request caller uid %d(app) changed to %d(user)", uid, uid_);
+  }
   return *this;
 }
 
@@ -182,7 +198,10 @@ uid_t Request::GetTargetUID() const {
 }
 
 void Request::SetTargetUID(uid_t uid) {
-  target_uid_ = uid;
+  target_uid_ = GetAppUserUidByUid(uid);
+  if(target_uid_ != uid) {
+    _W("Request target uid %d(app) changed to %d(user)", uid, target_uid_);
+  }
 }
 
 int Request::GetClientFD() const {