Remove Profile Build Dependency: Do it at runtime 01/98101/9
authorMyungJoo Ham <myungjoo.ham@samsung.com>
Wed, 16 Nov 2016 06:58:22 +0000 (15:58 +0900)
committerJiwoong Im <jiwoong.im@samsung.com>
Tue, 17 Jan 2017 08:59:24 +0000 (17:59 +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.

  In the code (alarm-manager), indentation for
 if(_APPFW_FEATURE_WAKEUP_USING_RTC) is ignored to help understand
 the patch. Correcting those indentation ignores will follow
 as another patch.

Change-Id: I18b2ff8ea39bbdda0ed435f08a89b343b868822e
Signed-off-by: MyungJoo Ham <myungjoo.ham@samsung.com>
Signed-off-by: Jiwoong Im <jiwoong.im@samsung.com>
CMakeLists.txt
alarm-manager.c
packaging/alarm-manager.spec

index c4a57e6..d1a006b 100644 (file)
@@ -6,16 +6,12 @@ INCLUDE_DIRECTORIES(
        include
 )
 
-SET(DEPS_PKGS "glib-2.0 dlog aul bundle db-util appsvc pkgmgr-info pkgmgr vconf gio-2.0 gio-unix-2.0 capi-system-device libtzplatform-config libsystemd-login eventsystem notification")
+SET(DEPS_PKGS "glib-2.0 dlog aul bundle db-util appsvc pkgmgr-info pkgmgr vconf gio-2.0 gio-unix-2.0 capi-system-device libtzplatform-config libsystemd-login eventsystem notification capi-system-info")
 
 IF(_APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG)
 ADD_DEFINITIONS("-D_APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG")
 ENDIF(_APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG)
 
-IF(_APPFW_FEATURE_WAKEUP_USING_RTC)
-       ADD_DEFINITIONS("-D_APPFW_FEATURE_WAKEUP_USING_RTC")
-ENDIF(_APPFW_FEATURE_WAKEUP_USING_RTC)
-
 message("${DEPS_PKGS}")
 
 INCLUDE(FindPkgConfig)
index 5c7a00f..1400ed2 100644 (file)
@@ -45,6 +45,7 @@
 #include <notification.h>
 #include <notification_ipc.h>
 #include <notification_internal.h>
+#include <system_info.h>
 
 #include <glib.h>
 #if !GLIB_CHECK_VERSION(2, 31, 0)
@@ -83,10 +84,9 @@ GSList *g_disabled_alarm_list;
 #include <sys/ioctl.h>
 #include <fcntl.h>
 
-#ifdef _APPFW_FEATURE_WAKEUP_USING_RTC
 static const char default_rtc[] = "/dev/rtc";
 static int gfd = -1;
-#endif /*__APPFW_FEATURE_WAKEUP_USING_RTC*/
+#define _APPFW_FEATURE_WAKEUP_USING_RTC (_get_profile() != PROFILE_TV)
 
 #ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG
 #define ALARMMGR_LOG_BUFFER_SIZE       10000
@@ -182,6 +182,49 @@ typedef struct {
        char *unique_name;
 } appid_cache_t;
 
+typedef enum {
+       PROFILE_UNKNOWN = 0,
+       PROFILE_MOBILE,
+       PROFILE_WEARABLE,
+       PROFILE_TV,
+       PROFILE_IVI,
+       PROFILE_COMMON,
+} profile_t;
+
+static profile_t _get_profile()
+{
+       static profile_t saved = PROFILE_UNKNOWN;
+       char *profileName;
+
+       if (__builtin_expect(saved != PROFILE_UNKNOWN, 1))
+               return saved;
+
+       system_info_get_platform_string("http://tizen.org/feature/profile", &profileName);
+       switch (*profileName) {
+               case 'm':
+               case 'M':
+                       saved = PROFILE_MOBILE;
+                       break;
+               case 'w':
+               case 'W':
+                       saved = PROFILE_WEARABLE;
+                       break;
+               case 't':
+               case 'T':
+                       saved = PROFILE_TV;
+                       break;
+               case 'i':
+               case 'I':
+                       saved = PROFILE_IVI;
+                       break;
+               default: // common or unknown ==> ALL ARE COMMON.
+                       saved = PROFILE_COMMON;
+       }
+       free(profileName);
+
+       return saved;
+}
+
 static bool __get_cached_unique_name(int pid, char *unique_name, bool *is_app, uid_t uid)
 {
        appid_cache_t *data = NULL;
@@ -229,7 +272,8 @@ void __free_cached_value(gpointer data)
 
 static void __rtc_set()
 {
-#ifdef _APPFW_FEATURE_WAKEUP_USING_RTC
+/* Indentation ingored to help understand the patch. */
+if (_APPFW_FEATURE_WAKEUP_USING_RTC) {
        const char *rtc = default_rtc;
        struct tm due_tm;
 #ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG
@@ -317,9 +361,9 @@ static void __rtc_set()
                ALARM_MGR_EXCEPTION_PRINT("[alarm-server]alarm_context.c_due_time is"
                        "less than 10 sec. RTC alarm does not need to be set");
        }
-#else
+} else {
        ALARM_MGR_LOG_PRINT("[alarm-server] RTC does not work.");
-#endif /* _APPFW_FEATURE_WAKEUP_USING_RTC */
+}
        return;
 }
 
@@ -340,7 +384,8 @@ int __set_time(time_t _time)
        if (ret < 0)
                ALARM_MGR_EXCEPTION_PRINT("settimeofday is failed.[%d]", errno);
 
-#ifdef _APPFW_FEATURE_WAKEUP_USING_RTC
+/* Indentation ingored to help understand the patch. */
+if (_APPFW_FEATURE_WAKEUP_USING_RTC) {
        /* Using /dev/alarm, this function changes both OS time and RTC. */
        const char *rtc0 = default_rtc;
        struct rtc_time _rtc_time;
@@ -390,9 +435,9 @@ int __set_time(time_t _time)
 
        __save_module_log(log_tag, log_message);
 #endif
-#else
+} else {
        ALARM_MGR_LOG_PRINT("[alarm-server] RTC does not work.");
-#endif /* _APPFW_FEATURE_WAKEUP_USING_RTC */
+}
 
        return 1;
 }
