Merge from 2.3b
authorhyun lee <hyunn.lee@samsung.com>
Thu, 13 Nov 2014 02:31:04 +0000 (11:31 +0900)
committerhyun lee <hyunn.lee@samsung.com>
Thu, 13 Nov 2014 02:31:04 +0000 (11:31 +0900)
Change-Id: Ib56027715d873cf3ed80fc8f1395eb5dfc86a4d2
Signed-off-by: hyun lee <hyunn.lee@samsung.com>
doc/shortcut_doc.h
doc_prod/shortcut_doc.h
lib/CMakeLists.txt
lib/include/shortcut_manager.h
lib/src/main.c
packaging/libshortcut.spec

index 6469494..2ac1878 100755 (executable)
 
 /**
  * @defgroup SHORTCUT_MODULE Shortcut
- * @brief To enhance the Add to home feature. Two types of API sets are supported.
- *   - One for the homescreen developers.
+ * @brief To enhance the Add to home feature.
  *   - The other for the application developers who should implement the Add to home feature.
  * @ingroup CAPI_APPLICATION_FRAMEWORK 
  * @section SHORTCUT_MODULE_HEADER Required Header
- *   \#include <shortcut.h>
+ *   \#include <shortcut_manager.h>
  * @section SHORTCUT_MODULE_OVERVIEW Overview
-<H1>1. Shortcut</H1>
-Tizen is supporting the "add shortcut or add to home" for various applications.
-Developers may use the shortcut library (libshortcut) to implement features like sending (applications) and receiving (possibly home screen) shortcuts.
-If home screen implements the shortcut service using the library, the applications are good to go for adding their shortcuts to the home screen(, and vice versa.)
-
-<H1>2. How to add a new shortcut to the home screen</H1>
-<H2>2.1 Add to home (From the app to home)</H2>
-
-The following are two separate APIs to support the "add to home" feature. 
-\code
-typedef int (*result_cb_t)(int ret, void *data)
-
-extern int shortcut_add_to_home(const char *name, shortcut_type type, const char *uri, const char *icon, int allow_duplicate, result_cb_t result_cb, void *data)
-\endcode
-
-Currently, our home screen can contain two different types of contents (that are pure shortcuts).
-
-To add a pure shortcut i.e., simply for launching an app, developers can use the "shortcut_add_to_home" API to deliver their shortcuts to a home screen.
-
-<TABLE>
-<TR><TH>Parameters</TH><TH>Comment</TH></TR>
-<TR><TD>name</TD><TD>Application name which will be displayed on the screen</TD></TR>
-<TR><TD>type</TD><TD>Basically it describes launching options whether to use a package name or URI. LAUNCH_BY_APP or LAUNCH_BY_URI</TD></TR>
-<TR><TD>content</TD><TD>
-Application data used for creating a pure shortcut
-
-    Shortcut
-
-1. If the type is Launch by app: None
-
-2. If the type is Launch by URI: Put the URI in the content
-
-<H3>2.1.1 Supported types</H3>
-shortcut.h Enumeration values for type of shortcuts
-
-<H2>2.2 Add shortcut (Home screen retrieves shortcuts from the app)</H2>
-"Add shortcut " service enables home screen to retrieve all shortcuts that applications promised to support and request an app to send their shortcuts to home directly, as opposed to "add to home".
-
-It is initiated by the home screen as opposed to "add to home" which is initiated by an application.The "Add shortcut" service enables the home screen to retrieve all shortcuts that applications promised to support and request an app to send their shortcuts to home directly, as opposed to "add to home".
-
-It is initiated by the home screen as opposed to "add to home" which is initiated by an application.
-
-<H3>2.2.1 Build the shortcut list DB</H3>
-\image html BuildShortcutList.png
-
-To recognize how many and what kinds of shortcuts have been registered, each application who wants to support the "add shortcut" service needs to install the XML file that defines "shortcut" information.
-The following table describes the format and information necessary to define the shortcuts application can support.
-Then, the information will be shown and used in home screen when a user selects "add shortcut" service.
-
-<TABLE>
-<caption>Syntax of the shortcut manifest file</caption>
-<TR><TD>
-\code
-<manifest xmlns="http://tizen.org/ns/packages" package="com.samsung.APP_PKGNAME">
-...
-    <shortcut-list>
-        <shortcut appid="com.samsung.myapp" extra_key="key_string" extra_data="data_string_for_key">
-           <icon>/opt/share/icons/default/small/com.samsung.myapp-shortcut.png</icon>
-           <label>Default name</label>
-           <label xml:lang="en-us">Name en</label>
-           <label xml:lang="nl-nl">Name nl</label>
-           <label xml:lang="de-de">Name de</label>
-           <label xml:lang="zh-hk">Name hk</label>
-           <label xml:lang="zh-cn">Name cn</label>
-           <label xml:lang="ru-ru">Name ru</label>
-           <label xml:lang="zh-tw">Name tw</label>
-           <label xml:lang="ja-jp">Name jp</label>
-           <label xml:lang="es-es">Name es</label>
-           <label xml:lang="el-gr">Name gr</label>
-           <label xml:lang="it-it">Name it</label>
-           <label xml:lang="tr-tr">Name tr</label>
-           <label xml:lang="pt-pt">Name pt</label>
-           <label xml:lang="fr-fr">Name fr</label>
-           <label xml:lang="ko-kr">Name kr</label>
-        </shortcut>
-        <shortcut appid="com.samsung.myapp" extra_key="key_string" extra_data="data_string_for_key">
-           <label>Default name</label>
-        </shortcut>
-        ...
-        <shortcut appid="com.samsung.myapp" extra_key="key_string" extra_data="data_string_for_key">
-           <label>Default name</label>
-           <icon>/opt/share/icons/default/small/com.samsung.myapp2.png</icon>
-        </shortcut>
-    </shortcut-list>
-...
-</manifest>
-\endcode
-</TD></TR>
-</TABLE>
-
-Install this XML file to /opt/share/packages/YOUR_PKGNAME.xml (Note: After manifest has been applied to the binary, simply copy the content to your manifest file.)
-The shortcut listing application will list up these items on its screen and each item will be displayed using the string in the label field.
-When selected, it will launch the selected app using app service with "appid" and a bundle holding data in the pair of extra_key and extra-data fields.
-Obviously, icon will be used to display visual information for given shortcut type.(that said the icon could be other than the application's default icon)
-
-<H3>2.2.2 Jump to the APP</H3>
-\image html JumpToApp.png
-
-The shortcut listing application will launch your application using app-svc with package name and param attributes.
-It will use the pkgname and param attrbute to launch your application.
-The shortcut list view will launch your "[App] Shortcut list" using the following code.
-
-When your app is launched, the app should send a selected item as a shortcut to the home screen using "shortcut_add" series functions mentioned above.
-
-<H3>2.2.3 What each app has to do</H3>
-You can implement your shortcut list view using App or UG.
-
-Who is going to handle the shortcut
-
-<UL>
-<LI>Handled by App
-       <LI>App should prepare a shortcut-add view as guided</LI>
-</LI>
-<LI>Handeld by UG
-       <LI>UG should be launched as an app and provide the shortcut-add view</LI>
-</LI>
-</UL>
-
-In your shortcut list view, you just call the "shortcut_add_to_home" which is described in the section 2.1
-
-<H4>2.2.3.1 Handled by App</H4>
-\image html ShortcutApp.png
-When your application is launched by the shortcut list application (displayed on the left most of above figure).
-Your application should go back to the normal view when you receive the PAUSE event.
-If you didn't change the view of your application, the user will see this shortcut list view again even if the user
-launches your application from the app-tray(or homescreen).
-So you have to change the view from the shortcut list to the normal(or previous) view when you get the PAUSE event.
-
-<H4>2.2.3.2 Handled by UG</H4>
-\image html ShortcutUG.png
-In this case, the Shortcut List application will launch your UG as a process.
-When you receive PAUSE event, or need to change to other view (not in the same UG), you should destroy current UG.
-If you didn't destroy it, it will be reside on the process list. and it will not be destroyed automatically.
-
-Currently, the UG container process only supports multiple instance for a process.
-So if the user tries to add a new shortcut again from the shortcut list application, your UG will be launched again if you didn't
-terminate previous UG process (when you got PAUSE event).
+It provides function of creating shortcut.
+Developers can use the "shortcut_add_to_home" API to create their shortcut to a home screen.
  *
  */
 
