Support screen connector 95/100695/15 submit/tizen_3.0/20161212.043612
authorHwankyu Jhun <h.jhun@samsung.com>
Tue, 29 Nov 2016 02:53:10 +0000 (11:53 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Mon, 12 Dec 2016 04:23:39 +0000 (13:23 +0900)
- The aul rsm will be removed.

Change-Id: Ibecb354d45f0c0242f6ad9054c98f030f8c4fff4
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
CMakeLists.txt
include/aul.h
include/aul_cmd.h
include/aul_screen_connector.h [new file with mode: 0644]
packaging/aul.spec
src/aul_screen_connector.c [new file with mode: 0644]
src/launch.c

index 964b525..58979f5 100644 (file)
@@ -15,12 +15,14 @@ ENDIF (with_x11)
 # Set required packages
 INCLUDE(FindPkgConfig)
 SET(AUL-1_LIB_PKG_CHECK_MODULES dlog bundle xdgmime libtzplatform-config pkgmgr-info capi-system-info vconf sqlite3 iniparser gio-2.0 glib-2.0 libxml-2.0 ttrace storage)
+
 IF (with_wayland)
        pkg_check_modules(libpkgs REQUIRED ${AUL-1_LIB_PKG_CHECK_MODULES} wayland-client tizen-extension-client ecore-wayland wayland-tbm-client tizen-remote-surface-client ecore)
 ENDIF (with_wayland)
 IF (with_x11)
        pkg_check_modules(libpkgs REQUIRED ${AUL-1_LIB_PKG_CHECK_MODULES})
 ENDIF (with_x11)
+
 IF(TIZEN_FEATURE_DEFAULT_USER)
        ADD_DEFINITIONS("-DTIZEN_FEATURE_DEFAULT_USER")
 ENDIF(TIZEN_FEATURE_DEFAULT_USER)
@@ -73,6 +75,7 @@ INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/aul_cmd.h DESTINATION include/
 INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/aul_app_com.h DESTINATION include/aul)
 INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/aul_rsm_viewer.h DESTINATION include/aul)
 INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/aul_rsm_provider.h DESTINATION include/aul)
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/aul_screen_connector.h DESTINATION include/aul)
 INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/aul.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
 INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/feature/preexec_list.txt DESTINATION ${SHARE_INSTALL_PREFIX}/aul )
 INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/data/miregex DESTINATION ${SHARE_INSTALL_PREFIX}/aul )
