Remove Profile Build Dependencies: do it at runtime 93/94893/4
authorMyungJoo Ham <myungjoo.ham@samsung.com>
Wed, 2 Nov 2016 02:39:16 +0000 (11:39 +0900)
committerMyungJoo Ham <myungjoo.ham@samsung.com>
Thu, 5 Jan 2017 08:44:10 +0000 (17:44 +0900)
1. This is for Tizen 4.0

2. When this commit is being SR-ed, the maintainer needs to create
a JIRA-TRE issue of:

  Add sdbd-profile_tv for TV profile

Change-Id: I8432436827023da8990c76f93df3e33c381e2e63
Signed-off-by: MyungJoo Ham <myungjoo.ham@samsung.com>
packaging/sdbd.spec
src/default_plugin_event.c

index bc9408f..a8285d9 100644 (file)
@@ -27,10 +27,21 @@ BuildRequires: pkgconfig(dbus-1)
 BuildRequires: pkgconfig(dbus-glib-1)
 BuildRequires: pkgconfig(dlog)
 Requires: dbus
+Provides:      %{name}-profile_common = %{version}-%{release}
+Provides:      %{name}-profile_mobile = %{version}-%{release}
+Provides:      %{name}-profile_ivi = %{version}-%{release}
+Provides:      %{name}-profile_wearable = %{version}-%{release}
 
 %description
 Description: SDB daemon.
 
+%package profile_tv
+Summary:   SDB daemon extension for TV
+Requires:  %{name} = %{version}-%{release}
+%description profile_tv
+SDB daemon extension for TV.
+This changes the service unit files of the default SDB daemon service files.
+
 %package -n sdbd-devel
 Summary:       SDBD plugin API
 Group:         Development/Libraries
@@ -43,18 +54,15 @@ SDBD plugin API library
 cp %{SOURCE1003} .
 
 %build
-%if "%{?tizen_profile_name}" == "wearable"
-%define wearable_profile on
-%else
-%define wearable_profile off
-%endif
+
+# DO YOU REALLY SURE THAT x86 is never going to be non-emulator?
 %if %{with emulator}
 %define target_arch x86
 %else
 %define target_arch arm
 %endif
+
 cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} \
-       -DWEARABLE_PROFILE=%{wearable_profile} \
        -DTARGET_ARCH=%{target_arch}
 
 make %{?jobs:-j%jobs}
@@ -67,20 +75,14 @@ cp LICENSE %{buildroot}/usr/share/license/%{name}
 mkdir -p %{buildroot}%{_unitdir}
 
 %if %{with emulator}
-%if "%{profile}" == "tv"
-install -m 0644 %SOURCE1006 %{buildroot}%{_unitdir}/sdbd.service
-%else
+install -m 0644 %SOURCE1006 %{buildroot}%{_unitdir}/sdbd.service.tv
 install -m 0644 %SOURCE1002 %{buildroot}%{_unitdir}/sdbd.service
-%endif
 mkdir -p %{buildroot}/%{_unitdir}/emulator_preinit.target.wants
 ln -s %{_unitdir}/sdbd.service %{buildroot}/%{_unitdir}/emulator_preinit.target.wants/
 
 %else
-%if "%{profile}" == "tv"
-install -m 0644 %SOURCE1005 %{buildroot}%{_unitdir}/sdbd.service
-%else
+install -m 0644 %SOURCE1005 %{buildroot}%{_unitdir}/sdbd.service.tv
 install -m 0644 %SOURCE1001 %{buildroot}%{_unitdir}/sdbd.service
-%endif
 install -m 0644 %SOURCE1004 %{buildroot}%{_unitdir}/sdbd_tcp.service
 mkdir -p %{buildroot}/%{_unitdir}/multi-user.target.wants
 ln -s %{_unitdir}/sdbd.service %{buildroot}/%{_unitdir}/multi-user.target.wants/
@@ -126,6 +128,18 @@ fi
 /usr/share/license/%{name}
 %{TZ_SYS_BIN}/profile_command
 
