Remove Profile Build Dependency: Do it at runtime 39/98139/6
authorMyungJoo Ham <myungjoo.ham@samsung.com>
Wed, 16 Nov 2016 08:17:18 +0000 (17:17 +0900)
committerSemun Lee <sm79.lee@samsung.com>
Mon, 16 Jan 2017 07:31:34 +0000 (23:31 -0800)
- This is for Tizen 4.0.

  : Tizen 4.0 Configurability and Build Blocks require
  to remove all profile-depending build options in spec files.
  (No More profile macros!)

- It is recommended to distinguish features/profiles at runtime.
 unless it incurs too much overhead, which requires you to
 create multiple binaries and subpackages.

Change-Id: Ia70c909b3dee7c6af6b34037f3e73dab5031c9f9
Signed-off-by: MyungJoo Ham <myungjoo.ham@samsung.com>
CMakeLists.txt
packaging/appcore-agent.spec
src/appcore-agent.c

index e84dc0f..9376f91 100644 (file)
@@ -11,17 +11,13 @@ SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
 
 SET(CMAKE_SKIP_BUILD_RPATH TRUE)
 
-IF(_TIZEN_FEATURE_BACKGROUND_MANAGEMENT)
-       ADD_DEFINITIONS("-DTIZEN_FEATURE_BACKGROUND_MANAGEMENT")
-ENDIF(_TIZEN_FEATURE_BACKGROUND_MANAGEMENT)
-
 #################################################################
 # Build appcore-agent Library
 # ------------------------------
 SET(APPCORE_AGENT "appcore-agent")
 
 INCLUDE(FindPkgConfig)
-pkg_check_modules(pkg_agent REQUIRED aul dlog capi-appfw-app-control capi-appfw-app-common vconf ecore vconf-internal-keys appcore-common)
+pkg_check_modules(pkg_agent REQUIRED aul dlog capi-appfw-app-control capi-appfw-app-common vconf ecore vconf-internal-keys appcore-common capi-system-info)
 FOREACH(flag ${pkg_agent_CFLAGS})
        SET(EXTRA_CFLAGS_agent "${EXTRA_CFLAGS_agent} ${flag}")
 ENDFOREACH(flag)
@@ -44,4 +40,4 @@ INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/capi-appfw-service-application.pc DEST
 INSTALL(DIRECTORY ${CMAKE_SOURCE_DIR}/include/ DESTINATION include/appcore-agent/
        FILES_MATCHING
        PATTERN "*.h"
-       )
\ No newline at end of file
+       )
index 82289a5..e321c10 100644 (file)
@@ -10,6 +10,7 @@ BuildRequires:  cmake
 BuildRequires:  pkgconfig(aul)
 BuildRequires:  pkgconfig(capi-appfw-app-control)
 BuildRequires:  pkgconfig(capi-appfw-app-common)
+BuildRequires:  pkgconfig(capi-system-info)
 BuildRequires:  pkgconfig(appcore-common)
 BuildRequires:  pkgconfig(dlog)
 BuildRequires:  pkgconfig(ecore)
@@ -19,18 +20,6 @@ BuildRequires:  pkgconfig(vconf-internal-keys)
 %description
 Service Application basic
 
-%if "%{?profile}" == "wearable"
-%define tizen_feature_background_management 1
-%else
-%if "%{?profile}" == "mobile"
-%define tizen_feature_background_management 1
-%else
-%if "%{?profile}" == "tv"
-%define tizen_feature_background_management 0
-%endif
-%endif
-%endif
-
 %package devel
 Summary:        Application Core Agent
 Group:          Application Framework/Development
@@ -53,14 +42,9 @@ cp %{SOURCE1001} .
 
 %build
 
-%if 0%{?tizen_feature_background_management}
-_TIZEN_FEATURE_BACKGROUND_MANAGEMENT=ON
-%endif
-
 MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'`
 
 %cmake -DFULLVER=%{version} -DMAJORVER=${MAJORVER} \
