Remove Profile Build Dependency: Do it at runtime 36/97336/9
authorMyungJoo Ham <myungjoo.ham@samsung.com>
Mon, 14 Nov 2016 02:09:32 +0000 (11:09 +0900)
committerMyungJoo Ham <myungjoo.ham@samsung.com>
Mon, 9 Jan 2017 04:22:12 +0000 (13:22 +0900)
- 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: I200b851806704eba228709e07f0f6e634f521032
Signed-off-by: MyungJoo Ham <myungjoo.ham@samsung.com>
CMakeLists.txt
include/appcore-internal.h
packaging/app-core.spec
src/appcore-efl.c
src/appcore.c

index 9e357fd..261f3eb 100644 (file)
@@ -35,14 +35,10 @@ IF(_WITH_X11)
        SET(SRCS_common ${SRCS_common} src/appcore-X.c)
 ENDIF(_WITH_X11)
 
-IF(_APPFW_FEATURE_BACKGROUND_MANAGEMENT)
-        ADD_DEFINITIONS("-D_APPFW_FEATURE_BACKGROUND_MANAGEMENT")
-ENDIF(_APPFW_FEATURE_BACKGROUND_MANAGEMENT)
-
 SET(HEADERS_common appcore-common.h)
 
 INCLUDE(FindPkgConfig)
-SET(APPCORE_PKG_CHECK_MODULES "gio-2.0 vconf sensor aul dlog ecore")
+SET(APPCORE_PKG_CHECK_MODULES "gio-2.0 vconf sensor aul dlog ecore capi-system-info")
 IF(_WITH_X11)
        SET(APPCORE_PKG_CHECK_MODULES "${APPCORE_PKG_CHECK_MODULES} x11 eina ecore-x")
 ENDIF(_WITH_X11)
@@ -85,7 +81,7 @@ SET(SRCS_efl src/appcore-efl.c src/appcore-group.c)
 SET(HEADERS_efl appcore-efl.h)
 
 INCLUDE(FindPkgConfig)
-SET(APPCORE_PKG_CHECK_MODULES2 "elementary dlog ecore gobject-2.0 glib-2.0 aul pkgmgr-info ttrace")
+SET(APPCORE_PKG_CHECK_MODULES2 "elementary dlog ecore gobject-2.0 glib-2.0 aul pkgmgr-info ttrace capi-system-info")
 IF(_WITH_X11)
         SET(APPCORE_PKG_CHECK_MODULES2 "${APPCORE_PKG_CHECK_MODULES2} ecore-x")
 ENDIF(_WITH_X11)
index a645a69..97e84a7 100644 (file)
@@ -201,4 +201,16 @@ void appcore_get_app_core(struct appcore **ac);
 
 #define MEMORY_FLUSH_ACTIVATE
 
+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;
+extern tizen_profile_t _get_tizen_profile();
+
+#define _APPFW_FEATURE_BACKGROUND_MANAGEMENT (_get_tizen_profile() & (TIZEN_PROFILE_WEARABLE | TIZEN_PROFILE_MOBILE))
+
 #endif                         /* __APPCORE_INTERNAL_H__ */
index d5f2513..fa84c6a 100644 (file)
@@ -34,6 +34,7 @@ BuildRequires:  pkgconfig(glib-2.0)
 BuildRequires:  pkgconfig(pkgmgr-info)
 BuildRequires:  pkgconfig(ttrace)
 BuildRequires:  cmake
+BuildRequires:  pkgconfig(capi-system-info)
 
 %description
 SLP common application basic
@@ -92,18 +93,6 @@ Group:      Development/Libraries
 %description template
 Application basics template
 
-%if "%{?profile}" == "wearable"
-%define appfw_feature_background_management 1
-%else
-%if "%{?profile}" == "mobile"
-%define appfw_feature_background_management 1
-%else
-%if "%{?profile}" == "tv"
-%define appfw_feature_background_management 0
-%endif
-%endif
-%endif
-
 %prep
 %setup -q
 cp %{SOURCE1001} .
