Add shortcut feature 97/144297/7 accepted/tizen/4.0/unified/20170904.143844 submit/tizen_4.0/20170904.025628 submit/tizen_4.0/20170904.030057
authorSeungha Son <seungha.son@samsung.com>
Wed, 16 Aug 2017 07:29:40 +0000 (16:29 +0900)
committerSeungha Son <seungha.son@samsung.com>
Thu, 31 Aug 2017 09:14:26 +0000 (18:14 +0900)
Signed-off-by: Seungha Son <seungha.son@samsung.com>
Change-Id: Id6d4b8704a4bd211d97be869fa5df76ee9a1fe89

doc/shortcut_doc.h
lib/CMakeLists.txt
lib/include/shortcut_manager.h
lib/include/shortcut_private.h
lib/src/shortcut_manager.c
packaging/libshortcut.spec

index 458264b..3dc9fe6 100755 (executable)
  * \#include <shortcut_manager.h>
  *
  * @section SHORTCUT_MODULE_OVERVIEW Overview
-   It provides function of creating shortcut.
-   Developers can use the "shortcut_add_to_home" API to create their shortcut to a home screen.
+ * It provides function of creating shortcut.
+ * Developers can use the "shortcut_add_to_home" API to create their shortcut to a home screen.
+
+ * @section CAPI_SHORTCUT_MODULE_FEATURE Related Features
+ * This API is related with the following features:\n
+ * - http://tizen.org/feature/shortcut\n
+ * It is recommended to design feature related codes in your application for reliability.\n
+ * You can check if a device supports the related features for this API by using @ref CAPI_SYSTEM_SYSTEM_INFO_MODULE, thereby controlling the procedure of your application.\n
+ * To ensure your application is only running on the device with specific features, please define the features in your manifest file using the manifest editor in the SDK.\n
+ * More details on featuring your application can be found from <a href="https://developer.tizen.org/development/tizen-studio/native-tools/configuring-your-app/manifest-text-editor#feature"><b>Feature Element</b>.</a>
  */
 
 
index bbedc6a..0ea5d25 100755 (executable)
@@ -17,6 +17,7 @@ pkg_check_modules(svc_pkgs REQUIRED
        vconf
        capi-base-common
        aul
+       capi-system-info
 )
 
 FOREACH(flag ${svc_pkgs_CFLAGS})