-       -D_TIZEN_FEATURE_BACKGROUND_MANAGEMENT:BOOL=${_TIZEN_FEATURE_BACKGROUND_MANAGEMENT} \
        .
 %__make %{?_smp_mflags}
 
index df898ea..591eaac 100644 (file)
 #include <app_control_internal.h>
 #include <dlog.h>
 #include <vconf.h>
+#include <system_info.h>
 
 #include "appcore-agent.h"
 
-#ifdef TIZEN_FEATURE_BACKGROUND_MANAGEMENT
 #include <gio/gio.h>
 
 #define RESOURCED_FREEZER_PATH "/Org/Tizen/Resourced/Freezer"
@@ -52,8 +52,6 @@
 #define APPFW_SUSPEND_HINT_INTERFACE "org.tizen.appfw.SuspendHint"
 #define APPFW_SUSPEND_HINT_SIGNAL "SuspendHint"
 
-#endif
-
 #ifdef LOG_TAG
 #undef LOG_TAG
 #endif
 #define APPID_MAX 256
 #define PATH_LOCALE "locale"
 
+
+typedef enum {
+       TIZEN_PROFILE_UNKNOWN = 0,
+       TIZEN_PROFILE_MOBILE = 0x1,
+       TIZEN_PROFILE_WEARABLE = 0x2,
+       TIZEN_PROFILE_TV = 0x4,
+       TIZEN_PROFILE_IVI = 0x8,
+       TIZEN_PROFILE_COMMON = 0x10,
+} tizen_profile_t;
+
+static tizen_profile_t _get_tizen_profile()
+{
+       static tizen_profile_t profile = TIZEN_PROFILE_UNKNOWN;
+       char *profileName;
+
+       if (__builtin_expect(profile != TIZEN_PROFILE_UNKNOWN, 1))
+               return profile;
+
+       system_info_get_platform_string("http://tizen.org/feature/profile", &profileName);
+       switch (*profileName) {
+       case 'm':
+       case 'M':
+               profile = TIZEN_PROFILE_MOBILE;
+               break;
+       case 'w':
+       case 'W':
+               profile = TIZEN_PROFILE_WEARABLE;
+               break;
+       case 't':
+       case 'T':
+               profile = TIZEN_PROFILE_TV;
+               break;
+       case 'i':
+       case 'I':
+               profile = TIZEN_PROFILE_IVI;
+               break;
+       default: // common or unknown ==> ALL ARE COMMON.
+               profile = TIZEN_PROFILE_COMMON;
+       }
+       free(profileName);
+
+       return profile;
+}
+#define TIZEN_FEATURE_BACKGROUND_MANAGEMENT (_get_tizen_profile() & (TIZEN_PROFILE_MOBILE | TIZEN_PROFILE_WEARABLE))
+
 static pid_t _pid;
 
 /**
@@ -265,16 +308,13 @@ static struct evt_ops evtops[] = {
         },
 };
 
-#ifdef TIZEN_FEATURE_BACKGROUND_MANAGEMENT
 static GDBusConnection *bus = NULL;
 static guint __suspend_dbus_handler_initialized = 0;
-#endif
 
 extern int app_control_create_event(bundle *data, struct app_control_s **app_control);
 static int __sys_do(struct agent_appcore *ac, void *event_info, enum sys_event event);
 
 /* LCOV_EXCL_START */
-#ifdef TIZEN_FEATURE_BACKGROUND_MANAGEMENT
 static int appcore_agent_flush_memory(void)
 {
        int (*flush_fn) (int);
@@ -307,27 +347,25 @@ static void __prepare_to_suspend(void *data)
                ac->suspended_state = true;
        }
 }