@@ -115,14 +104,10 @@ _WITH_WAYLAND=ON
 %if %{with x}
 _WITH_X11=ON
 %endif
-%if 0%{?appfw_feature_background_management}
-_APPFW_FEATURE_BACKGROUND_MANAGEMENT=ON
-%endif
 
 %cmake . \
        -D_WITH_WAYLAND:BOOL=${_WITH_WAYLAND} \
        -D_WITH_X11:BOOL=${_WITH_X11} \
-       -D_APPFW_FEATURE_BACKGROUND_MANAGEMENT:BOOL=${_APPFW_FEATURE_BACKGROUND_MANAGEMENT} \
        -DENABLE_GTK=OFF
 
 make %{?_smp_mflags}
index f0161b3..6ff2939 100644 (file)
@@ -51,6 +51,7 @@
 
 #include "appcore-internal.h"
 #include "appcore-efl.h"
+#include <system_info.h>
 
 static pid_t _pid;
 static bool resource_reclaiming = TRUE;
@@ -71,10 +72,8 @@ struct ui_priv {
        Ecore_Timer *mftimer; /* Ecore Timer for memory flushing */
 
        struct appcore *app_core;
-#ifdef _APPFW_FEATURE_BACKGROUND_MANAGEMENT
        void (*prepare_to_suspend) (void *data);
        void (*exit_from_suspend) (void *data);
-#endif
        struct appcore_ops *ops;
        void (*mfcb) (void); /* Memory Flushing Callback */
 
@@ -223,7 +222,6 @@ static void __unset_bg_state(void)
        __finish_wl();
 }
 
-#ifdef _APPFW_FEATURE_BACKGROUND_MANAGEMENT
 static void __appcore_efl_prepare_to_suspend(void *data)
 {
        struct ui_priv *ui = (struct ui_priv *)data;
@@ -255,7 +253,6 @@ static void __appcore_efl_exit_from_suspend(void *data)
        }
        _DBG("[__SUSPEND__]");
 }
