Each user can disable global app separately 09/56709/5
authorJunghyun Yeon <jungh.yeon@samsung.com>
Tue, 12 Jan 2016 07:46:56 +0000 (16:46 +0900)
committerJunghyun Yeon <jungh.yeon@samsung.com>
Tue, 19 Jan 2016 10:55:56 +0000 (19:55 +0900)
Changes applied at [slp-pkgmgr][pkgmgr-info][pkgmgr-server]

Change-Id: Ie67c58f8443bcaa832ca312ecbcdc7972eb3126f
Signed-off-by: Junghyun Yeon <jungh.yeon@samsung.com>
include/pkgmgr-info.h
include/pkgmgrinfo_private.h
parser/pkgmgr_parser_db.c
parser/pkgmgr_parser_db.h
src/pkgmgrinfo_appinfo.c
src/pkgmgrinfo_pkginfo.c
src/pkgmgrinfo_private.c

index 9db2a1d..f770e1e 100644 (file)
@@ -140,6 +140,9 @@ extern "C" {
  /** String property for filtering based on app info*/
 #define        PMINFO_APPINFO_PROP_APP_METADATA_VALUE  "PMINFO_APPINFO_PROP_APP_METADATA_VALUE"
 
+ /** Integer property for filtering app disabled by user*/
+#define        PMINFO_APPINFO_PROP_APP_DISABLE_FOR_USER        "PMINFO_APPINFO_PROP_APP_DISABLE_FOR_USER_VALUE"
+
  /** Boolean property for filtering based on app info*/
 #define        PMINFO_APPINFO_PROP_APP_NODISPLAY               "PMINFO_APPINFO_PROP_APP_NODISPLAY"
  /** Boolean property for filtering based on app info*/
index 9f7fa8f..3083fe1 100644 (file)
@@ -147,7 +147,8 @@ typedef enum _pkgmgrinfo_appinfo_filter_prop_bool {
 typedef enum _pkgmgrinfo_appinfo_filter_prop_int {
        /*Currently No Fields*/
        E_PMINFO_APPINFO_PROP_APP_MIN_INT = 601,
-       E_PMINFO_APPINFO_PROP_APP_MAX_INT = E_PMINFO_APPINFO_PROP_APP_MIN_INT
+       E_PMINFO_APPINFO_PROP_APP_DISABLE_FOR_USER,
+       E_PMINFO_APPINFO_PROP_APP_MAX_INT = E_PMINFO_APPINFO_PROP_APP_DISABLE_FOR_USER
 } pkgmgrinfo_appinfo_filter_prop_int;
 
 /*Integer properties for filtering based on app info*/
index 6e32460..1010335 100644 (file)
@@ -90,7 +90,8 @@ sqlite3 *pkgmgr_cert_db;
                                                "package_url text," \
                                                "root_path text," \
                                                "csc_path text," \
-                                               "package_support_disable text DEFAULT 'false')"
+                                               "package_support_disable text DEFAULT 'false', " \
+                                               "package_disable text DEFAULT 'false')"
 
 #define QUERY_CREATE_TABLE_PACKAGE_LOCALIZED_INFO "create table if not exists package_localized_info " \
                                                "(package text not null, " \
@@ -142,6 +143,7 @@ sqlite3 *pkgmgr_cert_db;
                                                "app_launch_mode text NOT NULL DEFAULT 'caller', " \
                                                "app_ui_gadget text DEFAULT 'false', " \
                                                "app_support_disable text DEFAULT 'false', " \
+                                               "app_disable text DEFAULT 'false', " \
                                                "component_type text, " \
                                                "package text not null, " \
                                                "app_tep_name text, " \
@@ -297,6 +299,11 @@ sqlite3 *pkgmgr_cert_db;
                                                "REFERENCES package_app_info(app_id) " \
                                                "ON DELETE CASCADE)"
 
+#define QUERY_CREATE_TABLE_PACKAGE_APP_DISABLE_FOR_USER "CREATE TABLE IF NOT EXISTS package_app_disable_for_user " \
+                                               "(app_id text not null, " \
+                                               "uid text not null, " \
+                                               "PRIMARY KEY(app_id, uid))"
+
 static int __insert_application_info(manifest_x *mfx);
 static int __insert_application_appcategory_info(manifest_x *mfx);
 static int __insert_application_appcontrol_info(manifest_x *mfx);
@@ -1542,6 +1549,36 @@ static int __delete_manifest_info_from_db(manifest_x *mfx, uid_t uid)
        return 0;
 }
 
+static int __disable_global_app_for_user(const char *appid, uid_t uid)
+{
+       int ret = -1;
+       char query[MAX_QUERY_LEN] = {'\0'};
+
+       sqlite3_snprintf(MAX_QUERY_LEN, query, "INSERT INTO " \
+                       "package_app_disable_for_user(app_id, uid) VALUES(%Q, %Q)",
+                       appid, (int)uid);
+       ret = __exec_query(query);
+       if (ret == -1)
+               _LOGD("Insert global app disable failed\n");
+
+       return ret;
+}
+
+static int __enable_global_app_for_user(const char *appid, uid_t uid)
+{
+       int ret = -1;
+       char query[MAX_QUERY_LEN] = {'\0'};
+
+       sqlite3_snprintf(MAX_QUERY_LEN, query, "DELETE FROM " \
+                       "package_app_disable_for_user WHERE app_id=%Q AND uid=%Q",
+                       appid, (int)uid);
+       ret = __exec_query(query);
+       if (ret == -1)
+               _LOGD("Delete global app disable failed\n");
+
+       return ret;
+}
+
 static int __update_preload_condition_in_db()
 {
        int ret = -1;
@@ -1638,6 +1675,13 @@ API int pkgmgr_parser_initialize_db(uid_t uid)
                _LOGD("package app data control DB initialization failed\n");
                return ret;
        }
+
+       ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_DISABLE_FOR_USER);
+       if (ret == -1) {
+               _LOGD("package app disable for user DB initialization failed\n");
+               return ret;
+       }
+
        /*Cert DB*/
        /* TODO: refactor this code */
        ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TABLE_PACKAGE_CERT_INFO);