@@ -2349,7 +2394,8 @@ gboolean alarm_manager_alarm_set_rtc_time(AlarmManager *pObj, GDBusMethodInvocat
                                int hour, int min, int sec,
                                gpointer user_data) {
        int return_code = ALARMMGR_RESULT_SUCCESS;
-#ifdef _APPFW_FEATURE_WAKEUP_USING_RTC
+/* Indentation ingored to help understand the patch. */
+if (_APPFW_FEATURE_WAKEUP_USING_RTC) {
        const char *rtc = default_rtc;
        struct rtc_wkalrm rtc_wkalarm;
        int retval = 0;
@@ -2421,10 +2467,10 @@ gboolean alarm_manager_alarm_set_rtc_time(AlarmManager *pObj, GDBusMethodInvocat
        snprintf(log_message, sizeof(log_message), "wakeup rtc time: %d, %s", (int)rtc_time, ctime(&rtc_time));
        __save_module_log(log_tag, log_message);
 #endif
-#else
+} else {
        ALARM_MGR_LOG_PRINT("[alarm-server] RTC does not work.");
        return_code = ERR_ALARM_SYSTEM_FAIL;
-#endif /* _APPFW_FEATURE_WAKEUP_USING_RTC */
+}
 
        g_dbus_method_invocation_return_value(invoc, g_variant_new("(i)", return_code));
        return true;
index 51d19b6..f9e802c 100644 (file)
@@ -32,6 +32,7 @@ BuildRequires: pkgconfig(libsystemd)
 BuildRequires: pkgconfig(eventsystem)
 BuildRequires: pkgconfig(notification)
 BuildRequires: python-xml
+BuildRequires: pkgconfig(capi-system-info)
 
 %define upgrade_script_path /usr/share/upgrade/scripts
 
@@ -67,21 +68,12 @@ Requires:   libalarm = %{version}-%{release}
 %description -n libalarm-devel
 Alarm server libraries development package (devel)
 
-%define appfw_feature_wakeup_using_rtc 1
-
-%if "%{?profile}" == "tv"
-%define appfw_feature_wakeup_using_rtc 0
-%endif
-
 %prep
 %setup -q
 
 
 %build
 MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'`
-%if 0%{?appfw_feature_wakeup_using_rtc}
-_APPFW_FEATURE_WAKEUP_USING_RTC=ON
-%endif
 
 export CFLAGS="$CFLAGS -DTIZEN_DEBUG_ENABLE"
 export CXXFLAGS="$CXXFLAGS -DTIZEN_DEBUG_ENABLE"
@@ -95,8 +87,7 @@ export FFLAGS="$FFLAGS -DTIZEN_DEBUG_ENABLE"
        -DFULLVER=%{version} \
        -DMAJORVER=${MAJORVER} \
        -DTZ_SYS_ETC=%{TZ_SYS_ETC} \
-       -D_APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG:BOOL=${_APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG} \
-       -D_APPFW_FEATURE_WAKEUP_USING_RTC:BOOL=${_APPFW_FEATURE_WAKEUP_USING_RTC}
+       -D_APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG:BOOL=${_APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG}
 
 make %{?jobs:-j%jobs}
 
@@ -114,10 +105,8 @@ ln -s ../alarm-server.service %{buildroot}%{_unitdir}/multi-user.target.wants/al
 ln -sf ../alarm_session_agent.socket %{buildroot}%{_unitdir_user}/sockets.target.wants/alarm-session-agent.socket
 mkdir -p %{buildroot}%{_tmpfilesdir}
 install -m 0644 %SOURCE4 %{buildroot}%{_tmpfilesdir}/alarm-manager.conf
-%if 0%{?appfw_feature_wakeup_using_rtc}
 mkdir -p %{buildroot}%{_libdir}/udev/rules.d
 install -m 0644 %SOURCE5 %{buildroot}%{_libdir}/udev/rules.d
-%endif
 
 mkdir -p %{buildroot}%{upgrade_script_path}
 cp -f scripts/508.alarmmgr_upgrade.sh %{buildroot}%{upgrade_script_path}
@@ -134,6 +123,14 @@ cp -f scripts/508.alarmmgr_upgrade.sh %{buildroot}%{upgrade_script_path}
 %postun -n libalarm
 /sbin/ldconfig
 
+%posttrans -n alarm-server
+if [ -e /etc/config/model-config.xml ]; then
+       grep "feature\/profile.*tv" /etc/config/model-config.xml > /dev/null
+       if [ $? -eq 0 ]; then
+               rm %{_libdir}/udev/rules.d/99-rtc.rules
+       fi
+fi
+
 %files -n alarm-server
 %manifest alarm-server.manifest
 %{_bindir}/*
@@ -148,9 +145,7 @@ cp -f scripts/508.alarmmgr_upgrade.sh %{buildroot}%{upgrade_script_path}
 %license LICENSE
 %config %{_sysconfdir}/dbus-1/system.d/alarm-service.conf
 %{_tmpfilesdir}/alarm-manager.conf
-%if 0%{?appfw_feature_wakeup_using_rtc}
 %{_libdir}/udev/rules.d/99-rtc.rules
-%endif
 %if 0%{?appfw_feature_alarm_manager_module_log}
 %attr(0755,root,root) %{TZ_SYS_ETC}/dump.d/module.d/alarmmgr_log_dump.sh
 %endif