index 6469494..5f360c6 100755 (executable)
@@ -85,7 +85,7 @@ Then, the information will be shown and used in home screen when a user selects
 ...
     <shortcut-list>
         <shortcut appid="com.samsung.myapp" extra_key="key_string" extra_data="data_string_for_key">
-           <icon>/opt/share/icons/default/small/com.samsung.myapp-shortcut.png</icon>
+           <icon>com.samsung.myapp-shortcut.png</icon>
            <label>Default name</label>
            <label xml:lang="en-us">Name en</label>
            <label xml:lang="nl-nl">Name nl</label>
@@ -109,7 +109,7 @@ Then, the information will be shown and used in home screen when a user selects
         ...
         <shortcut appid="com.samsung.myapp" extra_key="key_string" extra_data="data_string_for_key">
            <label>Default name</label>
-           <icon>/opt/share/icons/default/small/com.samsung.myapp2.png</icon>
+           <icon>com.samsung.myapp2.png</icon>
         </shortcut>
     </shortcut-list>
 ...
index 4444b43..c4abdaf 100755 (executable)
@@ -19,6 +19,7 @@ pkg_check_modules(svc_pkgs REQUIRED
        com-core
        vconf
        capi-base-common
+       aul
 )
 
 FOREACH(flag ${svc_pkgs_CFLAGS})