-#endif
 
 static void __appcore_efl_update_requested(void *data)
 {
@@ -280,12 +277,10 @@ static Eina_Bool __appcore_memory_flush_cb(void *data)
        if (ui)
                ui->mftimer = NULL;
 
-#ifdef _APPFW_FEATURE_BACKGROUND_MANAGEMENT
-       if (ui && ui->prepare_to_suspend) {
+       if (_APPFW_FEATURE_BACKGROUND_MANAGEMENT && ui && ui->prepare_to_suspend) {
                _DBG("[__SUSPEND__] flush case");
                ui->prepare_to_suspend(ui);
        }
-#endif
 
        return ECORE_CALLBACK_CANCEL;
 }
@@ -435,12 +430,10 @@ static void __do_app(enum app_event event, void *data, bundle * b)
                below_app = bundle_get_val(b, AUL_SVC_K_RELOCATE_BELOW);
                if (below_app)
                        ui->below_app = strdup(below_app);
-#ifdef _APPFW_FEATURE_BACKGROUND_MANAGEMENT
-               if (ui->exit_from_suspend) {
+               if (_APPFW_FEATURE_BACKGROUND_MANAGEMENT && ui->exit_from_suspend) {
                        _DBG("[__SUSPEND__] reset case");
                        ui->exit_from_suspend(ui);
                }
-#endif
 
                if (ui->ops->reset) {
                        traceBegin(TTRACE_TAG_APPLICATION_MANAGER,
@@ -451,10 +444,8 @@ static void __do_app(enum app_event event, void *data, bundle * b)
                LOG(LOG_DEBUG, "LAUNCH", "[%s:Application:reset:done]", ui->name);
 
                if (first_launch) {
-#ifdef _APPFW_FEATURE_BACKGROUND_MANAGEMENT
-                       if (ui->app_core->allowed_bg)
+                       if (_APPFW_FEATURE_BACKGROUND_MANAGEMENT && ui->app_core->allowed_bg)
                                __appcore_timer_add(ui);
-#endif
                        first_launch = FALSE;
                } else {
                        _INFO("[APP %d] App already running, raise the window", _pid);
@@ -484,13 +475,11 @@ static void __do_app(enum app_event event, void *data, bundle * b)
                        ui->state = AS_PAUSED;
                        if (r >= 0 && resource_reclaiming == TRUE)
                                __appcore_timer_add(ui);
-#ifdef _APPFW_FEATURE_BACKGROUND_MANAGEMENT
-                       else if (r >= 0 && resource_reclaiming == FALSE
+                       else if (_APPFW_FEATURE_BACKGROUND_MANAGEMENT && r >= 0 && resource_reclaiming == FALSE
                                        && ui->prepare_to_suspend) {
                                _DBG("[__SUSPEND__] pause case");
                                ui->prepare_to_suspend(ui);
                        }
-#endif
                }
                /* TODO : rotation stop */
                /* r = appcore_pause_rotation_cb(); */
@@ -499,14 +488,14 @@ static void __do_app(enum app_event event, void *data, bundle * b)
        case AE_RESUME:
                LOG(LOG_DEBUG, "LAUNCH", "[%s:Application:resume:start]",
                                ui->name);
-#ifdef _APPFW_FEATURE_BACKGROUND_MANAGEMENT
-               if (ui->exit_from_suspend) {
-                       _DBG("[__SUSPEND__] resume case");
-                       ui->exit_from_suspend(ui);
+               if (_APPFW_FEATURE_BACKGROUND_MANAGEMENT) {
+                       if (ui->exit_from_suspend) {
+                               _DBG("[__SUSPEND__] resume case");
+                               ui->exit_from_suspend(ui);
+                       }
+                       if (ui->app_core->allowed_bg)
+                               __appcore_timer_del(ui);
                }
-               if (ui->app_core->allowed_bg)
-                       __appcore_timer_del(ui);
-#endif
 
                if (ui->state == AS_PAUSED || ui->state == AS_CREATED) {
                        _DBG("[APP %d] RESUME", _pid);
@@ -976,9 +965,7 @@ static int __before_loop(struct ui_priv *ui, int *argc, char ***argv)
 {
        int r;
        char *hwacc = NULL;
-#if _APPFW_FEATURE_BACKGROUND_MANAGEMENT
        struct appcore *ac = NULL;
-#endif
        bundle *b;
        const char *bg_launch;
 
@@ -1009,11 +996,11 @@ static int __before_loop(struct ui_priv *ui, int *argc, char ***argv)
        r = appcore_init(ui->name, &efl_ops, *argc, *argv);
        _retv_if(r == -1, -1);
 
-#if _APPFW_FEATURE_BACKGROUND_MANAGEMENT
-       appcore_get_app_core(&ac);
-       ui->app_core = ac;
-       SECURE_LOGD("[__SUSPEND__] appcore initialized, appcore addr: #%x", ac);
-#endif
+       if (_APPFW_FEATURE_BACKGROUND_MANAGEMENT) {
+               appcore_get_app_core(&ac);
+               ui->app_core = ac;
+               SECURE_LOGD("[__SUSPEND__] appcore initialized, appcore addr: #%x", ac);
+       }
 
        b = bundle_import_from_argv(*argc, *argv);
        if (b) {
@@ -1131,11 +1118,11 @@ static int __set_data(struct ui_priv *ui, const char *name,
        ui->rot_cb_data = NULL;
        ui->rot_mode = APPCORE_RM_UNKNOWN;
 
-#ifdef  _APPFW_FEATURE_BACKGROUND_MANAGEMENT
-       ui->app_core = NULL;
-       ui->prepare_to_suspend = __appcore_efl_prepare_to_suspend;
-       ui->exit_from_suspend = __appcore_efl_exit_from_suspend;
-#endif
+       if (_APPFW_FEATURE_BACKGROUND_MANAGEMENT) {
+               ui->app_core = NULL;
+               ui->prepare_to_suspend = __appcore_efl_prepare_to_suspend;
+               ui->exit_from_suspend = __appcore_efl_exit_from_suspend;
+       }
 
        return 0;
 }
@@ -1334,3 +1321,36 @@ EXPORT_API unsigned int appcore_get_main_surface(void)
        return 0;
 }
 #endif
+
+tizen_profile_t _get_tizen_profile()
+{
+       static tizen_profile_t profile = TIZEN_PROFILE_UNKNOWN;
+       if (__builtin_expect(profile != TIZEN_PROFILE_UNKNOWN, 1))
+               return profile;
+
+       char *profileName;
+       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 unTIZEN_nown ==> ALL ARE COMMON.
+               profile = TIZEN_PROFILE_COMMON;
+       }
+       free(profileName);
+
+       return profile;
+}
index 20fb3c4..c93d447 100644 (file)
@@ -32,8 +32,8 @@
 #include <aul.h>
 #include <bundle_internal.h>
 #include "appcore-internal.h"
+#include <system_info.h>
 
-#ifdef _APPFW_FEATURE_BACKGROUND_MANAGEMENT
 #include <gio/gio.h>
 
 #define RESOURCED_FREEZER_PATH "/Org/Tizen/Resourced/Freezer"
@@ -42,7 +42,6 @@
 
 int __appcore_init_suspend_dbus_handler(void *data);
 void __appcore_fini_suspend_dbus_handler(void);
-#endif
 
 #define SQLITE_FLUSH_MAX               (1024*1024)
 
@@ -139,10 +138,8 @@ static struct evt_ops evtops[] = {
         },
 };
 
-#ifdef _APPFW_FEATURE_BACKGROUND_MANAGEMENT
 static GDBusConnection *bus;
 static guint __suspend_dbus_handler_initialized;
-#endif
 
 static int __get_locale_resource_dir(char *locale_dir, int size)
 {
@@ -466,7 +463,6 @@ static int __del_vconf_list(void)
        return 0;
 }
 
-#ifdef _APPFW_FEATURE_BACKGROUND_MANAGEMENT
 static gboolean __flush_memory(gpointer data)
 {
        int suspend = APPCORE_SUSPENDED_STATE_WILL_ENTER_SUSPEND;
@@ -500,7 +496,6 @@ static void __remove_suspend_timer(struct appcore *ac)
                ac->tid = 0;
        }
 }
-#endif
 
 static int __aul_handler(aul_type type, bundle *b, void *data)
 {
@@ -508,11 +503,9 @@ static int __aul_handler(aul_type type, bundle *b, void *data)
        const char **tep_path = NULL;
        int len = 0;
        int i;
-#ifdef _APPFW_FEATURE_BACKGROUND_MANAGEMENT
        const char *bg = NULL;
        struct appcore *ac = data;
        int suspend = APPCORE_SUSPENDED_STATE_DID_EXIT_FROM_SUSPEND;
-#endif
 
        switch (type) {
        case AUL_START:
@@ -528,27 +521,27 @@ static int __aul_handler(aul_type type, bundle *b, void *data)
                        }
                }
 
-#ifdef _APPFW_FEATURE_BACKGROUND_MANAGEMENT
-               bg = bundle_get_val(b, AUL_K_ALLOWED_BG);
-               if (bg && strncmp(bg, "ALLOWED_BG", strlen("ALLOWED_BG")) == 0) {
-                       _DBG("[__SUSPEND__] allowed background");
-                       ac->allowed_bg = true;
-                       __remove_suspend_timer(data);
+               if (_APPFW_FEATURE_BACKGROUND_MANAGEMENT) {
+                       bg = bundle_get_val(b, AUL_K_ALLOWED_BG);
+                       if (bg && strncmp(bg, "ALLOWED_BG", strlen("ALLOWED_BG")) == 0) {
+                               _DBG("[__SUSPEND__] allowed background");
+                               ac->allowed_bg = true;
+                               __remove_suspend_timer(data);
+                       }
                }
-#endif
 
                __app_reset(data, b);
                break;
        case AUL_RESUME:
                _DBG("[APP %d]     AUL event: AUL_RESUME", _pid);
-#ifdef _APPFW_FEATURE_BACKGROUND_MANAGEMENT
-               bg = bundle_get_val(b, AUL_K_ALLOWED_BG);
-               if (bg && strncmp(bg, "ALLOWED_BG", strlen("ALLOWED_BG")) == 0) {
-                       _DBG("[__SUSPEND__] allowed background");
-                       ac->allowed_bg = true;
-                       __remove_suspend_timer(data);
+               if (_APPFW_FEATURE_BACKGROUND_MANAGEMENT) {
+                       bg = bundle_get_val(b, AUL_K_ALLOWED_BG);
+                       if (bg && strncmp(bg, "ALLOWED_BG", strlen("ALLOWED_BG")) == 0) {
+                               _DBG("[__SUSPEND__] allowed background");
+                               ac->allowed_bg = true;
+                               __remove_suspend_timer(data);
+                       }
                }
-#endif
 
                if (open.callback) {
                        ret = open.callback(open.cbdata);
@@ -560,19 +553,15 @@ static int __aul_handler(aul_type type, bundle *b, void *data)
                break;
        case AUL_TERMINATE:
                _DBG("[APP %d]     AUL event: AUL_TERMINATE", _pid);
-#ifdef _APPFW_FEATURE_BACKGROUND_MANAGEMENT
-               if (!ac->allowed_bg)
+               if (_APPFW_FEATURE_BACKGROUND_MANAGEMENT && !ac->allowed_bg)
                        __remove_suspend_timer(data);
-#endif
 
                __app_terminate(data);
                break;
        case AUL_TERMINATE_BGAPP:
                _DBG("[APP %d]     AUL event: AUL_TERMINATE_BGAPP", _pid);
-#ifdef _APPFW_FEATURE_BACKGROUND_MANAGEMENT
-               if (!ac->allowed_bg)
+               if (_APPFW_FEATURE_BACKGROUND_MANAGEMENT && !ac->allowed_bg)
                        __remove_suspend_timer(data);
-#endif
 
                __bgapp_terminate(data);
                break;
@@ -580,36 +569,40 @@ static int __aul_handler(aul_type type, bundle *b, void *data)
                _DBG("[APP %d]     AUL event: AUL_PAUSE", _pid);
                __app_pause(data);
                break;
-#ifdef _APPFW_FEATURE_BACKGROUND_MANAGEMENT
        case AUL_WAKE:
-               _DBG("[APP %d]     AUL event: AUL_WAKE", _pid);
-               if (!ac->allowed_bg && ac->suspended_state) {
-                       __remove_suspend_timer(data);
-                       __sys_do(ac, &suspend, SE_SUSPENDED_STATE);
-                       ac->suspended_state = false;
-               }
-
-               if (b) {
-                       bg = bundle_get_val(b, AUL_K_ALLOWED_BG);
-                       if (bg && strcmp(bg, "ALLOWED_BG") == 0) {
-                               _DBG("[__SUSPEND__] allowed background");
-                               ac->allowed_bg = true;
+               if (_APPFW_FEATURE_BACKGROUND_MANAGEMENT) {
+                       _DBG("[APP %d]     AUL event: AUL_WAKE", _pid);
+                       if (!ac->allowed_bg && ac->suspended_state) {
+                               __remove_suspend_timer(data);
+                               __sys_do(ac, &suspend, SE_SUSPENDED_STATE);
+                               ac->suspended_state = false;
+                       }
+                       if (b) {
+                               bg = bundle_get_val(b, AUL_K_ALLOWED_BG);
+                               if (bg && strcmp(bg, "ALLOWED_BG") == 0) {
+                                       _DBG("[__SUSPEND__] allowed background");
+                                       ac->allowed_bg = true;
+                               }
                        }
+                       break;
                }
-               break;
+               goto __default__;
        case AUL_SUSPEND:
-               _DBG("[APP %d]     AUL event: AUL_SUSPEND", _pid);
-               ac->allowed_bg = false;
-               if (!ac->suspended_state) {
-                       __remove_suspend_timer(data);
-                       __flush_memory((gpointer)ac);
+               if (_APPFW_FEATURE_BACKGROUND_MANAGEMENT) {
+                       _DBG("[APP %d]     AUL event: AUL_SUSPEND", _pid);
+                       ac->allowed_bg = false;
+                       if (!ac->suspended_state) {
+                               __remove_suspend_timer(data);
+                               __flush_memory((gpointer)ac);
+                       }
+                       break;
                }
-               break;
-#endif
+               goto __default__;
        case AUL_UPDATE_REQUESTED:
                _DBG("[APP %d]     AUL event: AUL_UPDATE_REQUESTED", _pid);
                __app_update_requested(data);
                break;
+__default__:
        default:
                _DBG("[APP %d]     AUL event: %d", _pid, type);
                /* do nothing */
@@ -680,7 +673,6 @@ EXPORT_API int appcore_set_event_callback(enum appcore_event event,
        return 0;
 }
 
-#ifdef _APPFW_FEATURE_BACKGROUND_MANAGEMENT
 static gboolean __init_suspend(gpointer data)
 {
        int r;
@@ -692,7 +684,6 @@ static gboolean __init_suspend(gpointer data)
 
        return FALSE;
 }
-#endif
 
 EXPORT_API int appcore_init(const char *name, const struct ui_ops *ops,
                            int argc, char **argv)
@@ -736,9 +727,8 @@ EXPORT_API int appcore_init(const char *name, const struct ui_ops *ops,
 
        _pid = getpid();
 
-#ifdef _APPFW_FEATURE_BACKGROUND_MANAGEMENT
-       g_idle_add(__init_suspend, NULL);
-#endif
+       if (_APPFW_FEATURE_BACKGROUND_MANAGEMENT)
+               g_idle_add(__init_suspend, NULL);
 
        return 0;
  err:
@@ -752,10 +742,10 @@ EXPORT_API void appcore_exit(void)
        if (core.state) {
                __del_vconf_list();
                __clear(&core);
-#ifdef _APPFW_FEATURE_BACKGROUND_MANAGEMENT
-               __remove_suspend_timer(&core);
-               __appcore_fini_suspend_dbus_handler();
-#endif
+               if (_APPFW_FEATURE_BACKGROUND_MANAGEMENT) {
+                       __remove_suspend_timer(&core);
+                       __appcore_fini_suspend_dbus_handler();
+               }
        }
        aul_finalize();
 }
@@ -791,7 +781,6 @@ EXPORT_API int appcore_flush_memory(void)
        return 0;
 }
 
-#ifdef _APPFW_FEATURE_BACKGROUND_MANAGEMENT
 static void __suspend_dbus_signal_handler(GDBusConnection *connection,
                                        const gchar *sender_name,
                                        const gchar *object_path,
@@ -870,5 +859,36 @@ void __appcore_fini_suspend_dbus_handler(void)
        g_object_unref(bus);
        bus = NULL;
 }
-#endif
 
+tizen_profile_t _get_tizen_profile()
+{
+       static tizen_profile_t profile = TIZEN_PROFILE_UNKNOWN;
+       if (__builtin_expect(profile != TIZEN_PROFILE_UNKNOWN, 1))
+               return profile;
+
+       char *profileName;
+       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 unTIZEN_nown ==> ALL ARE COMMON.
+               profile = TIZEN_PROFILE_COMMON;
+       }
+       free(profileName);
+
+       return profile;
+}