index 96854b2..6d656fc 100755 (executable)
@@ -234,6 +234,7 @@ int shortcut_add_to_home_widget(const char *name, shortcut_widget_size_e size, c
  * @retval #SHORTCUT_ERROR_IO_ERROR I/O Error
  * @retval #SHORTCUT_ERROR_PERMISSION_DENIED Permission denied
  * @retval #SHORTCUT_ERROR_COMM Connection not established or communication problem
+ * @retval #SHORTCUT_ERROR_NOT_SUPPORTED Not supported
  * @pre You have to prepare the callback function.
  * @post You have to check the return status from the callback function which is passed by the argument.
  * @see result_cb_t
@@ -299,6 +300,7 @@ typedef int (*shortcut_list_cb)(const char *package_name, const char *icon, cons
  * @retval #SHORTCUT_ERROR_PERMISSION_DENIED Permission denied
  * @retval #SHORTCUT_ERROR_FAULT Unrecoverable error
  * @retval #SHORTCUT_ERROR_COMM Connection not established or communication problem
+ * @retval #SHORTCUT_ERROR_NOT_SUPPORTED Not supported
  * @pre You have to prepare the callback function.
  * @post You have to check the return status from the callback function which is passed by the argument.
  *
@@ -362,6 +364,7 @@ typedef int (*shortcut_remove_cb)(const char *package_name, const char *name, in
  * @retval #SHORTCUT_ERROR_IO_ERROR I/O Error
  * @retval #SHORTCUT_ERROR_PERMISSION_DENIED Permission denied
  * @retval #SHORTCUT_ERROR_COMM Connection not established or communication problem
+ * @retval #SHORTCUT_ERROR_NOT_SUPPORTED Not supported
  * @pre You have to prepare a callback function.
  * @post If a request is sent from the application, the registered callback will be invoked.
  * @see request_cb_t
@@ -373,9 +376,15 @@ int shortcut_set_request_cb(shortcut_request_cb request_cb, void *data);
 /**
  * @brief Unregisters a callback for the shortcut request.
  * @since_tizen 3.0
+ * @remarks The specific error code can be obtained using the gat_last_result() method. Error codes are described in Exception section.
  * @privlevel public
  * @privilege %http://tizen.org/privilege/shortcut
+ * @return None
+ * @exception #SHORTCUT_ERROR_NONE Successful
+ * @exception #SHORTCUT_ERROR_NOT_SUPPORTED Not supported
+ * @exception #SHORTCUT_ERROR_PERMISSION_DENIED Permission denied
  * @see shortcut_set_request_cb
+ * @see get_last_result()
  */
 void shortcut_unset_request_cb(void);
 
@@ -397,6 +406,7 @@ void shortcut_unset_request_cb(void);
  * @retval #SHORTCUT_ERROR_IO_ERROR I/O Error
  * @retval #SHORTCUT_ERROR_PERMISSION_DENIED Permission denied
  * @retval #SHORTCUT_ERROR_COMM Connection not established or communication problem
+ * @retval #SHORTCUT_ERROR_NOT_SUPPORTED Not supported
  * @pre You have to prepare a callback function.
  * @post If a request is sent from the application, the registered callback will be invoked.
  * @see remove_cb_t
@@ -408,9 +418,15 @@ int shortcut_set_remove_cb(shortcut_remove_cb remove_cb, void *data);
 /**
  * @brief Unregisters a callback for the shortcut remove.
  * @since_tizen 3.0
+ * @remarks The specific error code can be obtained using the gat_last_result() method. Error codes are described in Exception section.
  * @privlevel public
  * @privilege %http://tizen.org/privilege/shortcut
+ * @return None
+ * @exception #SHORTCUT_ERROR_NONE Successful
+ * @exception #SHORTCUT_ERROR_NOT_SUPPORTED Not supported
+ * @exception #SHORTCUT_ERROR_PERMISSION_DENIED Permission denied
  * @see shortcut_set_remove_cb
+ * @see get_last_result()
  */
 void shortcut_unset_remove_cb(void);
 
index 87d3bd1..3a62cff 100755 (executable)
  *
  */
 
+#ifndef __SHORTCUT_PRIVATE_H__
+#define __SHORTCUT_PRIVATE_H__
+
+#include <system_info.h>
+
 #if !defined(FLOG)
 #define SHORTCUT_DBG(format, arg...)   SECURE_LOGD(format, ##arg)
 #define SHORTCUT_ERR(format, arg...)   SECURE_LOGE(format, ##arg)
@@ -30,8 +35,40 @@ extern FILE *__file_log_fp;
 #define EAPI __attribute__((visibility("default")))
 #endif
 
-
 #define DEFAULT_ICON_LAYOUT ""
 #define DEFAULT_ICON_GROUP ""
 
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+#define SHORTCUT_FEATURE "http://tizen.org/feature/shortcut"
+#define CHECK_SHORTCUT_FEATURE() \
+       do { \
+               bool is_supported = false; \
+               if (!system_info_get_platform_bool(SHORTCUT_FEATURE, &is_supported)) { \
+                       if (is_supported == false) { \
+                               LOGE("[%s] feature is disabled", SHORTCUT_FEATURE); \
+                               return SHORTCUT_ERROR_NOT_SUPPORTED; \
+                       } \
+               } \
+       } while (0)
+
+#define CHECK_SHORTCUT_FEATURE_RET_LAST_RESULT() \
+       do { \
+               bool is_supported = false; \
+               if (!system_info_get_platform_bool(SHORTCUT_FEATURE, &is_supported)) { \
+                       if (is_supported == false) { \
+                               LOGE("[%s] feature is disabled", SHORTCUT_FEATURE); \
+                               set_last_result(SHORTCUT_ERROR_NOT_SUPPORTED); \
+                               return; \
+                       } \
+               } \
+       } while (0)
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* __SHORTCUT_PRIVATE_H__ */
+
 /* End of a file */
index efba17a..390925f 100755 (executable)
@@ -79,6 +79,7 @@ EAPI int shortcut_set_request_cb(shortcut_request_cb request_cb, void *data)
 {
        int ret;
 
+       CHECK_SHORTCUT_FEATURE();
        if (request_cb == NULL)
                return SHORTCUT_ERROR_INVALID_PARAMETER; /* LCOV_EXCL_LINE */
 
@@ -93,13 +94,25 @@ EAPI int shortcut_set_request_cb(shortcut_request_cb request_cb, void *data)
 
 EAPI void shortcut_unset_request_cb(void)
 {
+       int ret;
+
+       CHECK_SHORTCUT_FEATURE_RET_LAST_RESULT();
+
+       ret = _check_privilege();
+       if (ret == SHORTCUT_ERROR_PERMISSION_DENIED) {
+               set_last_result(SHORTCUT_ERROR_PERMISSION_DENIED);
+               return;
+       }
+
        _unset_request_cb();
+       set_last_result(SHORTCUT_ERROR_NONE);
 }
 
 EAPI int shortcut_set_remove_cb(shortcut_remove_cb remove_cb, void *data)
 {
        int ret;
 
+       CHECK_SHORTCUT_FEATURE();
        if (remove_cb == NULL)
                return SHORTCUT_ERROR_INVALID_PARAMETER;
 
@@ -114,7 +127,18 @@ EAPI int shortcut_set_remove_cb(shortcut_remove_cb remove_cb, void *data)
 
 EAPI void shortcut_unset_remove_cb(void)
 {
+       int ret;
+
+       CHECK_SHORTCUT_FEATURE_RET_LAST_RESULT();
+
+       ret = _check_privilege();
+       if (ret == SHORTCUT_ERROR_PERMISSION_DENIED) {
+               set_last_result(SHORTCUT_ERROR_PERMISSION_DENIED);
+               return;
+       }
+
        _unset_remove_cb();
+       set_last_result(SHORTCUT_ERROR_NONE);
 }
 
 static char *_make_request_id()
@@ -139,6 +163,8 @@ EAPI int shortcut_add_to_home(const char *name, shortcut_type type, const char *
        GVariant *body;
        char *request_id = NULL;
 
+       CHECK_SHORTCUT_FEATURE();
+
        if (ADD_TO_HOME_IS_DYNAMICBOX(type)) {
                /* LCOV_EXCL_START */
                SHORTCUT_ERR("Invalid type used for adding a shortcut\n");
@@ -220,6 +246,8 @@ EAPI int shortcut_add_to_home_widget(const char *name, shortcut_widget_size_e si
        GVariant *body;
        char *request_id = NULL;
 
+       CHECK_SHORTCUT_FEATURE();
+
        if (name == NULL) {
                SHORTCUT_ERR("AppID is null\n");
                return SHORTCUT_ERROR_INVALID_PARAMETER;
@@ -296,6 +324,8 @@ EAPI int shortcut_remove_from_home(const char *name, result_cb_t result_cb, void
        GVariant *body;
        char *request_id = NULL;
 
+       CHECK_SHORTCUT_FEATURE();
+
        if (name == NULL) {
                SHORTCUT_ERR("name is NULL.");
                return SHORTCUT_ERROR_INVALID_PARAMETER;
@@ -369,6 +399,8 @@ EAPI int shortcut_get_list(const char *package_name, shortcut_list_cb list_cb, v
        GVariantBuilder *b;
        shortcut_info_s shortcut;
 
+       CHECK_SHORTCUT_FEATURE();
+
        if (list_cb == NULL)
                return SHORTCUT_ERROR_INVALID_PARAMETER;
 
@@ -411,6 +443,7 @@ EAPI int shortcut_get_list(const char *package_name, shortcut_list_cb list_cb, v
 EAPI int add_to_home_shortcut(const char *appid, const char *name, int type, const char *content,
                const char *icon, int allow_duplicate, result_internal_cb_t result_cb, void *data)
 {
+       CHECK_SHORTCUT_FEATURE();
        /*Deprecated API */
        return SHORTCUT_ERROR_NONE;
 }
@@ -419,6 +452,7 @@ EAPI int add_to_home_shortcut(const char *appid, const char *name, int type, con
 /* LCOV_EXCL_START */
 EAPI int add_to_home_dynamicbox(const char *appid, const char *name, int type, const char *content, const char *icon, double period, int allow_duplicate, result_internal_cb_t result_cb, void *data)
 {
+       CHECK_SHORTCUT_FEATURE();
        /*Deprecated API */
        return SHORTCUT_ERROR_NONE;
 }
index 0c80315..2736589 100755 (executable)
@@ -20,6 +20,7 @@ BuildRequires: pkgconfig(vconf)
 BuildRequires: pkgconfig(capi-base-common)
 BuildRequires: pkgconfig(aul)
 BuildRequires: pkgconfig(libtzplatform-config)
+BuildRequires: pkgconfig(capi-system-info)
 
 %define upgrade_script_path /usr/share/upgrade/scripts