return 0;
}
+static bool __need_to_kill_by_res_pkg(struct app_status_s *app_status,
+ const char *pkgid)
+{
+ GHashTable *res_pkg_tbl = _app_status_get_extra(
+ app_status, APP_STATUS_RES_PACKAGE);
+ const char *auto_close;
+
+ if (!res_pkg_tbl)
+ return false;
+
+ if (!g_hash_table_contains(res_pkg_tbl, pkgid))
+ return false;
+
+ auto_close = (const char *)g_hash_table_lookup(res_pkg_tbl, pkgid);
+ if (auto_close && !strcmp(auto_close, "true"))
+ return true;
+
+ return false;
+}
+
+int _app_status_terminate_apps_by_res_pkgid(const char *pkgid, uid_t uid)
+{
+ GSList *iter;
+ struct app_status_s *app_status;
+ int ret;
+
+ if (pkgid == NULL)
+ return -1;
+
+ for (iter = app_status_list; iter; iter = g_slist_next(iter)) {
+ app_status = (struct app_status_s *)iter->data;
+ if (app_status->uid == uid &&
+ app_status->status != STATUS_DYING &&
+ __need_to_kill_by_res_pkg(app_status, pkgid)) {
+ ret = _terminate_app_local(app_status->uid,
+ app_status->pid);
+ if (ret < 0) {
+ _E("Failed to terminate app(%d)",
+ app_status->pid);
+ }
+
+ _app_status_update_status(app_status, STATUS_DYING,
+ false, true);
+ __delete_socket_path(app_status->pid, app_status->uid);
+ }
+ }
+
+ return 0;
+}
+
int _app_status_get_appid_bypid(int fd, int pid)
{
int cmd = APP_GET_INFO_ERROR;
extern "C" {
#endif
+#define APP_STATUS_RES_PACKAGE "res_package"
+
typedef enum {
AT_SERVICE_APP,
AT_UI_APP,
int _app_status_terminate_apps_by_pkgid(const char *pkgid, uid_t uid);
+int _app_status_terminate_apps_by_res_pkgid(const char *pkgid, uid_t uid);
+
int _app_status_get_appid_bypid(int fd, int pid);
int _app_status_get_pkgid_bypid(int fd, int pid);
#include <vector>
#include <tuple>
+#include "lib/amd_app_status.h"
#include "lib/amd_login_monitor.h"
#include "lib/amd_noti.h"
#include "lib/amd_res_info.h"
continue;
res_pkginfo->SetBlocking();
+ _app_status_terminate_apps_by_res_pkgid(pkgid, uids[i]);
}
free(uids);
return NOTI_CONTINUE;
return NOTI_CONTINUE;
res_pkginfo->SetBlocking();
+ _app_status_terminate_apps_by_res_pkgid(pkgid, uid);
return NOTI_CONTINUE;
}
return NOTI_CONTINUE;
}
+static int __on_app_status_add(const char* msg, int arg1, int arg2,
+ void* arg3, bundle* b) {
+ app_status_h app_status = (app_status_h)arg3;
+ const char* appid = _app_status_get_appid(app_status);
+ uid_t uid = _app_status_get_uid(app_status);
+ std::shared_ptr<ResAppInfo> res_appinfo =
+ ResInfoManager::GetInst().GetUserResAppInfo(appid, uid);
+ if (!res_appinfo)
+ return NOTI_CONTINUE;
+
+ GHashTable* res_pkg_tbl = g_hash_table_new_full(g_str_hash,
+ g_str_equal, free, free);
+ if (!res_pkg_tbl) {
+ _E("Out of memory");
+ return NOTI_CONTINUE;
+ }
+
+ for (const auto& rc : res_appinfo->GetResControlList()) {
+ const std::shared_ptr<ResPkgInfo>& allowed_package = rc.GetAllowedPackage();
+ const std::shared_ptr<ResPkgInfo>& global_package = rc.GetGlobalPackage();
+ const std::string& auto_close = rc.GetAutoClose();
+ if (allowed_package) {
+ g_hash_table_insert(res_pkg_tbl,
+ strdup(allowed_package->GetPkgId().c_str()),
+ strdup(auto_close.c_str()));
+ }
+ if (global_package) {
+ g_hash_table_insert(res_pkg_tbl,
+ strdup(global_package->GetPkgId().c_str()),
+ strdup(auto_close.c_str()));
+ }
+ }
+
+ _app_status_set_extra(app_status, APP_STATUS_RES_PACKAGE, res_pkg_tbl);
+
+ return NOTI_CONTINUE;
+}
+
+static int __on_app_status_destroy(const char* msg, int arg1, int arg2,
+ void* arg3, bundle* data) {
+ app_status_h app_status = (app_status_h)arg3;
+ GHashTable* res_pkg_tbl = reinterpret_cast<GHashTable*>(
+ _app_status_get_extra(app_status, APP_STATUS_RES_PACKAGE));
+
+ if (res_pkg_tbl)
+ g_hash_table_destroy(res_pkg_tbl);
+
+ return NOTI_CONTINUE;
+}
+
int _resinfo_init(void) {
_noti_listen(AMD_NOTI_MSG_LOGIN_MONITOR_LOGIN_START,
__on_login_monitor_login_start);
__on_package_update_end);
_noti_listen(AMD_NOTI_MSG_APPINFO_PACKAGE_UPDATE_ERROR,
__on_package_update_error);
+ _noti_listen(AMD_NOTI_MSG_APP_STATUS_ADD,
+ __on_app_status_add);
+ _noti_listen(AMD_NOTI_MSG_APP_STATUS_DESTROY,
+ __on_app_status_destroy);
return 0;
}
namespace amd {
+const std::string& ResControl::GetResType() const {
+ return res_type;
+}
+
+const std::string& ResControl::GetMinResVersion() const {
+ return min_res_version;
+}
+
+const std::string& ResControl::GetMaxResVersion() const {
+ return max_res_version;
+}
+
+const std::string& ResControl::GetAutoClose() const {
+ return auto_close;
+}
+
+const std::shared_ptr<ResPkgInfo>& ResControl::GetAllowedPackage() const {
+ return allowed_package;
+}
+
+const std::shared_ptr<ResPkgInfo>& ResControl::GetGlobalPackage() const {
+ return global_package;
+}
+
std::shared_ptr<ResAppInfo> ResAppInfo::CreateResAppInfo(
const pkgmgrinfo_appinfo_h handle, uid_t uid) {
char* appid;
return appid_;
}
+const std::vector<ResControl>& ResAppInfo::GetResControlList() {
+ return res_control_list_;
+}
+
void ResAppInfo::ClearResControlMountInfo() {
for (auto& res_control : res_control_list_) {
res_control.allowed_package.reset();
allowed_package(nullptr),
global_package(nullptr) {}
+ const std::string& GetResType() const;
+ const std::string& GetMinResVersion() const;
+ const std::string& GetMaxResVersion() const;
+ const std::string& GetAutoClose() const;
+ const std::shared_ptr<ResPkgInfo>& GetAllowedPackage() const;
+ const std::shared_ptr<ResPkgInfo>& GetGlobalPackage() const;
+
private:
std::string res_type;
std::string min_res_version;
const pkgmgrinfo_appinfo_h handle, uid_t uid);
const std::string& GetAppId();
+ const std::vector<ResControl>& GetResControlList();
void ClearResControlMountInfo();
void UpdateResControlMountInfo(
const std::map<std::string, std::shared_ptr<ResPkgInfo>>& res_pkgs);