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;
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) {
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;
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;
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;
});
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());
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
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()))
}
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(),
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(),
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());
}
}
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));
};
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(),
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());
}
}
}
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) {
}
Update(app_status, STATUS_DYING, false, true);
- DeleteSocketPath(app_status->GetPID(), app_status->GetUID());
+ DeleteSocketDirectory(app_status->GetPID(), app_status->GetUID());
}
}
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());
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;
}
}
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);
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);
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)
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);
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;
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,
int AppStatusManager::Init() {
AddSignalReadyCb();
SetRequestBrokerDisconnectedEventCb();
- if (AddInotifyWatch() != 0) return -1;
AddVconfInitTimer();
_noti_listen(AMD_NOTI_MSG_LAUNCH_PREPARE_END, OnLaunchPrepareEnd);