Remove Profile Build Dependency: Do it at runtime
[platform/core/appfw/app-core.git] / src / appcore.c
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;
+}