add app launcher 88/207488/1
authorAbhay agarwal <ay.agarwal@samsung.com>
Tue, 28 May 2019 14:00:26 +0000 (19:30 +0530)
committersaerome kim <saerome.kim@samsung.com>
Wed, 5 Jun 2019 08:41:07 +0000 (17:41 +0900)
Change-Id: Ie82336dfd5bb8d86174d8805bd45336aec38e7fe
Signed-off-by: Abhay agarwal <ay.agarwal@samsung.com>
12 files changed:
include/ua-api.h
include/ua-internal.h
packaging/ua-manager.spec
ua-api/src/ua-api.c
ua-api/src/ua-event-handler.c
ua-daemon/CMakeLists.txt
ua-daemon/include/ua-manager-common.h
ua-daemon/src/pm/ua-pm-util.c
ua-daemon/src/pm/ua-wifi-plugin-handler.c
ua-daemon/src/ua-manager-core.c
ua-daemon/src/ua-manager-event-sender.c
ua-daemon/src/ua-manager-request-handler.c

index cb85c46..c8453fa 100644 (file)
@@ -42,6 +42,7 @@ extern "C" {
 #define UAM_IP_ADDRESS_MAX_STRING_LEN 50
 #define UAM_USER_NAME_MAX_STRING_LEN 254
 #define UAM_USER_ACCOUNT_MAX_STRING_LEN 254
+#define UAM_APP_ID_MAX_STRING_LEN 100
 
 #define FOREACH_EVENT(EVENT) \
        EVENT(UAM_EVENT_USER_ADDED) \
@@ -119,6 +120,10 @@ int _uam_start_search_active_devices(unsigned int bitmask, int detection_period)
 
 int _uam_stop_search_active_devices(unsigned int bitmask);
 
+int _uam_register_app(const char *app_id, unsigned short uid);
+
+int _uam_deregister_app(const char *app_id, unsigned short uid);
+
 typedef enum {
        UAM_PRESENCE_STATE_INVALID = 0x00,
        UAM_PRESENCE_STATE_PRESENT,
@@ -171,6 +176,12 @@ typedef struct {
        int retries;
 } uam_detection_params_t;
 
+typedef struct {
+       char* sender;
+       unsigned short uid;
+       char app_id[UAM_APP_ID_MAX_STRING_LEN];
+} uam_app_info_t;
+
 int _uam_get_registered_users(GPtrArray **user_list);
 
 int _uam_is_device_registered(
index f472921..6ff05bc 100644 (file)
@@ -61,6 +61,8 @@ extern "C" {
        REQUEST(UAM_REQUEST_SET_DETECTION_PARAMS) \
        REQUEST(UAM_REQUEST_START_SEARCH_ACTIVE_DEVICES) \
        REQUEST(UAM_REQUEST_STOP_SEARCH_ACTIVE_DEVICES) \
+       REQUEST(UAM_REQUEST_REGISTER_APP) \
+       REQUEST(UAM_REQUEST_DEREGISTER_APP) \
        REQUEST(UAM_REQUEST_MAX)
 
 #define GENERATE_REQUEST_ENUM(ENUM) ENUM,
index 91b41b2..2b8eb1d 100644 (file)
@@ -20,6 +20,8 @@ BuildRequires:  pkgconfig(gio-unix-2.0)
 BuildRequires:  pkgconfig(libtzplatform-config)
 BuildRequires:  pkgconfig(sqlite3)
 BuildRequires:  pkgconfig(json-c)
+BuildRequires:  pkgconfig(bundle)
+BuildRequires:  pkgconfig(aul)
 Requires(post): /sbin/ldconfig
 Requires(postun): /sbin/ldconfig
 
index 4a7b354..6b97199 100644 (file)
@@ -809,3 +809,47 @@ UAM_EXPORT_API int _uam_stop_search_active_devices(unsigned int bitmask)
        FUNC_EXIT;
        return ret;
 }
+
+UAM_EXPORT_API int _uam_register_app(const char *app_id, unsigned short uid)
+{
+       FUNC_ENTRY;
+       int ret;
+       uam_app_info_t app_info;
+
+       UAM_INIT_PARAMS();
+       UAM_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
+
+       g_strlcpy(app_info.app_id, app_id, UAM_APP_ID_MAX_STRING_LEN);
+       app_info.uid = uid;
+
+       g_array_append_vals(in_param1, &app_info, sizeof(uam_app_info_t));
+       ret = _uam_sync_request(UAM_REQUEST_REGISTER_APP,
+                       in_param1, in_param2, in_param3, in_param4, &out_param);
+
+       UAM_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
+
+       FUNC_EXIT;
+       return ret;
+}
+
+UAM_EXPORT_API int _uam_deregister_app(const char *app_id, unsigned short uid)
+{
+       FUNC_ENTRY;
+       int ret;
+       uam_app_info_t app_info;
+
+       UAM_INIT_PARAMS();
+       UAM_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
+
+       g_strlcpy(app_info.app_id, app_id, UAM_APP_ID_MAX_STRING_LEN);
+       app_info.uid = uid;
+
+       g_array_append_vals(in_param1, &app_info, sizeof(uam_app_info_t));
+       ret = _uam_sync_request(UAM_REQUEST_DEREGISTER_APP,
+                       in_param1, in_param2, in_param3, in_param4, &out_param);
+
+       UAM_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
+
+       FUNC_EXIT;
+       return ret;
+}
index bf7df72..2e84f3e 100644 (file)
@@ -17,7 +17,6 @@
 
 #include "ua-api.h"
 #include "ua-internal.h"
-
 #include "ua-common.h"
 
 typedef struct {
index f957f4f..bb623bb 100644 (file)
@@ -40,6 +40,8 @@ SET(PKG_MODULES
        libtzplatform-config
        sqlite3
        json-c
+       bundle
+       aul
        )
 
 INCLUDE(FindPkgConfig)
index 836e2a9..c18e543 100644 (file)
@@ -123,6 +123,10 @@ void _uam_remove_timer(guint id);
 
 const char* _uam_get_sensor_str(unsigned int ids);
 
+int _uam_register_app_info(char* sender, uam_app_info_t app_info);
+
+int _uam_deregister_app_info(char* sender, uam_app_info_t app_info);
+
 #ifdef __cplusplus
 }
 #endif
index 08cc0fa..3467ea6 100644 (file)
@@ -310,9 +310,9 @@ uam_device_info_t *_pm_util_uas_dev_info_to_uam_dev_info(const uas_device_info_t
 uam_active_scan_event_e _pm_util_uas_scan_event_to_uam_scan_event(uas_active_scan_event_e event)
 {
        switch (event) {
-       case UAS_ACTIVE_DEVICE_FOUND :
+       case UAS_ACTIVE_DEVICE_FOUND:
                return UAM_ACTIVE_DEVICE_FOUND;
-       case UAS_ACTIVE_SCAN_COMPLETED :
+       case UAS_ACTIVE_SCAN_COMPLETED:
                return UAM_ACTIVE_SCAN_COMPLETED;
        default:
                UAM_WARN("Unknown event 0x%8.8X", event);
index 2c95270..d48c82d 100644 (file)
@@ -115,7 +115,7 @@ static void wifi_active_scan_callback(uas_active_scan_event_e event,
        uam_device_info_t *dev_info = NULL;
        uam_active_scan_event_e event_info;
 
-       if(UAS_ACTIVE_DEVICE_FOUND == event){
+       if (UAS_ACTIVE_DEVICE_FOUND == event) {
                ret_if(NULL == device);
 
                dev_info = _pm_util_uas_dev_info_to_uam_dev_info(device);
index 9236abf..73a0c1a 100644 (file)
@@ -2084,14 +2084,14 @@ int _uam_core_stop_search_active_devices(char *sender, unsigned int sensors)
                if (!scanner || !scanner->name)
                        continue;
 
-               if (scanner->sensors & sensors){
+               if (scanner->sensors & sensors) {
                        ret = _uam_pm_stop_search_active_devices(sensors);
                        if (UAM_ERROR_NONE != ret) {
                                UAM_ERR("Failed with error: %s (0x%4.4X)",
                                        _uam_manager_error_to_str(ret), ret);
                                return ret;
                        }
-                       scanners = g_slist_remove(scanners,scanner);
+                       scanners = g_slist_remove(scanners, scanner);
                        g_free(scanner->name);
                        g_free(scanner);
                }
@@ -2116,12 +2116,12 @@ void _uam_core_handle_active_device(uam_active_scan_event_e event, unsigned int
                if (!scanner || !scanner->name)
                        continue;
 
-               if (scanner->sensors & sensor){
+               if (scanner->sensors & sensor) {
 
                        name = g_strdup(scanner->name);
-                       if(event == UAM_ACTIVE_SCAN_COMPLETED){
+                       if (event == UAM_ACTIVE_SCAN_COMPLETED) {
                                scanner->sensors &= ~(sensor);
-                               if(scanner->sensors == 0){
+                               if (scanner->sensors == 0) {
                                        done = 1;
                                        scanners = g_slist_remove(scanners, scanner);
                                        g_free(scanner->name);
@@ -2132,7 +2132,7 @@ void _uam_core_handle_active_device(uam_active_scan_event_e event, unsigned int
                }
        }
 
-       if(event == UAM_ACTIVE_DEVICE_FOUND){
+       if (event == UAM_ACTIVE_DEVICE_FOUND) {
                param = g_variant_new("(iiisss)",
                                UAM_ERROR_NONE,
                                dev_info->operating_system,
@@ -2144,8 +2144,7 @@ void _uam_core_handle_active_device(uam_active_scan_event_e event, unsigned int
                /* Send device event to application */
                if (UAM_ERROR_NONE != _uam_manager_send_event(name, UAM_EVENT_DEVICE_FOUND, param))
                        UAM_ERR("Failed to send %s", _uam_manager_event_to_str(event));
-       }
-       else if(done == 1 && event == UAM_ACTIVE_SCAN_COMPLETED){
+       } else if (done == 1 && event == UAM_ACTIVE_SCAN_COMPLETED) {
                UAM_INFO_C("Send %s to applications", _uam_manager_event_to_str(UAM_EVENT_SCAN_COMPLETED));
                /* Send device event to application */
                if (UAM_ERROR_NONE != _uam_manager_send_event(name, UAM_EVENT_SCAN_COMPLETED, param))
index 2c064f6..bc8e629 100644 (file)
 
 #include "ua-api.h"
 #include "ua-internal.h"
-
 #include "ua-manager-common.h"
 
+#include <aul.h>
+#include <aul_svc.h>
+#include <bundle_internal.h>
+
+GSList *apps; /* List of apps to launch - uam_app_info_t*/
+
+# define APP_CONTROL_DATA_PUSH_LAUNCH_TYPE "http://tizen.org/appcontrol/data/push/launch_type"
+# define EXTRA_DATA_FROM_REGISTRATION_CHANGE "registration_change"
+
+static void __uam_app_launcher(uam_app_info_t *app_info)
+{
+       FUNC_ENTRY;
+       int r = 0;
+
+       r = aul_app_get_status_for_uid((const char *)app_info->app_id, app_info->uid);
+       UAM_INFO("returned r: [%d] ", r);
+       if (r == -1) {
+               /* Send launch request to wake application */
+               UAM_INFO("[%s] will be launched for receiving registration change callback", (const char*)app_info->app_id);
+
+               bundle *bund = NULL;
+               bund = bundle_create();
+
+               bundle_add(bund, APP_CONTROL_DATA_PUSH_LAUNCH_TYPE, EXTRA_DATA_FROM_REGISTRATION_CHANGE);
+
+               int result;
+               result = aul_svc_set_background_launch(bund, TRUE);
+               if (result < AUL_R_OK)
+                       UAM_ERR("ERROR : aul_svc_set_background_launch failed. app_id [%s] bundle[%p] result[%d : %s]", app_info->app_id, bund, result, get_error_message(result));
+
+               result = aul_launch_app_async_for_uid(app_info->app_id, bund, app_info->uid);
+               if (result < AUL_R_OK)
+                       UAM_ERR("ERROR : aul_launch_app failed. app_id [%s] bundle[%p] result[%d : %s]", app_info->app_id, bund, result, get_error_message(result));
+
+               bundle_free(bund);
+       }
+       FUNC_EXIT;
+}
+
+static void __uam_resume_app(const char* dest)
+{
+       FUNC_ENTRY;
+       GSList *l;
+
+       UAM_INFO("dest: [%s] ", dest);
+       if (NULL == dest) {
+               for (l = apps; NULL != l; l = g_slist_next(l)) {
+                       uam_app_info_t *app_info = l->data;
+                       if (NULL == app_info)
+                               continue;
+
+                       UAM_INFO("app_id: [%s] ", (const char*)app_info->app_id);
+                       UAM_INFO("uid: [%d] ", app_info->uid);
+                       __uam_app_launcher(app_info);
+               }
+       } else {
+               for (l = apps; NULL != l; l = g_slist_next(l)) {
+                       uam_app_info_t *app_info = l->data;
+                       if (NULL == app_info)
+                               continue;
+
+                       UAM_INFO("app_id: [%s] ", (const char*)app_info->app_id);
+                       UAM_INFO("uid: [%d] ", app_info->uid);
+                       if (!g_strcmp0(app_info->sender, dest)) {
+                               __uam_app_launcher(app_info);
+                               break;
+                       }
+               }
+       }
+
+       FUNC_EXIT;
+}
+
 int _uam_manager_send_event(
                const char* dest, int event, GVariant *param)
 {
@@ -82,6 +154,9 @@ int _uam_manager_send_event(
        UAM_INFO_C("Destination: [%s], event: [%s], signal: [%s]",
                        dest, _uam_manager_event_to_str(event), signal);
 
+       /* Check if application requires resume before sending event */
+       __uam_resume_app(dest);
+
        if (!g_dbus_connection_emit_signal(conn, dest, UAM_EVENT_PATH,
                                UAM_EVENT_INTERFACE, signal, param, &error)) {
                UAM_ERR("Error while sending Signal: %s", signal);
@@ -97,3 +172,81 @@ int _uam_manager_send_event(
        FUNC_EXIT;
        return UAM_ERROR_NONE;
 }
+
+static uam_app_info_t *__uam_find_app(const char *name)
+{
+//     FUNC_ENTRY;
+       GSList *l;
+
+       retv_if(NULL == name, NULL);
+
+       for (l = apps; NULL != l; l = g_slist_next(l)) {
+               uam_app_info_t *app_info = l->data;
+
+               if (!app_info || !app_info->sender)
+                       continue;
+
+               if (0 == g_strcmp0(app_info->sender, name)) {
+                       UAM_DBG("Monitoring application found in list");
+                       return app_info;
+               }
+       }
+
+//     FUNC_EXIT;
+       return NULL;
+}
+
+int _uam_register_app_info(char* sender, uam_app_info_t app_info)
+{
+       FUNC_ENTRY;
+
+       int ret;
+       uam_app_info_t *app;
+
+       app = __uam_find_app(sender);
+
+       if (app) {
+               ret = UAM_ERROR_ALREADY_DONE;
+               UAM_ERR("Failed with error: %s (0x%4.4X)",
+                       _uam_manager_error_to_str(ret), ret);
+               return ret;
+       }
+
+       app = g_malloc0(sizeof(uam_app_info_t));
+       app->sender = g_strdup(sender);
+       g_strlcpy(app->app_id, app_info.app_id, UAM_APP_ID_MAX_STRING_LEN);
+       app->uid = app_info.uid;
+
+       apps = g_slist_append(apps, app);
+       ret = UAM_ERROR_NONE;
+
+       FUNC_EXIT;
+       return ret;
+}
+
+int _uam_deregister_app_info(char* sender, uam_app_info_t app_info)
+{
+       FUNC_ENTRY;
+
+       int ret;
+       uam_app_info_t *app;
+
+       app = __uam_find_app(sender);
+
+       if (!app) {
+               ret = UAM_ERROR_ALREADY_DONE;
+               UAM_ERR("Failed with error: %s (0x%4.4X)",
+                       _uam_manager_error_to_str(ret), ret);
+               return ret;
+       }
+
+       UAM_DBG("Remove app from list");
+       apps = g_slist_remove(apps, app);
+       g_free(app->sender);
+       g_free(app);
+
+       ret = UAM_ERROR_NONE;
+
+       FUNC_EXIT;
+       return ret;
+}
index 8435c78..9d515e9 100644 (file)
@@ -412,6 +412,24 @@ static int __uam_manager_sync_request_handler(
                result = _uam_core_stop_search_active_devices(sender, sensors);
                break;
        }
+       case UAM_REQUEST_REGISTER_APP: {
+               uam_app_info_t app_info;
+
+               __uam_manager_copy_params(in_param1,
+                               &app_info, sizeof(uam_app_info_t));
+
+               result = _uam_register_app_info(sender, app_info);
+               break;
+       }
+       case UAM_REQUEST_DEREGISTER_APP: {
+               uam_app_info_t app_info;
+
+               __uam_manager_copy_params(in_param1,
+                               &app_info, sizeof(uam_app_info_t));
+
+               result = _uam_deregister_app_info(sender, app_info);
+               break;
+       }
        default:
                UAM_WARN("UnSupported function [%s(0x%4.4X)]",
                                _uam_manager_request_to_str(function), function);
@@ -545,6 +563,8 @@ static gboolean __uam_manager_is_sync_function(int function)
        case UAM_REQUEST_SET_DETECTION_PARAMS:
        case UAM_REQUEST_START_SEARCH_ACTIVE_DEVICES:
        case UAM_REQUEST_STOP_SEARCH_ACTIVE_DEVICES:
+       case UAM_REQUEST_REGISTER_APP:
+       case UAM_REQUEST_DEREGISTER_APP:
                return TRUE;
        default:
                return FALSE;