-#endif
 /* LCOV_EXCL_STOP */
 
 /* LCOV_EXCL_START */
 static void __exit_from_suspend(void *data)
 {
-#ifdef TIZEN_FEATURE_BACKGROUND_MANAGEMENT
-       int suspend = APPCORE_AGENT_SUSPENDED_STATE_DID_EXIT_FROM_SUSPEND;
-       struct agent_appcore *ac = data;
-
-       if (ac && !ac->allowed_bg && ac->suspended_state) {
-               _DBG("[__SUSPEND__]");
-               __sys_do(ac, &suspend, SE_SUSPENDED_STATE);
-               ac->suspended_state = false;
+       if (TIZEN_FEATURE_BACKGROUND_MANAGEMENT) {
+               int suspend = APPCORE_AGENT_SUSPENDED_STATE_DID_EXIT_FROM_SUSPEND;
+               struct agent_appcore *ac = data;
+
+               if (ac && !ac->allowed_bg && ac->suspended_state) {
+                       _DBG("[__SUSPEND__]");
+                       __sys_do(ac, &suspend, SE_SUSPENDED_STATE);
+                       ac->suspended_state = false;
+               }
        }
-#endif
 }
 /* LCOV_EXCL_START */
 
 /* LCOV_EXCL_START */
-#ifdef TIZEN_FEATURE_BACKGROUND_MANAGEMENT
 static gboolean __flush_memory(gpointer data)
 {
        struct agent_appcore *ac = (struct agent_appcore *)data;
@@ -343,27 +381,23 @@ static gboolean __flush_memory(gpointer data)
        __prepare_to_suspend(ac);
        return FALSE;
 }
-#endif
 /* LCOV_EXCL_STOP */
 
 /* LCOV_EXCL_START */
 static void __add_suspend_timer(struct agent_appcore *ac)
 {
-#ifdef TIZEN_FEATURE_BACKGROUND_MANAGEMENT
-       ac->tid = g_timeout_add_seconds(5, __flush_memory, ac);
-#endif
+       if (TIZEN_FEATURE_BACKGROUND_MANAGEMENT)
+               ac->tid = g_timeout_add_seconds(5, __flush_memory, ac);
 }
 /* LCOV_EXCL_STOP */
 
 /* LCOV_EXCL_START */
 static void __remove_suspend_timer(struct agent_appcore *ac)
 {
-#ifdef TIZEN_FEATURE_BACKGROUND_MANAGEMENT
-       if (ac->tid > 0) {
+       if (TIZEN_FEATURE_BACKGROUND_MANAGEMENT && ac->tid > 0) {
                g_source_remove(ac->tid);
                ac->tid = 0;
        }
-#endif
 }
 /* LCOV_EXCL_STOP */
 
@@ -846,7 +880,6 @@ EXPORT_API int appcore_agent_set_event_callback(enum appcore_agent_event event,
        return r;
 }
 
-#ifdef TIZEN_FEATURE_BACKGROUND_MANAGEMENT
 static gboolean __init_suspend(gpointer data)
 {
        int r;
@@ -857,7 +890,6 @@ static gboolean __init_suspend(gpointer data)
 
        return FALSE;
 }
-#endif
 
 static int __get_locale_resource_dir(char *locale_dir, int size)
 {
@@ -904,9 +936,8 @@ EXPORT_API int appcore_agent_init(const struct agent_ops *ops,
        free(app_name);
        _retv_if(r == -1, -1);
 
-#ifdef TIZEN_FEATURE_BACKGROUND_MANAGEMENT
-       g_idle_add(__init_suspend, NULL);
-#endif
+       if (TIZEN_FEATURE_BACKGROUND_MANAGEMENT)
+               g_idle_add(__init_suspend, NULL);
 
        r = aul_launch_init(__aul_handler, &core);
        if (r < 0)
@@ -1021,7 +1052,6 @@ EXPORT_API int appcore_agent_main(int argc, char **argv,
 }
 
 /* LCOV_EXCL_START */
-#ifdef TIZEN_FEATURE_BACKGROUND_MANAGEMENT
 static void __suspend_dbus_signal_handler(GDBusConnection *connection,
                                        const gchar *sender_name,
                                        const gchar *object_path,
@@ -1086,5 +1116,3 @@ int _appcore_agent_init_suspend_dbus_handler(void *data)
 
        return 0;
 }
-
-#endif