Remove Profile Build Dependency: Do it at runtime
authorMyungJoo Ham <myungjoo.ham@samsung.com>
Wed, 16 Nov 2016 08:36:07 +0000 (17:36 +0900)
committerjongmyeongko <jongmyeong.ko@samsung.com>
Fri, 13 Jan 2017 11:13:33 +0000 (20:13 +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.

(csr is included in Tizen:TV; thus we can keep BuildRequires on csr for TV
while not using csr in TV at runtime)

patchset5: updated coding style

Change-Id: Ibc2e335a4f88918c37d703f8e9379a07d94a7fdc
Signed-off-by: MyungJoo Ham <myungjoo.ham@samsung.com>
Signed-off-by: jongmyeongko <jongmyeong.ko@samsung.com>
CMakeLists.txt
packaging/pkgmgr-server.spec
src/pkgmgr-server.c

index b7bf90d..f6f0c64 100644 (file)
@@ -27,10 +27,7 @@ INCLUDE(FindPkgConfig)
 SET(PKGMGR_SERVER "pkgmgr-server")
 AUX_SOURCE_DIRECTORY(src SRCS)
 
-SET(SERVER_CHECK_MODULES gio-2.0 glib-2.0 dlog pkgmgr-parser pkgmgr-info libtzplatform-config drm-service-core-tizen libgum sqlite3 pkgmgr pkgmgr-installer libsystemd aul minizip)
-IF(TIZEN_FEATURE_CSR)
-       SET(SERVER_CHECK_MODULES "${SERVER_CHECK_MODULES} csr")
-ENDIF(TIZEN_FEATURE_CSR)
+SET(SERVER_CHECK_MODULES gio-2.0 glib-2.0 dlog pkgmgr-parser pkgmgr-info libtzplatform-config drm-service-core-tizen libgum sqlite3 pkgmgr pkgmgr-installer libsystemd aul minizip csr capi-system-info)
 
 pkg_check_modules(SERVER_DEPS REQUIRED ${SERVER_CHECK_MODULES})
 
@@ -38,10 +35,6 @@ FOREACH(SERVER_FLAGS ${SERVER_DEPS_CFLAGS})
        SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${SERVER_FLAGS}")
 ENDFOREACH(SERVER_FLAGS)
 
-IF(TIZEN_FEATURE_CSR)
-       ADD_DEFINITIONS("-DTIZEN_FEATURE_CSR")
-ENDIF(TIZEN_FEATURE_CSR)
-
 ADD_EXECUTABLE(${PKGMGR_SERVER} ${SRCS})
 TARGET_LINK_LIBRARIES(${PKGMGR_SERVER} pkgmgr_installer)
 TARGET_LINK_LIBRARIES(${PKGMGR_SERVER} ${SERVER_DEPS_LDFLAGS})
index b27c953..98ac770 100644 (file)
@@ -27,9 +27,8 @@ BuildRequires:  pkgconfig(libsystemd)
 BuildRequires:  pkgconfig(minizip)
 BuildRequires:  fdupes
 
-%if "%{?profile}" != "tv"
 BuildRequires:  pkgconfig(csr)
-%endif
+BuildRequires:  pkgconfig(capi-system-info)
 
 %description
 Packager Manager server package for packaging
@@ -45,17 +44,10 @@ cp %{SOURCE1001} .
 %build
 sqlite3 restriction.db < ./restriction.sql
 
-%if "%{?profile}" != "tv"
-_TIZEN_FEATURE_CSR=ON
-%else
-_TIZEN_FEATURE_CSR=OFF
-%endif
-
 %cmake . -DRUN_DIR=%{run_dir} \
          -DDB_DIR=%{db_dir} \
          -DBACKEND_DIR=%{backend_dir} \
-         -DUNITDIR=%{_unitdir} \
-         -DTIZEN_FEATURE_CSR:BOOL=${_TIZEN_FEATURE_CSR}
+         -DUNITDIR=%{_unitdir}
 
 %__make %{?_smp_mflags}
 
index cf55a28..638e89a 100644 (file)
 #include <pkgmgr/pkgmgr_parser_db.h>
 #include <tzplatform_config.h>
 #include <drm-tizen-apps.h>
-#ifdef TIZEN_FEATURE_CSR
 #include <csr-content-screening.h>
-#endif
 
 #include "pkgmgr_installer.h"
 #include "pkgmgr-server.h"
 #include "queue.h"
 #include "package-manager.h"
 
+#include <system_info.h>
+
 #define OWNER_ROOT 0
 #define GLOBAL_USER tzplatform_getuid(TZ_SYS_GLOBALAPP_USER)
 #define APPFW_UID 301
@@ -102,6 +102,50 @@ static void sighandler(int signo);
 
 gboolean exit_server(void *data);
 
+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_CSR (_get_tizen_profile() != TIZEN_PROFILE_TV)
+
 /* To check whether a particular backend is free/busy */
 static int __is_backend_busy(int position)
 {
@@ -322,7 +366,6 @@ gboolean exit_server(void *data)
        return TRUE;
 }
 
-#ifdef TIZEN_FEATURE_CSR
 static int __check_csr(const char *path)
 {
        csr_cs_context_h context = NULL;
@@ -348,7 +391,6 @@ static int __check_csr(const char *path)
 
        return 0;
 }
-#endif
 
 static int __kill_app(char *appid, uid_t uid)
 {
@@ -1536,19 +1578,19 @@ gboolean queue_job(void *data)
        /* set current backend job */
        DBG("handle request type [%d]", job->req_type);
 
-#ifdef TIZEN_FEATURE_CSR
-       if (job->req_type == REQUEST_TYPE_INSTALL ||
-                       job->req_type == REQUEST_TYPE_MOUNT_INSTALL ||
-                       job->req_type == REQUEST_TYPE_REINSTALL) {
-               ret = __check_csr(job->pkgid);
-               if (ret != 0) {
-                       ret = -1;
-                       _send_fail_signal(job);
-                       _free_backend_job(job);
-                       return TRUE;
+       if (TIZEN_FEATURE_CSR) {
+               if (job->req_type == REQUEST_TYPE_INSTALL ||
+                               job->req_type == REQUEST_TYPE_MOUNT_INSTALL ||
+                               job->req_type == REQUEST_TYPE_REINSTALL) {
+                       ret = __check_csr(job->pkgid);
+                       if (ret != 0) {
+                               ret = -1;
+                               _send_fail_signal(job);
+                               _free_backend_job(job);
+                               return TRUE;
+                       }
                }
        }
-#endif
 
        switch (job->req_type) {
        case REQUEST_TYPE_INSTALL: