Implement restriction mode api 06/68306/5
authorSangyoon Jang <s89.jang@samsung.com>
Tue, 3 May 2016 10:35:33 +0000 (19:35 +0900)
committerSangyoon Jang <s89.jang@samsung.com>
Mon, 9 May 2016 02:07:06 +0000 (11:07 +0900)
Related patch:
 - https://review.tizen.org/gerrit/66938

Change-Id: I9d1edfa4ac20c6e2b543e0694eb27f5f459f7758
Signed-off-by: Sangyoon Jang <s89.jang@samsung.com>
client/include/package-manager.h
client/src/pkgmgr.c

index 0308221..f797bf5 100644 (file)
@@ -334,6 +334,14 @@ typedef enum {
        PM_GET_MAX
 } pkgmgr_getsize_type;
 
+typedef enum {
+       PM_RESTRICTION_MODE_ALL = 0x0F,
+       PM_RESTRICTION_MODE_INSTALL = 0x01,
+       PM_RESTRICTION_MODE_UNINSTALL = 0x02,
+       PM_RESTRICTION_MODE_REINSTALL = 0x04,
+       PM_RESTRICTION_MODE_MOVE = 0x08,
+} pkgmgr_restriction_mode;
+
 /**
  * @brief      This API creates pkgmgr client.
  *
@@ -977,6 +985,57 @@ int pkgmgr_client_usr_enable_splash_screen(pkgmgr_client *pc, const char *appid,
 int pkgmgr_client_disable_splash_screen(pkgmgr_client *pc, const char *appid);
 int pkgmgr_client_usr_disable_splash_screen(pkgmgr_client *pc, const char *appid, uid_t uid);
 
+/**
+ * @brief      Set restriction mode
+ *
+ * This API set restriction mode bit.\n
+ *
+ * @param[in]  pc      The pointer to pkgmgr_client instance
+ * @param[in]  mode    restriction mode bit
+ * @return     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
+ * @retval     PKGMGR_R_EPRIV privilege denied
+ * @see pkgmgr_restriction_mode
+ */
+int pkgmgr_client_set_restriction_mode(pkgmgr_client *pc, int mode);
+int pkgmgr_client_usr_set_restriction_mode(pkgmgr_client *pc, int mode, uid_t uid);
+
+/**
+ * @brief      Unset restriction mode
+ *
+ * This API unset restriction mode bit.\n
+ *
+ * @param[in]  pc      The pointer to pkgmgr_client instance
+ * @param[in]  mode    restriction mode bit
+ * @return     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
+ * @retval     PKGMGR_R_EPRIV privilege denied
+ * @see pkgmgr_restriction_mode
+ */
+int pkgmgr_client_unset_restriction_mode(pkgmgr_client *pc, int mode);
+int pkgmgr_client_usr_unset_restriction_mode(pkgmgr_client *pc, int mode, uid_t uid);
+
+/**
+ * @brief      Get restriction mode
+ *
+ * This API gets restriction mode bit.\n
+ *
+ * @param[in]  pc      The pointer to pkgmgr_client instance
+ * @param[out] mode    restriction mode bit
+ * @return     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
+ * @retval     PKGMGR_R_EPRIV privilege denied
+ * @see pkgmgr_restriction_mode
+ */
+int pkgmgr_client_get_restriction_mode(pkgmgr_client *pc, int *mode);
+int pkgmgr_client_usr_get_restriction_mode(pkgmgr_client *pc, int *mode, uid_t uid);
+
 /** @} */
 
 
index 1babdd6..946779e 100644 (file)
@@ -2493,3 +2493,100 @@ API int pkgmgr_client_usr_disable_splash_screen(pkgmgr_client *pc,
        return ret;
 }
 
+API int pkgmgr_client_usr_set_restriction_mode(pkgmgr_client *pc, int mode,
+               uid_t uid)
+{
+       GVariant *result;
+       int ret = PKGMGR_R_ECOMM;
+       pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc;
+
+       if (pc == NULL) {
+               ERR("invalid parameter");
+               return PKGMGR_R_EINVAL;
+       }
+
+       ret = comm_client_request(mpc->info.request.cc, "set_restriction_mode",
+                       g_variant_new("(ui)", uid, mode), &result);
+       if (ret != PKGMGR_R_OK) {
+               ERR("request failed: %d", ret);
+               return ret;
+       }
+
+       g_variant_get(result, "(i)", &ret);
+       g_variant_unref(result);
+
+       return ret;
+}
+
+API int pkgmgr_client_set_restriction_mode(pkgmgr_client *pc, int mode)
+{
+       return pkgmgr_client_usr_set_restriction_mode(pc, mode, _getuid());
+}
+
+API int pkgmgr_client_usr_unset_restriction_mode(pkgmgr_client *pc, int mode,
+               uid_t uid)
+{
+       GVariant *result;
+       int ret = PKGMGR_R_ECOMM;
+       pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc;
+
+       if (pc == NULL) {
+               ERR("invalid parameter");
+               return PKGMGR_R_EINVAL;
+       }
+
+       ret = comm_client_request(mpc->info.request.cc,
+                       "unset_restriction_mode",
+                       g_variant_new("(ui)", uid, mode), &result);
+       if (ret != PKGMGR_R_OK) {
+               ERR("request failed: %d", ret);
+               return ret;
+       }
+
+       g_variant_get(result, "(i)", &ret);
+       g_variant_unref(result);
+
+       return ret;
+}
+
+API int pkgmgr_client_unset_restriction_mode(pkgmgr_client *pc, int mode)
+{
+       return pkgmgr_client_usr_unset_restriction_mode(pc, mode, _getuid());
+}
+
+API int pkgmgr_client_usr_get_restriction_mode(pkgmgr_client *pc,
+               int *mode, uid_t uid)
+{
+       GVariant *result;
+       int ret = PKGMGR_R_ECOMM;
+       gint m;
+       pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc;
+
+       if (pc == NULL) {
+               ERR("invalid parameter");
+               return PKGMGR_R_EINVAL;
+       }
+
+       ret = comm_client_request(mpc->info.request.cc,
+                       "get_restriction_mode",
+                       g_variant_new("(u)", uid), &result);
+       if (ret != PKGMGR_R_OK) {
+               ERR("request failed: %d", ret);
+               return ret;
+       }
+
+       g_variant_get(result, "(ii)", &m, &ret);
+       g_variant_unref(result);
+       if (ret != PKGMGR_R_OK)
+               return ret;
+
+       *mode = m;
+
+       return PKGMGR_R_OK;
+}
+
+API int pkgmgr_client_get_restriction_mode(pkgmgr_client *pc,
+               int *mode)
+{
+       return pkgmgr_client_usr_get_restriction_mode(pc, mode, _getuid());
+}