Add deactivate/activate apps internal APIs 31/117031/1
authorJunghyun Yeon <jungh.yeon@samsung.com>
Wed, 22 Feb 2017 05:40:01 +0000 (14:40 +0900)
committerJunghyun Yeon <jungh.yeon@samsung.com>
Thu, 2 Mar 2017 10:27:53 +0000 (19:27 +0900)
Related changes:
[pkgmgr-server] : https://review.tizen.org/gerrit/115924

Change-Id: I2fbbc40cde9bc840be20ee7f5c7b819e8f515096
Signed-off-by: Junghyun Yeon <jungh.yeon@samsung.com>
client/include/package-manager.h
client/src/pkgmgr.c

index 58c3859..9f78be4 100644 (file)
@@ -498,6 +498,42 @@ int pkgmgr_client_deactivate_app(pkgmgr_client *pc, const char *appid, pkgmgr_ap
 int pkgmgr_client_usr_deactivate_app(pkgmgr_client *pc, const char *appid, pkgmgr_app_handler app_event_cb, void *data, uid_t uid);
 
 /**
+ * @brief      This API activates multiple apps.
+ *
+ * This API is for package-manager client application.\n
+ *
+ * @param[in]  pc      pkgmgr_client
+ * @param[in]  appids  array of application ids
+ * @param[in]  n_apps  size of array
+ * @param[in]  app_event_cb    user callback
+ * @param[in]  data    user data
+ * @return     request_id (>0) if success, error code(<0) if fail\n
+ * @retval     PKGMGR_R_OK     success
+ * @retval     PKGMGR_R_EINVAL invalid argument
+ * @retval     PKGMGR_R_ECOMM  communication error
+*/
+int pkgmgr_client_activate_apps(pkgmgr_client *pc, const char **appids, int n_apps, pkgmgr_app_handler app_event_cb, void *data);
+int pkgmgr_client_usr_activate_apps(pkgmgr_client *pc, const char **appids, int n_apps, pkgmgr_app_handler app_event_cb, void *data, uid_t uid);
+
+/**
+ * @brief      This API deactivates multiple apps.
+ *
+ * This API is for package-manager client application.\n
+ *
+ * @param[in]  pc      pkgmgr_client
+ * @param[in]  appids  array of application ids
+ * @param[in]  n_apps  size of array
+ * @param[in]  app_event_cb    user callback
+ * @param[in]  data    user data
+ * @return     request_id (>0) if success, error code(<0) if fail\n
+ * @retval     PKGMGR_R_OK     success
+ * @retval     PKGMGR_R_EINVAL invalid argument
+ * @retval     PKGMGR_R_ECOMM  communication error
+*/
+int pkgmgr_client_deactivate_apps(pkgmgr_client *pc, const char **appids, int n_apps, pkgmgr_app_handler app_event_cb, void *data);
+int pkgmgr_client_usr_deactivate_apps(pkgmgr_client *pc, const char **appids, int n_apps, pkgmgr_app_handler app_event_cb, void *data, uid_t uid);
+
+/**
  * @brief      This API deactivates global app for user specified by uid.
  *
  * This API is for package-manager client application.\n
index 5a2ab72..4cfddd0 100644 (file)
@@ -1020,6 +1020,72 @@ API int pkgmgr_client_activate_app(pkgmgr_client *pc, const char *appid,
                        data, _getuid());
 }
 
+API int pkgmgr_client_usr_activate_apps(pkgmgr_client *pc, const char **appids,
+               int n_apps, pkgmgr_app_handler app_event_cb, void *data, uid_t uid)
+{
+       GVariant *result;
+       GVariantBuilder *builder;
+       int ret = PKGMGR_R_ECOMM;
+       char *req_key = NULL;
+       struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc;
+       struct cb_info *cb_info;
+       int i;
+
+       if (pc == NULL || appids == NULL || n_apps < 1) {
+               ERR("invalid parameter");
+               return PKGMGR_R_EINVAL;
+       }
+
+       if (client->pc_type != PC_REQUEST) {
+               ERR("client type is not PC_REQUEST");
+               return PKGMGR_R_EINVAL;
+       }
+
+       builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
+       for (i = 0; i < n_apps; i++)
+               g_variant_builder_add(builder, "s", appids[i]);
+
+       ret = pkgmgr_client_connection_send_request(client, "enable_apps",
+               g_variant_new("(uas)", uid, builder), &result);
+       g_variant_builder_unref(builder);
+       if (ret != PKGMGR_R_OK) {
+               ERR("request failed: %d", ret);
+               return ret;
+       }
+
+       g_variant_get(result, "(i&s)", &ret, &req_key);
+       if (req_key == NULL) {
+               g_variant_unref(result);
+               return PKGMGR_R_ECOMM;
+       }
+       if (ret != PKGMGR_R_OK) {
+               g_variant_unref(result);
+               return ret;
+       }
+
+       cb_info = __create_app_event_cb_info(client, app_event_cb, data, req_key);
+       if (cb_info == NULL) {
+               g_variant_unref(result);
+               return PKGMGR_R_ERROR;
+       }
+       g_variant_unref(result);
+       ret = pkgmgr_client_connection_set_callback(client, cb_info);
+       if (ret != PKGMGR_R_OK) {
+               __free_cb_info(cb_info);
+               return ret;
+       }
+       client->cb_info_list = g_list_append(client->cb_info_list, cb_info);
+
+       return cb_info->req_id;
+}
+
+API int pkgmgr_client_activate_apps(pkgmgr_client *pc, const char **appids,
+               int n_apps, pkgmgr_app_handler app_event_cb, void *data)
+{
+       return pkgmgr_client_usr_activate_apps(pc, appids, n_apps,
+                       app_event_cb, data, _getuid());
+}
+
 API int pkgmgr_client_activate_global_app_for_uid(pkgmgr_client *pc,
                const char *appid, pkgmgr_app_handler app_event_cb, void *data, uid_t uid)
 {
@@ -1124,6 +1190,73 @@ API int pkgmgr_client_deactivate_app(pkgmgr_client *pc, const char *appid,
                        _getuid());
 }
 
+API int pkgmgr_client_usr_deactivate_apps(pkgmgr_client *pc,
+               const char **appids, int n_apps,
+               pkgmgr_app_handler app_event_cb, void *data, uid_t uid)
+{
+       GVariant *result;
+       GVariantBuilder *builder;
+       int ret = PKGMGR_R_ECOMM;
+       char *req_key = NULL;
+       struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc;
+       struct cb_info *cb_info;
+       int i;
+
+       if (pc == NULL || appids == NULL || n_apps < 1) {
+               ERR("invalid parameter");
+               return PKGMGR_R_EINVAL;
+       }
+
+       if (client->pc_type != PC_REQUEST) {
+               ERR("client type is not PC_REQUEST");
+               return PKGMGR_R_EINVAL;
+       }
+
+       builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
+       for (i = 0; i < n_apps; i++)
+               g_variant_builder_add(builder, "s", appids[i]);
+
+       ret = pkgmgr_client_connection_send_request(client, "disable_apps",
+               g_variant_new("(uas)", uid, builder), &result);
+       g_variant_builder_unref(builder);
+       if (ret != PKGMGR_R_OK) {
+               ERR("request failed: %d", ret);
+               return ret;
+       }
+
+       g_variant_get(result, "(i&s)", &ret, &req_key);
+       if (req_key == NULL) {
+               g_variant_unref(result);
+               return PKGMGR_R_ECOMM;
+       }
+       if (ret != PKGMGR_R_OK) {
+               g_variant_unref(result);
+               return ret;
+       }
+
+       cb_info = __create_app_event_cb_info(client, app_event_cb, data, req_key);
+       if (cb_info == NULL) {
+               g_variant_unref(result);
+               return PKGMGR_R_ERROR;
+       }
+       g_variant_unref(result);
+       ret = pkgmgr_client_connection_set_callback(client, cb_info);
+       if (ret != PKGMGR_R_OK) {
+               __free_cb_info(cb_info);
+               return ret;
+       }
+       client->cb_info_list = g_list_append(client->cb_info_list, cb_info);
+
+       return cb_info->req_id;
+}
+
+API int pkgmgr_client_deactivate_apps(pkgmgr_client *pc, const char **appids,
+               int n_apps, pkgmgr_app_handler app_event_cb, void *data)
+{
+       return pkgmgr_client_usr_deactivate_apps(pc, appids, n_apps,
+                       app_event_cb, data, _getuid());
+}
+
 API int pkgmgr_client_deactivate_global_app_for_uid(pkgmgr_client *pc,
                const char *appid, pkgmgr_app_handler app_event_cb, void *data, uid_t uid)
 {