+%post profile_tv
+pushd {%_unitdir}
+mv sdbd.service.tv sdbd.service
+popd
+%preun profile_tv
+pushd {%_unitdir}
+cp sdbd.service sdbd.service.tv
+echo For correct bahavior of %{name} after uninstalling %{name}-profile_tv, you need to reinstall %{name}
+popd
+%files profile_tv
+%{_unitdir}/sdbd.service.tv
+
 %files -n sdbd-devel
 %{_includedir}/sdb/sdbd_plugin.h
 %{_libdir}/pkgconfig/sdbd.pc
index 6731746..787c3f4 100644 (file)
 #include "sdbd_plugin.h"
 #include "default_plugin.h"
 
+#include <system_info.h>
+
+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 profile = TIZEN_PROFILE_UNKNOWN;
+static tizen_profile_t _get_tizen_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 unknown ==> ALL ARE COMMON.
+        profile = TIZEN_PROFILE_COMMON;
+    }
+    free(profileName);
+
+    return profile;
+}
+static inline tizen_profile_t get_tizen_profile()
+{
+    if (__builtin_expect(profile != TIZEN_PROFILE_UNKNOWN, 1))
+        return profile;
+
+    return _get_tizen_profile();
+}
+
 int plugin_pwlocked ( void )
 {
     int pwlock_status = 0;
@@ -30,29 +77,29 @@ int plugin_pwlocked ( void )
         pwlock_status = 0;
         PLUGIN_LOG ( "failed to get pw lock status\n" );
     }
-#ifdef _WEARABLE
-    PLUGIN_LOG ( "wearable lock applied\n" );
-    // for wearable which uses different VCONF key (lock type)
-    if ( vconf_get_int ( VCONFKEY_SETAPPL_PRIVACY_LOCK_TYPE_INT, &pwlock_type ) ) {
-        pwlock_type = 0;
-        PLUGIN_LOG ( "failed to get pw lock type\n" );
-    }
-    if ( ( pwlock_status == VCONFKEY_IDLE_LOCK ) && ( pwlock_type != SETTING_PRIVACY_LOCK_TYPE_NONE ) ) {
-        PLUGIN_LOG ( "device has been locked\n" );
-        return 1; // locked!
-    }
-#else
-    PLUGIN_LOG ( "mobile lock applied\n" );
-    // for mobile
-    if ( vconf_get_int ( VCONFKEY_SETAPPL_SCREEN_LOCK_TYPE_INT, &pwlock_type ) ) {
-        pwlock_type = 0;
-        PLUGIN_LOG ( "failed to get pw lock type\n" );
-    }
-    if ( pwlock_status == VCONFKEY_IDLE_LOCK && ( ( pwlock_type != SETTING_SCREEN_LOCK_TYPE_NONE ) && ( pwlock_type != SETTING_SCREEN_LOCK_TYPE_SWIPE ) ) ) {
-        PLUGIN_LOG ( "device has been locked\n" );
-        return 1; // locked!
+    if (get_tizen_profile() == TIZEN_PROFILE_WEARABLE) {
+        PLUGIN_LOG ( "wearable lock applied\n" );
+        // for wearable which uses different VCONF key (lock type)
+        if ( vconf_get_int ( VCONFKEY_SETAPPL_PRIVACY_LOCK_TYPE_INT, &pwlock_type ) ) {
+            pwlock_type = 0;
+            PLUGIN_LOG ( "failed to get pw lock type\n" );
+        }
+        if ( ( pwlock_status == VCONFKEY_IDLE_LOCK ) && ( pwlock_type != SETTING_PRIVACY_LOCK_TYPE_NONE ) ) {
+            PLUGIN_LOG ( "device has been locked\n" );
+            return 1; // locked!
+        }
+    } else {
+        PLUGIN_LOG ( "mobile lock applied\n" );
+        // for mobile
+        if ( vconf_get_int ( VCONFKEY_SETAPPL_SCREEN_LOCK_TYPE_INT, &pwlock_type ) ) {
+            pwlock_type = 0;
+            PLUGIN_LOG ( "failed to get pw lock type\n" );
+        }
+        if ( pwlock_status == VCONFKEY_IDLE_LOCK && ( ( pwlock_type != SETTING_SCREEN_LOCK_TYPE_NONE ) && ( pwlock_type != SETTING_SCREEN_LOCK_TYPE_SWIPE ) ) ) {
+            PLUGIN_LOG ( "device has been locked\n" );
+            return 1; // locked!
+        }
     }
-#endif
     return 0; // unlocked!
 }