Add enable/disable apps 29/117029/1
authorJunghyun Yeon <jungh.yeon@samsung.com>
Wed, 22 Feb 2017 05:35:30 +0000 (14:35 +0900)
committerJunghyun Yeon <jungh.yeon@samsung.com>
Thu, 2 Mar 2017 10:25:59 +0000 (19:25 +0900)
- Add handling enable/disable apps

Related changes :
[slp-pkgmgr] : https://review.tizen.org/gerrit/115926

Change-Id: Ib1ffaaeca75dc2a3d49939c43259b67e33d45d19
Signed-off-by: Junghyun Yeon <jungh.yeon@samsung.com>
src/request.c

index b3f9164..cfa9ac4 100644 (file)
@@ -78,6 +78,18 @@ static const char instropection_xml[] =
        "      <arg type='i' name='ret' direction='out'/>"
        "      <arg type='s' name='reqkey' direction='out'/>"
        "    </method>"
+       "    <method name='enable_apps'>"
+       "      <arg type='u' name='uid' direction='in'/>"
+       "      <arg type='as' name='appids' direction='in'/>"
+       "      <arg type='i' name='ret' direction='out'/>"
+       "      <arg type='s' name='reqkey' direction='out'/>"
+       "    </method>"
+       "    <method name='disable_apps'>"
+       "      <arg type='u' name='uid' direction='in'/>"
+       "      <arg type='as' name='appids' direction='in'/>"
+       "      <arg type='i' name='ret' direction='out'/>"
+       "      <arg type='s' name='reqkey' direction='out'/>"
+       "    </method>"
        "    <method name='enable_global_app_for_uid'>"
        "      <arg type='u' name='uid' direction='in'/>"
        "      <arg type='s' name='appid' direction='in'/>"
@@ -713,6 +725,91 @@ static int __handle_request_disable_pkgs(uid_t caller_uid,
        return 0;
 }
 
+static int __handle_request_enable_apps(uid_t caller_uid,
+               GDBusMethodInvocation *invocation, GVariant *parameters)
+{
+       uid_t target_uid = (uid_t)-1;
+       char *appid;
+       char *reqkey;
+       char buf[MAX_PKG_ARGS_LEN];
+       GVariantIter *iter;
+
+       g_variant_get(parameters, "(uas)", &target_uid, &iter);
+       if (target_uid == (uid_t)-1 || iter == NULL) {
+               g_dbus_method_invocation_return_value(invocation,
+                               g_variant_new("(is)", PKGMGR_R_ECOMM, ""));
+               return -1;
+       }
+
+       reqkey = __generate_reqkey("enable_apps");
+       if (reqkey == NULL) {
+               g_dbus_method_invocation_return_value(invocation,
+                               g_variant_new("(is)", PKGMGR_R_ENOMEM, ""));
+               return -1;
+       }
+
+       while (g_variant_iter_next(iter, "&s", &appid)) {
+               if (_push_queue(target_uid, caller_uid, reqkey,
+                                       REQUEST_TYPE_ENABLE_APP,
+                                       "default", appid, buf)) {
+                       g_dbus_method_invocation_return_value(invocation,
+                                       g_variant_new("(is)",
+                                               PKGMGR_R_ESYSTEM, ""));
+                       free(reqkey);
+                       return -1;
+               }
+       }
+
+       g_dbus_method_invocation_return_value(invocation,
+               g_variant_new("(is)", PKGMGR_R_OK, reqkey));
+
+       free(reqkey);
+       return 0;
+}
+
+static int __handle_request_disable_apps(uid_t caller_uid,
+               GDBusMethodInvocation *invocation, GVariant *parameters)
+{
+       uid_t target_uid = (uid_t)-1;
+       char *appid;
+       char *reqkey;
+       char buf[MAX_PKG_ARGS_LEN];
+       GVariantIter *iter;
+
+       g_variant_get(parameters, "(uas)", &target_uid, &iter);
+       if (target_uid == (uid_t)-1 || iter == NULL) {
+               g_dbus_method_invocation_return_value(invocation,
+                               g_variant_new("(is)", PKGMGR_R_ECOMM, ""));
+               return -1;
+       }
+
+       reqkey = __generate_reqkey("disable_apps");
+       if (reqkey == NULL) {
+               g_dbus_method_invocation_return_value(invocation,
+                               g_variant_new("(is)", PKGMGR_R_ENOMEM, ""));
+               return -1;
+       }
+
+       while (g_variant_iter_next(iter, "&s", &appid)) {
+               if (_push_queue(target_uid, caller_uid, reqkey,
+                                       REQUEST_TYPE_DISABLE_APP,
+                                       "default", appid, buf)) {
+                       g_dbus_method_invocation_return_value(invocation,
+                                       g_variant_new("(is)",
+                                               PKGMGR_R_ESYSTEM, ""));
+                       free(reqkey);
+                       return -1;
+               }
+       }
+
+       g_dbus_method_invocation_return_value(invocation,
+               g_variant_new("(is)", PKGMGR_R_OK, reqkey));
+
+       free(reqkey);
+       return 0;
+
+}
+
 static int __handle_request_enable_app(uid_t caller_uid,
                GDBusMethodInvocation *invocation, GVariant *parameters)
 {
@@ -1531,6 +1628,10 @@ static void __handle_method_call(GDBusConnection *connection,
                ret = __handle_request_enable_app(uid, invocation, parameters);
        else if (g_strcmp0(method_name, "disable_app") == 0)
                ret = __handle_request_disable_app(uid, invocation, parameters);
+       else if (g_strcmp0(method_name, "enable_apps") == 0)
+               ret = __handle_request_enable_apps(uid, invocation, parameters);
+       else if (g_strcmp0(method_name, "disable_apps") == 0)
+               ret = __handle_request_disable_apps(uid, invocation, parameters);
        else if (g_strcmp0(method_name, "enable_global_app_for_uid") == 0)
                ret = __handle_request_enable_global_app_for_uid(uid,
                                invocation, parameters);