Add badge_new_for API 76/195576/2
authorMi-Ju Lee <miju52.lee@samsung.com>
Fri, 14 Dec 2018 10:50:21 +0000 (19:50 +0900)
committermk5004.lee <mk5004.lee@samsung.com>
Fri, 11 Jan 2019 02:17:57 +0000 (11:17 +0900)
Change-Id: I7f467d045e5ce52962e9d038c80e3ed22a0806ba

include/badge_internal.h
src/badge_internal.c

index a0fe5ba..ed0988a 100644 (file)
@@ -201,6 +201,40 @@ int badge_create_for_uid(const char *pkgname, const char *writable_pkg, uid_t ui
 
 int badge_new_for_uid(const char *writable_app_id, uid_t uid);
 
+/**
+ * @internal
+ * @brief Creates a badge for the application specified by the badge_app_id.
+ * @since_tizen 5.5
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/notification
+ * @details Creates new badge to display.
+ * @param[in] badge_app_id The id of the application for which the badge will be created. This should be the same package id with the caller application's package id
+ * @param[in] writable_app_id The id of the application which is authorized to change the badge
+ * @return #BADGE_ERROR_NONE if success, other value if failure
+ * @retval #BADGE_ERROR_NONE Success
+ * @retval #BADGE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #BADGE_ERROR_PERMISSION_DENIED The application does not have the privilege to call this method
+ * @retval #BADGE_ERROR_IO_ERROR Error from I/O
+ * @retval #BADGE_ERROR_SERVICE_NOT_READY Service is not ready
+ * @retval #BADGE_ERROR_INVALID_PACKAGE Error while caller package is different with the id of the application badge creates
+ * @see #badge_error_e
+ * @par Sample code:
+ * @code
+#include <badge_internal.h>
+
+{
+       int err = BADGE_ERROR_NONE;
+
+       err = badge_new_for(badge_app_id,app_id);
+       if(err != BADGE_ERROR_NONE) {
+               return;
+       }
+}
+ * @endcode
+ */
+int badge_new_for(const char *badge_app_id, const char *writable_app_id);
+int badge_new_for_for_uid(const char *badge_app_id, const char *writable_app_id, uid_t uid);
+
 int badge_add_for_uid(const char *badge_app_id, uid_t uid);
 
 int badge_remove_for_uid(const char *app_id, uid_t uid);
index 1046e6f..701f7b4 100644 (file)
@@ -1357,6 +1357,52 @@ int badge_new_for_uid(const char *writable_app_id, uid_t uid)
        return err;
 }
 
+int badge_new_for_for_uid(const char *badge_app_id, const char *writable_app_id, uid_t uid)
+{
+       CHECK_BADGE_FEATURE();
+       char *caller = NULL;
+       int err = BADGE_ERROR_NONE;
+
+       caller = _badge_get_pkgname_by_pid();
+       if (!caller) {
+               ERR("Failed to get caller pkgname");
+               return BADGE_ERROR_PERMISSION_DENIED;
+       }
+
+       if (badge_app_id == NULL) {
+               badge_app_id = caller;
+       } else {
+               int pkgmgr_ret  = PACKAGE_MANAGER_ERROR_NONE;
+               package_manager_compare_result_type_e compare_result =
+                                               PACKAGE_MANAGER_COMPARE_MISMATCH;
+
+               pkgmgr_ret = package_manager_compare_app_cert_info(badge_app_id,
+                                                       caller, &compare_result);
+
+               if (pkgmgr_ret != PACKAGE_MANAGER_ERROR_NONE ||
+                       compare_result != PACKAGE_MANAGER_COMPARE_MATCH) {
+                       err = BADGE_ERROR_INVALID_PACKAGE;
+                       goto out;
+               }
+       }
+
+       err = badge_ipc_request_insert(badge_app_id, writable_app_id, caller, uid);
+out:
+       if (caller)
+               free(caller);
+       return err;
+}
+
+EXPORT_API
+int badge_new_for(const char *badge_app_id, const char *writable_app_id)
+{
+       CHECK_BADGE_FEATURE();
+       if (writable_app_id == NULL)
+               return BADGE_ERROR_INVALID_PARAMETER;
+
+       return badge_new_for_for_uid(badge_app_id, writable_app_id, getuid());
+}
+
 EXPORT_API
 int badge_add_for_uid(const char *badge_app_id, uid_t uid)
 {