index 394e6d4..f3864e9 100644 (file)
@@ -70,6 +70,7 @@ typedef enum _aul_type {
        AUL_WAKE,
        AUL_SUSPEND,
        AUL_WIDGET_CONTENT,
+       AUL_UPDATE_REQUESTED,
 } aul_type;
 
 typedef enum aul_widget_lifecycle_event {
index 1cedb97..d3df0e6 100644 (file)
@@ -106,6 +106,12 @@ enum app_cmd {
        APP_ENABLE_ALIAS_INFO = 77,
        APP_DISABLE_ALIAS_INFO = 78,
        APP_GROUP_ACTIVATE_ABOVE = 79,
+       ADD_APP_SCREEN = 80,
+
+       REMOVE_APP_SCREEN = 81,
+       UPDATE_APP_SCREEN = 82,
+       ADD_SCREEN_VIEWER = 83,
+       REMOVE_SCREEN_VIEWER = 84,
 
        APP_CMD_MAX
 };
diff --git a/include/aul_screen_connector.h b/include/aul_screen_connector.h
new file mode 100644 (file)
index 0000000..9eb5839
--- /dev/null
@@ -0,0 +1,65 @@
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef __AUL_SCREEN_CONNECTOR_H__
+#define __AUL_SCREEN_CONNECTOR_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef void (*aul_app_screen_added)(const char *appid, const int pid,
+               const unsigned int surface_id, void *data);
+typedef void (*aul_app_screen_removed)(const char *appid, const int pid,
+               void *data);
+
+typedef struct aul_screen_viewer_handler_s {
+       aul_app_screen_added app_added;
+       aul_app_screen_removed app_removed;
+} aul_screen_viewer_handler;
+
+/*
+ * This API is only for Appfw internally.
+ */
+int aul_screen_connector_add_app_screen(unsigned int surf);
+
+/*
+ * This API is only for Appfw internally.
+ */
+int aul_screen_connector_remove_app_screen(void);
+
+/*
+ * This API is only for Appfw internally.
+ */
+int aul_screen_connector_update_app_screen(const char *appid);
+
+/*
+ * This API is only for Appfw internally.
+ */
+int aul_screen_connector_add_screen_viewer(aul_screen_viewer_handler *cbs,
+               void *data);
+
+/*
+ * This API is only for Appfw internally.
+ */
+int aul_screen_connector_remove_screen_viewer(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __AUL_SCREEN_CONNECTOR_H__ */
index 700128f..1b59ac1 100644 (file)
@@ -3,7 +3,7 @@
 
 Name:       aul
 Summary:    App utility library
-Version:    0.0.303
+Version:    0.0.304
 Release:    1
 Group:      Application Framework/Libraries
 License:    Apache-2.0
@@ -32,6 +32,8 @@ BuildRequires:  pkgconfig(iniparser)
 BuildRequires:  pkgconfig(sqlite3)
 BuildRequires:  pkgconfig(storage)
 BuildRequires:  pkgconfig(ttrace)
+BuildRequires:  pkgconfig(pkgmgr-installer)
+BuildRequires:  pkgconfig(libxml-2.0)
 %if %{with wayland}
 BuildRequires:  pkgconfig(ecore)
 BuildRequires:  pkgconfig(ecore-wayland)
@@ -39,8 +41,6 @@ BuildRequires:  pkgconfig(wayland-client)
 BuildRequires:  pkgconfig(wayland-tbm-client)
 BuildRequires:  pkgconfig(tizen-extension-client)
 %endif
-BuildRequires:  pkgconfig(pkgmgr-installer)
-BuildRequires:  pkgconfig(libxml-2.0)
 
 %define upgrade_script_path /usr/share/upgrade/scripts
 
@@ -90,13 +90,13 @@ TIZEN_FEATURE_SOCKET_TIMEOUT=ON
 
 MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'`
 %cmake -DFULLVER=%{version} \
-       -DMAJORVER=${MAJORVER} \
 %if %{with wayland}
        -Dwith_wayland=TRUE \
 %endif
 %if %{with x}
        -Dwith_x11=TRUE \
 %endif
+       -DMAJORVER=${MAJORVER} \
        -DTIZEN_FEATURE_DEFAULT_USER:BOOL=${TIZEN_FEATURE_DEFAULT_USER} \
        -DTIZEN_FEATURE_SOCKET_TIMEOUT:BOOL=${TIZEN_FEATURE_SOCKET_TIMEOUT} \
        .
diff --git a/src/aul_screen_connector.c b/src/aul_screen_connector.c
new file mode 100644 (file)
index 0000000..d7ba58f
--- /dev/null
@@ -0,0 +1,322 @@
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <stdbool.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <glib.h>
+#include <bundle.h>
+#include <bundle_internal.h>
+
+#include "aul_util.h"
+#include "aul_api.h"
+#include "aul.h"
+#include "aul_sock.h"
+#include "aul_app_com.h"
+#include "aul_screen_connector.h"
+
+static aul_app_com_connection_h added_conn;
+static aul_app_com_connection_h removed_conn;
+static bool screen_viewer_initialized;
+static aul_screen_viewer_handler *screen_viewer_handler;
+static void *screen_viewer_data;
+
+static int __add_screen_viewer(void)
+{
+       int ret;
+       bundle *b;
+
+       b = bundle_create();
+       if (b == NULL) {
+               _E("out of memory");
+               return -1;
+       }
+
+       ret = aul_sock_send_bundle(AUL_UTIL_PID, getuid(),
+                       ADD_SCREEN_VIEWER, b, AUL_SOCK_NONE);
+       bundle_free(b);
+       if (ret < 0)
+               return -1;
+
+       return 0;
+}
+
+static int __remove_screen_viewer(void)
+{
+       int ret;
+       bundle *b;
+
+       b = bundle_create();
+       if (b == NULL) {
+               _E("out of memory");
+               return -1;
+       }
+
+       ret = aul_sock_send_bundle(AUL_UTIL_PID, getuid(),
+                       REMOVE_SCREEN_VIEWER, b, AUL_SOCK_NOREPLY);
+       bundle_free(b);
+       if (ret < 0)
+               return -1;
+
+       return 0;
+}
+
+static int __app_screen_added(const char *endpoint, aul_app_com_result_e res,
+               bundle *envelope, void *user_data)
+{
+       char *appid = NULL;
+       unsigned int *surf = NULL;
+       int *pid = NULL;
+       size_t size;
+
+       bundle_get_str(envelope, "__AUL_SC_APPID__", &appid);
+       if (appid == NULL) {
+               _E("Failed to get appid");
+               return -1;
+       }
+
+       bundle_get_byte(envelope, "__AUL_SC_SURFACE__",
+                       (void **)&surf, &size);
+       if (surf == NULL) {
+               _E("Failed to get surface");
+               return -1;
+       }
+
+       bundle_get_byte(envelope, "__AUL_SC_PID__", (void **)&pid, &size);
+       if (pid == NULL) {
+               _E("Failed to get pid");
+               return -1;
+       }
+
+       if (screen_viewer_handler->app_added) {
+               screen_viewer_handler->app_added(appid, *pid, *surf,
+                               screen_viewer_data);
+       }
+       _D("appid(%s), pid(%d), surface(%d)", appid, *pid, *surf);
+
+       return 0;
+}
+
+static int __app_screen_removed(const char *endpoint, aul_app_com_result_e res,
+               bundle *envelope, void *user_data)
+{
+       char *appid = NULL;
+       int *pid = NULL;
+       size_t size;
+
+       bundle_get_str(envelope, "__AUL_SC_APPID__", &appid);
+       if (appid == NULL) {
+               _E("Failed to get appid");
+               return -1;
+       }
+
+       bundle_get_byte(envelope, "__AUL_SC_PID__", (void **)&pid, &size);
+       if (pid == NULL) {
+               _E("Failed to get pid");
+               return -1;
+       }
+
+       if (screen_viewer_handler->app_removed) {
+               screen_viewer_handler->app_removed(appid, *pid,
+                               screen_viewer_data);
+       }
+       _D("appid(%s), pid(%d)", appid, *pid);
+
+       return 0;
+}
+
+static int __screen_viewer_fini(void)
+{
+       int ret;
+
+       if (!screen_viewer_initialized)
+               return 0;
+
+       if (removed_conn) {
+               aul_app_com_leave(removed_conn);
+               removed_conn = NULL;
+       }
+
+       if (added_conn) {
+               aul_app_com_leave(added_conn);
+               added_conn = NULL;
+       }
+
+       ret = __remove_screen_viewer();
+       if (ret < 0) {
+               _E("Failed to remove screen watcher");
+               return -1;
+       }
+
+       screen_viewer_initialized = false;
+
+       return 0;
+}
+
+static int __screen_viewer_init(void)
+{
+       int ret;
+
+       if (screen_viewer_initialized)
+               return 0;
+
+       ret = __add_screen_viewer();
+       if (ret < 0) {
+               _E("Failed to add screen watcher");
+               return -1;
+       }
+
+       aul_app_com_create("app_screen_added", NULL, __app_screen_added,
+                       NULL, &added_conn);
+       if (added_conn == NULL) {
+               _E("Failed to create app com - watch_app_added");
+               __screen_viewer_fini();
+               return -1;
+       }
+
+       aul_app_com_create("app_screen_removed", NULL, __app_screen_removed,
+                       NULL, &removed_conn);
+       if (removed_conn == NULL) {
+               _E("Failed to create app com - watch_app_removed");
+               __screen_viewer_fini();
+               return -1;
+       }
+
+       screen_viewer_initialized = true;
+
+       return 0;
+}
+
+API int aul_screen_connector_add_screen_viewer(aul_screen_viewer_handler *cbs,
+               void *data)
+{
+       if (cbs == NULL) {
+               _E("Invalid parameter");
+               return AUL_R_EINVAL;
+       }
+
+       if (__screen_viewer_init() < 0) {
+               _E("Failed to initialize screen viewer");
+               return AUL_R_ERROR;
+       }
+
+       screen_viewer_handler = cbs;
+       screen_viewer_data = data;
+
+       return AUL_R_OK;
+}
+
+API int aul_screen_connector_remove_screen_viewer(void)
+{
+       if (__screen_viewer_fini() < 0) {
+               _E("Failed to finalize screen viewer");
+               return -1;
+       }
+
+       screen_viewer_handler = NULL;
+       screen_viewer_data = NULL;
+
+       return AUL_R_OK;
+}
+
+API int aul_screen_connector_add_app_screen(unsigned int surf)
+{
+       int ret;
+       bundle *b;
+       char buf[MAX_PID_STR_BUFSZ];
+
+       b = bundle_create();
+       if (b == NULL) {
+               _E("out of memory");
+               return AUL_R_ERROR;
+       }
+
+       snprintf(buf, sizeof(buf), "%d", surf);
+       ret = bundle_add(b, AUL_K_WID, buf);
+       if (ret != BUNDLE_ERROR_NONE) {
+               _E("Failed to add surf");
+               bundle_free(b);
+               return AUL_R_ERROR;
+       }
+
+       ret = aul_sock_send_bundle(AUL_UTIL_PID, getuid(),
+                       ADD_APP_SCREEN, b, AUL_SOCK_NONE);
+       bundle_free(b);
+       if (ret < 0) {
+               _E("Failed to add app screen");
+               return ret;
+       }
+
+       return AUL_R_OK;
+}
+
+API int aul_screen_connector_remove_app_screen(void)
+{
+       int ret;
+       bundle *b;
+
+       b = bundle_create();
+       if (b == NULL) {
+               _E("out of memory");
+               return AUL_R_ERROR;
+       }
+
+       ret = aul_sock_send_bundle(AUL_UTIL_PID, getuid(),
+                       REMOVE_APP_SCREEN, b, AUL_SOCK_NONE);
+       bundle_free(b);
+       if (ret < 0) {
+               _E("Failed to remove app screen");
+               return ret;
+       }
+
+       return AUL_R_OK;
+}
+
+API int aul_screen_connector_update_app_screen(const char *appid)
+{
+       int ret;
+       bundle *b;
+
+       if (appid == NULL) {
+               _E("Invalid parameter");
+               return -1;
+       }
+
+       b = bundle_create();
+       if (b == NULL) {
+               _E("out of memory");
+               return AUL_R_ERROR;
+       }
+
+       ret = bundle_add(b, AUL_K_APPID, appid);
+       if (ret != BUNDLE_ERROR_NONE) {
+               _E("Failed to add appid");
+               bundle_free(b);
+               return AUL_R_ERROR;
+       }
+
+       ret = aul_sock_send_bundle(AUL_UTIL_PID, getuid(),
+                       UPDATE_APP_SCREEN, b, AUL_SOCK_NONE);
+       bundle_free(b);
+       if (ret < 0) {
+               _E("Failed to update app screen");
+               return ret;
+       }
+
+       return AUL_R_OK;
+}
index e3ecea7..10247cf 100644 (file)
@@ -128,6 +128,12 @@ static int app_prepare_to_wake()
        return 0;
 }
 
+static void app_update_requested(void)
+{
+       _D("[UPDATE REQUESTED]");
+       __call_aul_handler(AUL_UPDATE_REQUESTED, NULL);
+}
+
 static int __send_cmd_for_uid_opt(int pid, uid_t uid, int cmd, bundle *kb, int opt)
 {
        int res;
@@ -494,6 +500,9 @@ int aul_sock_handler(int fd)
        case WIDGET_GET_CONTENT:
                widget_get_content(clifd, kbundle);
                break;
+       case UPDATE_APP_SCREEN:
+               app_update_requested();
+               break;
        default:
                _E("no support packet");
        }