From fb2f805e077d1256c5e52b71dc5f98370a47266d Mon Sep 17 00:00:00 2001 From: jongmyeongko Date: Tue, 2 May 2017 23:57:52 +0900 Subject: [PATCH] Modify the function to kill running apps When the sdcard is removed, the app2sd can't acess the app2sd file. And this can cause the failure to get pkginfo and appinfo. Change-Id: I7c2eae676bee659e0b2a410728bfac70d9fa7e9d Signed-off-by: jongmyeongko (cherry picked from commit 2b9f24daf1adf82259ddba110d5cd513a0ea780f) --- plugin/app2sd/server/app2sd_interface.c | 34 +++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/plugin/app2sd/server/app2sd_interface.c b/plugin/app2sd/server/app2sd_interface.c index 4495a6c..56b06f5 100644 --- a/plugin/app2sd/server/app2sd_interface.c +++ b/plugin/app2sd/server/app2sd_interface.c @@ -494,26 +494,48 @@ static int _app2sd_kill_running_app(const char *pkgid, uid_t uid) { int ret = 0; pkgmgrinfo_pkginfo_h handle; + pkgmgrinfo_appinfo_filter_h filter; - ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, uid, &handle); + ret = pkgmgrinfo_pkginfo_get_usr_all_pkginfo(pkgid, uid, &handle); if (ret < 0) { _E("failed to get pkginfo"); return APP2EXT_ERROR_PKGMGR_ERROR; } - ret = pkgmgrinfo_appinfo_get_usr_list(handle, - PMINFO_ALL_APP, _app2sd_application_handler, &uid, uid); + pkgmgrinfo_pkginfo_destroy_pkginfo(handle); + + ret = pkgmgrinfo_appinfo_filter_create(&filter); + if (ret < 0) { + _E("failed to create appinfo filter"); + return APP2EXT_ERROR_PKGMGR_ERROR; + } + + ret = pkgmgrinfo_appinfo_filter_add_string(filter, + PMINFO_APPINFO_PROP_APP_PACKAGE, pkgid); if (ret < 0) { - _E("failed to get appinfo"); + _E("failed to add pkgid to filter"); + pkgmgrinfo_appinfo_filter_destroy(filter); return APP2EXT_ERROR_PKGMGR_ERROR; } - ret = pkgmgrinfo_pkginfo_destroy_pkginfo(handle); + ret = pkgmgrinfo_appinfo_filter_add_bool(filter, + PMINFO_APPINFO_PROP_APP_CHECK_STORAGE, false); if (ret < 0) { - _E("failed to destroy pkginfo"); + _E("failed to add check_storage to filter"); + pkgmgrinfo_appinfo_filter_destroy(filter); return APP2EXT_ERROR_PKGMGR_ERROR; } + ret = pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(filter, + _app2sd_application_handler, &uid, uid); + if (ret < 0) { + _E("failed to get filtered foreach appinfo"); + pkgmgrinfo_appinfo_filter_destroy(filter); + return APP2EXT_ERROR_PKGMGR_ERROR; + } + + pkgmgrinfo_appinfo_filter_destroy(filter); + return APP2EXT_SUCCESS; } -- 2.7.4