index 685e7b5..5cbab0b 100755 (executable)
@@ -48,7 +48,7 @@ typedef int (*result_cb_t)(int ret, void *data);
 
 /**
  * @brief Enumeration for shortcut types.
- * @details Basically, three types of shortcuts are defined.
+ * @details Basically, two types of shortcuts are defined.
  *          Every homescreen developer should support these types of shortcuts.
  *          Or return a proper errno to figure out why the application failed to add a shortcut.
  *          #LAUNCH_BY_APP is used for adding a package itself as a shortcut.
@@ -113,7 +113,7 @@ enum shortcut_error_e {
  * @retval #SHORTCUT_ERROR_IO_ERROR I/O error
  * @retval #SHORTCUT_ERROR_PERMISSION_DENIED Permission denied
  * @retval #SHORTCUT_ERROR_NOT_SUPPORTED Not supported
- * @retval #SHORTCUT_ERROR_BUSY Device or resource busy
+ * @retval #SHORTCUT_ERROR_RESOURCE_BUSY Device or resource busy
  * @retval #SHORTCUT_ERROR_NO_SPACE No space
  * @retval #SHORTCUT_ERROR_EXIST Already exist
  * @retval #SHORTCUT_ERROR_FAULT Unrecoverable error
@@ -129,7 +129,7 @@ enum shortcut_error_e {
  * @code
  *
  * #include <stdio.h>
- * #include <shortcut.h>
+ * #include <shortcut_manager.h>
  *
  * static int result_cb(int ret, int pid, void *data)
  * {
@@ -142,9 +142,18 @@ enum shortcut_error_e {
  *
  * static int app_create(void *data)
  * {
+ *     char* data_path = app_get_data_path();
+ *     int path_len = strlen(data_path)+10;
+ *     char * path = malloc(path_len);
+ *     memset(path, 0, path_len);
+ *     strncat(path, data_path, path_len);
+ *     strncat(path, "Friend.jpg", path_len); 
+ *
  *     shortcut_add_to_home("With friends",
  *                                     LAUNCH_BY_URI, "gallery:0000-0000",
- *                                     "/opt/media/Pictures/Friends.jpg", 0, result_cb, NULL);
+ *                                     path, 0, result_cb, NULL);
+ *     free(path);
+ *
  *     return 0;
  * }
  *
index 23dbe83..92d9966 100755 (executable)
@@ -24,6 +24,7 @@
 #include <sys/ioctl.h>
 #include <libgen.h>
 
+#include <aul.h>
 #include <dlog.h>
 #include <glib.h>
 #include <db-util.h>
@@ -37,6 +38,9 @@
 #include "shortcut.h"
 #include "shortcut_product.h"
 #include "shortcut_private.h"
+#include "shortcut_manager.h"
+
+#define SHORTCUT_PKGNAME_LEN 512
 
 int errno;
 
@@ -211,6 +215,23 @@ static void master_started_cb(keynode_t *node, void *user_data)
 
 
 
+int shortcut_is_master_ready(void)
+{
+       int ret = -1, is_master_started = 0;
+
+       ret = vconf_get_bool(VCONFKEY_MASTER_STARTED, &is_master_started);
+       if (ret == 0 && is_master_started == 1) {
+               ErrPrint("the master has been started");
+       } else {
+               is_master_started = 0;
+               ErrPrint("the master has been stopped");
+       }
+
+       return is_master_started;
+}
+
+
+
 static gboolean timeout_cb(void *data)
 {
        int ret;
@@ -314,6 +335,54 @@ static inline int make_connection(void)
 
 
 
+static char *_shortcut_get_pkgname_by_pid(void)
+{
+       char pkgname[SHORTCUT_PKGNAME_LEN + 1] = { 0, };
+       int pid = 0, ret = 0;
+       int fd;
+       char  *dup_pkgname;
+
+       pid = getpid();
+
+       ret = aul_app_get_pkgname_bypid(pid, pkgname, sizeof(pkgname));
+       if (ret != 0) {
+               char buf[SHORTCUT_PKGNAME_LEN + 1] = { 0, };
+
+               snprintf(buf, sizeof(buf), "/proc/%d/cmdline", pid);
+
+               fd = open(buf, O_RDONLY);
+               if (fd < 0) {
+                       return NULL;
+               }
+
+               ret = read(fd, pkgname, sizeof(pkgname) - 1);
+               close(fd);
+
+               if (ret <= 0) {
+                       return NULL;
+               }
+
+               pkgname[ret] = '\0';
+               /*!
+                * \NOTE
+                * "ret" is not able to be larger than "sizeof(pkgname) - 1",
+                * if the system is not going wrong.
+                */
+       } else {
+               if (strlen(pkgname) <= 0) {
+                       return NULL;
+               }
+       }
+
+       dup_pkgname = strdup(pkgname);
+       if (!dup_pkgname)
+               ErrPrint("Heap: %s\n", strerror(errno));
+
+       return dup_pkgname;
+}
+
+
+
 EAPI int shortcut_set_request_cb(request_cb_t request_cb, void *data)
 {
        if (request_cb == NULL) {
@@ -343,7 +412,8 @@ EAPI int shortcut_set_request_cb(request_cb_t request_cb, void *data)
 
 
 struct result_cb_item {
-       result_internal_cb_t result_cb;
+       result_internal_cb_t result_internal_cb;
+       result_cb_t result_cb;
        void *data;
 };
 
@@ -362,8 +432,10 @@ static int shortcut_send_cb(pid_t pid, int handle, const struct packet *packet,
                ret = SHORTCUT_ERROR_INVALID_PARAMETER;
        }
 
-       if (item->result_cb) {
-               ret = item->result_cb(ret, pid, item->data);
+       if (item->result_internal_cb) {
+               ret = item->result_internal_cb(ret, pid, item->data);
+       } else if (item->result_cb) {
+               ret = item->result_cb(ret, item->data);
        } else {
                ret = SHORTCUT_ERROR_NONE;
        }
@@ -410,7 +482,8 @@ EAPI int add_to_home_remove_shortcut(const char *appid, const char *name, const
                return SHORTCUT_ERROR_OUT_OF_MEMORY;
        }
 
-       item->result_cb = result_cb;
+       item->result_internal_cb = result_cb;
+       item->result_cb = NULL;
        item->data = data;
 
        packet = packet_create("rm_shortcut", "isss", getpid(), appid, name, content_info);
@@ -472,7 +545,8 @@ EAPI int add_to_home_remove_dynamicbox(const char *appid, const char *name, resu
                return SHORTCUT_ERROR_OUT_OF_MEMORY;
        }
 
-       item->result_cb = result_cb;
+       item->result_internal_cb = result_cb;
+       item->result_cb = NULL;
        item->data = data;
 
        packet = packet_create("rm_dynamicbox", "iss", getpid(), appid, name);
@@ -533,7 +607,8 @@ EAPI int add_to_home_shortcut(const char *appid, const char *name, int type, con
                return SHORTCUT_ERROR_OUT_OF_MEMORY;
        }
 
-       item->result_cb = result_cb;
+       item->result_internal_cb = result_cb;
+       item->result_cb = NULL;
        item->data = data;
 
        if (!name) {
@@ -569,7 +644,81 @@ EAPI int add_to_home_shortcut(const char *appid, const char *name, int type, con
 
 EAPI int shortcut_add_to_home(const char *name, shortcut_type type, const char *uri, const char *icon, int allow_duplicate, result_cb_t result_cb, void *data)
 {
-       return 0;
+       struct packet *packet;
+       struct result_cb_item *item;
+       char *appid = NULL;
+       int ret;
+
+       if (ADD_TO_HOME_IS_DYNAMICBOX(type)) {
+               ErrPrint("Invalid type used for adding a shortcut\n");
+               return SHORTCUT_ERROR_INVALID_PARAMETER;
+       }
+
+       appid = _shortcut_get_pkgname_by_pid();
+
+       if (!s_info.initialized) {
+               s_info.initialized = 1;
+               com_core_add_event_callback(CONNECTOR_DISCONNECTED, disconnected_cb, NULL);
+       }
+
+       if (s_info.client_fd < 0) {
+               static struct method service_table[] = {
+                       {
+                               .cmd = NULL,
+                               .handler = NULL,
+                       },
+               };
+
+               s_info.client_fd = com_core_packet_client_init(s_info.socket_file, 0, service_table);
+               if (s_info.client_fd < 0) {
+                       if (shortcut_is_master_ready() == 1) {
+                               return SHORTCUT_ERROR_PERMISSION_DENIED;
+                       }
+                       else {
+                               return SHORTCUT_ERROR_COMM;
+                       }
+               }
+       }
+
+       item = malloc(sizeof(*item));
+       if (!item) {
+               ErrPrint("Heap: %s\n", strerror(errno));
+               return SHORTCUT_ERROR_OUT_OF_MEMORY;
+       }
+
+       item->result_cb = result_cb;
+       item->result_internal_cb = NULL;
+       item->data = data;
+
+       if (!name) {
+               name = "";
+       }
+
+       if (!uri) {
+               uri = "";
+       }
+
+       if (!icon) {
+               icon = "";
+       }
+
+       packet = packet_create("add_shortcut", "ississi", getpid(), appid, name, type, uri, icon, allow_duplicate);
+       if (!packet) {
+               ErrPrint("Failed to build a packet\n");
+               free(item);
+               return SHORTCUT_ERROR_FAULT;
+       }
+
+       ret = com_core_packet_async_send(s_info.client_fd, packet, 0.0f, shortcut_send_cb, item);
+       if (ret < 0) {
+               packet_destroy(packet);
+               free(item);
+               com_core_packet_client_fini(s_info.client_fd);
+               s_info.client_fd = SHORTCUT_ERROR_INVALID_PARAMETER;
+               return SHORTCUT_ERROR_COMM;
+       }
+
+       return SHORTCUT_ERROR_NONE;
 }
 
 
@@ -609,7 +758,8 @@ EAPI int add_to_home_dynamicbox(const char *appid, const char *name, int type, c
                return SHORTCUT_ERROR_OUT_OF_MEMORY;
        }
 
-       item->result_cb = result_cb;
+       item->result_internal_cb = result_cb;
+       item->result_cb = NULL;
        item->data = data;
 
        packet = packet_create("add_dynamicbox", "ississdi", getpid(), appid, name, type, content, icon, period, allow_duplicate);
index 465cd43..a69863f 100755 (executable)
@@ -19,6 +19,7 @@ BuildRequires: pkgconfig(com-core)
 BuildRequires: pkgconfig(libxml-2.0)
 BuildRequires: pkgconfig(vconf)
 BuildRequires: pkgconfig(capi-base-common)
+BuildRequires: pkgconfig(aul)
 
 %description
 [Shortcut] AddToHome feature supporting library for menu/home screen developers.