@@ -2132,3 +2176,45 @@ err:
        pkgmgr_parser_close_db();
        return ret;
 }
+
+API int pkgmgr_parser_update_global_app_disable_info_in_db(const char *appid, uid_t uid, int is_disable)
+{
+       int ret = -1;
+
+       ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
+       if (ret == -1) {
+               _LOGD("Failed to open DB\n");
+               return ret;
+       }
+
+       /*Begin transaction*/
+       ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
+       if (ret != SQLITE_OK) {
+               _LOGD("Failed to begin transaction\n");
+               ret = -1;
+               goto err;
+       }
+       _LOGD("Transaction Begin\n");
+       if (is_disable)
+               ret = __disable_global_app_for_user(appid, uid);
+       else
+               ret = __enable_global_app_for_user(appid, uid);
+       if (ret == -1) {
+               _LOGD("__update_preload_condition_in_db failed. Rollback now\n");
+               sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
+               goto err;
+       }
+       /*Commit transaction*/
+       ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
+       if (ret != SQLITE_OK) {
+               _LOGD("Failed to commit transaction, Rollback now\n");
+               sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
+               ret = -1;
+               goto err;
+       }
+       _LOGD("Transaction Commit and End\n");
+err:
+       pkgmgr_parser_close_db();
+       return ret;
+
+}
index 2c145bb..9cbe871 100644 (file)
@@ -162,6 +162,7 @@ int pkgmgr_parser_delete_manifest_info_from_usr_db(manifest_x *mfx, uid_t uid);
 
 int pkgmgr_parser_update_preload_info_in_db();
 int pkgmgr_parser_update_preload_info_in_usr_db(uid_t uid);
+int pkgmgr_parser_update_global_app_disable_info_in_db(const char *appid, uid_t uid, int is_disable);
 
 int pkgmgr_parser_create_and_initialize_db(uid_t uid);
 
index 75c1c21..3394698 100644 (file)
@@ -562,22 +562,17 @@ static int _appinfo_get_application(sqlite3 *db, const char *appid,
                "app_support_disable, "
                "component_type, package, app_process_pool, app_installed_storage, "
                "app_background_category "
-               "FROM package_app_info WHERE app_id=%Q";
+               "FROM package_app_info WHERE app_id='%s' AND app_disable='false' "
+               "AND app_id NOT IN "
+               "(SELECT app_id from package_app_disable_for_user WHERE uid='%d')";
        int ret;
-       char *query;
+       char query[MAX_QUERY_LEN] = { '\0' };
        sqlite3_stmt *stmt;
        int idx;
        application_x *info;
        char *bg_category_str = NULL;
-
-       query = sqlite3_mprintf(query_raw, appid);
-       if (query == NULL) {
-               LOGE("out of memory");
-               return PMINFO_R_ERROR;
-       }
-
+       snprintf(query, MAX_QUERY_LEN - 1, query_raw, appid, (int)getuid());
        ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
-       sqlite3_free(query);
        if (ret != SQLITE_OK) {
                LOGE("prepare failed: %s", sqlite3_errmsg(db));
                return PMINFO_R_ERROR;
@@ -819,6 +814,13 @@ API int pkgmgrinfo_appinfo_get_usr_list(pkgmgrinfo_pkginfo_h handle,
                return PMINFO_R_ERROR;
        }
 
+       if (uid == GLOBAL_USER) {
+               if (pkgmgrinfo_appinfo_filter_add_int(filter,
+                                       PMINFO_APPINFO_PROP_APP_DISABLE_FOR_USER, (int)getuid())) {
+                       pkgmgrinfo_appinfo_filter_destroy(filter);
+                       return PMINFO_R_ERROR;
+               }
+       }
 
        switch (component) {
        case PMINFO_UI_APP:
index 501fa2b..7c6a7ca 100644 (file)
@@ -203,7 +203,8 @@ static int _pkginfo_get_list(sqlite3 *db, const char *locale,
                "  ON package_info.package=package_localized_info.package"
                "  AND package_localized_info.package_locale=%Q "
                " LEFT OUTER JOIN package_privilege_info"
-               "  ON package_info.package=package_privilege_info.package";
+               "  ON package_info.package=package_privilege_info.package"
+               " WHERE package_info.package_disable='false'";
        int ret;
        char *query;
        char *query_localized;
@@ -640,7 +641,7 @@ static int _pkginfo_get_package(sqlite3 *db, const char *pkgid,
                "installed_storage, storeclient_id, mainapp_id, package_url, "
                "root_path, csc_path, package_nodisplay, package_api_version, "
                "package_support_disable, package_tep_name "
-               "FROM package_info WHERE package=%Q";
+               "FROM package_info WHERE package=%Q AND package_disable='false'";
        int ret;
        char *query;
        sqlite3_stmt *stmt;
index d695232..914a95a 100644 (file)
@@ -103,7 +103,7 @@ struct _appinfo_int_map_t {
 };
 
 static struct _appinfo_int_map_t appinfo_int_prop_map[] = {
-       /*Currently No Fields*/
+       {E_PMINFO_APPINFO_PROP_APP_DISABLE_FOR_USER,    PMINFO_APPINFO_PROP_APP_DISABLE_FOR_USER}
 };
 
 struct _appinfo_bool_map_t {
@@ -358,6 +358,10 @@ void __get_filter_condition(gpointer data, char **condition)
        case E_PMINFO_APPINFO_PROP_APP_SUPPORT_DISABLE:
                snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_support_disable IN %s", node->value);
                break;
+       case E_PMINFO_APPINFO_PROP_APP_DISABLE_FOR_USER:
+               snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_id NOT IN "
+                               "(SELECT app_id from package_app_disable_for_user WHERE uid='%s')", node->value);
+               break;
        default:
                _LOGE("Invalid Property Type\n");
                *condition = NULL;