Remove Profile Build Dependency: Do it at runtime 29/98329/5
authorMyungJoo Ham <myungjoo.ham@samsung.com>
Thu, 17 Nov 2016 05:44:57 +0000 (14:44 +0900)
committerMyungJoo Ham <myungjoo.ham@samsung.com>
Wed, 4 Jan 2017 02:19:01 +0000 (11:19 +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.

- When SR-ing this commit, maintainers need to create JIRA-TRE issue of

  Add net-config-profile_tv for TV profile

patchset5: code style update

Change-Id: I8641e53861df320698a6fba0dca1dd0ebcffeaa6
Signed-off-by: MyungJoo Ham <myungjoo.ham@samsung.com>
12 files changed:
CMakeLists.txt
include/util.h
include/wifi-power.h
include/wifi.h
packaging/net-config.spec
src/main.c
src/utils/util.c
src/wifi-config.c
src/wifi-firmware.c
src/wifi-power.c
src/wifi-wps.c
src/wifi.c

index 7c65574..fbf35e8 100755 (executable)
@@ -68,26 +68,10 @@ IF(TIZEN_CAPTIVE_PORTAL)
        SET(SRCS ${SRCS} src/utils/network-accessibility.c)
 ENDIF(TIZEN_CAPTIVE_PORTAL)
 
-IF(TIZEN_TV)
-       ADD_DEFINITIONS(-DTIZEN_TV)
-ENDIF(TIZEN_TV)
-
 IF(TIZEN_WEARABLE)
        ADD_DEFINITIONS(-DTIZEN_WEARABLE)
 ENDIF(TIZEN_WEARABLE)
 
-IF(TIZEN_TELEPHONY_ENABLE)
-       ADD_DEFINITIONS(-DTIZEN_TELEPHONY_ENABLE)
-ENDIF(TIZEN_TELEPHONY_ENABLE)
-
-IF(TIZEN_NTP_ENABLE)
-       ADD_DEFINITIONS(-DTIZEN_NTP_ENABLE)
-ENDIF(TIZEN_NTP_ENABLE)
-
-IF(TIZEN_WLAN_BOARD_SPRD)
-       ADD_DEFINITIONS(-DTIZEN_WLAN_BOARD_SPRD)
-ENDIF(TIZEN_WLAN_BOARD_SPRD)
-
 INCLUDE(FindPkgConfig)
 PKG_CHECK_MODULES(pkgs REQUIRED
        dlog
index 9df584b..908c737 100755 (executable)
@@ -83,4 +83,19 @@ void netconfig_set_mac_address_from_file(void);
 }
 #endif
 
+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 TIZEN_TELEPHONY_ENABLE (_get_tizen_profile() == TIZEN_PROFILE_MOBILE)
+#define TIZEN_WLAN_BOARD_SPRD (_get_tizen_profile() == TIZEN_PROFILE_MOBILE)
+#define TIZEN_TV (_get_tizen_profile() == TIZEN_PROFILE_TV)
+#define TIZEN_NTP_ENABLE (_get_tizen_profile() == TIZEN_PROFILE_IVI)
+
 #endif /* __NETCONFIG_UTIL_H__ */
index 4929ba4..66af3ef 100755 (executable)
@@ -44,9 +44,7 @@ gboolean      handle_remove_driver(Wifi *wifi, GDBusMethodInvocation *context);
 gboolean       handle_load_p2p_driver(Wifi *wifi, GDBusMethodInvocation *context);
 gboolean       handle_remove_p2p_driver(Wifi *wifi, GDBusMethodInvocation *context);
 
-#if defined TIZEN_TV
-       void __netconfig_set_ether_macaddr();
-#endif
+void __netconfig_set_ether_macaddr();
 
 #ifdef __cplusplus
 }
index 7dfa070..84d030f 100755 (executable)
@@ -37,10 +37,7 @@ extern "C" {
 void __netconfig_wifi_connect_reply(GObject *source_object, GAsyncResult *res,
                gpointer user_data);
 
-#if defined TIZEN_WLAN_BOARD_SPRD
 int wifi_firmware_download(void);
-#endif
-
 void wifi_object_create_and_init(void);
 void wifi_object_deinit(void);
 
index 757375e..c3cf2f0 100755 (executable)
@@ -27,15 +27,38 @@ Requires:           systemd
 Requires(post):                systemd
 Requires(preun):       systemd
 Requires(postun):      systemd
+Provides:       %{name}-profile_common = %{version}-%{release}
+Provides:       %{name}-profile_mobile = %{version}-%{release}
+Provides:       %{name}-profile_wearable = %{version}-%{release}
+Provides:       %{name}-profile_ivi = %{version}-%{release}
 
 %define upgrade_script_path /usr/share/upgrade/scripts
 
 %description
 TIZEN Network Configuration service
 
+%package profile_tv
+Summary:        net-config extension for TV profile
+Requires:       %{name} = %{version}-%{release}
+%description profile_tv
+TIZEN Network Configuration service extension for Tizen TV profile.
+
+
 %prep
 %setup -q
 
+# NOTE: the following macros are undefined.
+# PLEASE DO NOT USE model_build_features in the future with Tizen 4.0+.
+#{?model_build_feature_wlan_concurrent_mode}
+#{?model_build_feature_wlan_p2p_disable}
+#{?model_build_feature_network_tethering_disable}
+#{?model_build_feature_wlan_wearable}
+# In case, we have commercializing team using such unwelcomed
+# macros in their productin build, we are keeping those.
+# However, it is recommended to remove all if/endif with model_build_feature
+
+# NOTE: Are we really going to make "mobile" == "SPRD"?
+
 %build
 cmake -DCMAKE_INSTALL_PREFIX=%{_prefix} \
        -DTIZEN_WLAN_PASSPOINT=1 \
@@ -49,17 +72,6 @@ cmake -DCMAKE_INSTALL_PREFIX=%{_prefix} \
 %if ! 0%{?model_build_feature_network_tethering_disable}
        -DTIZEN_TETHERING_ENABLE=1 \
 %endif
-%if "%{profile}" == "mobile"
-       -DTIZEN_TELEPHONY_ENABLE=1 \
-       -DTIZEN_WLAN_BOARD_SPRD=1 \
-%else
-%if "%{profile}" == "tv"
-       -DTIZEN_TV=1 \
-%endif
-%endif
-%if "%{profile}" == "ivi"
-       -DTIZEN_NTP_ENABLE=1 \
-%endif
 %if 0%{?model_build_feature_wlan_wearable} == 1
        -DTIZEN_WEARABLE=1 \
        -DTIZEN_CAPTIVE_PORTAL=1 \
@@ -78,19 +90,16 @@ mkdir -p %{buildroot}%{_libdir}/systemd/system/
 mkdir -p %{buildroot}%{_unitdir}
 %endif
 
-%if "%{profile}" == "tv"
-cp resources/usr/lib/systemd/system/net-config_tv.service %{buildroot}%{_libdir}/systemd/system/net-config.service
+cp resources/usr/lib/systemd/system/net-config_tv.service %{buildroot}%{_libdir}/systemd/system/net-config.service.tv
 mkdir -p %{buildroot}%{_libdir}/udev/rules.d/
 cp resources/usr/lib/udev/rules.d/99-wifiusb-dev.rules %{buildroot}%{_libdir}/udev/rules.d/99-wifiusb-dev.rules
 %if "%{?_lib}" == "lib64"
-cp resources/usr/lib/systemd/system/net-config_tv.service %{buildroot}%{_unitdir}/net-config.service
+cp resources/usr/lib/systemd/system/net-config_tv.service %{buildroot}%{_unitdir}/net-config.service.tv
 %endif
-%else
 cp resources/usr/lib/systemd/system/net-config.service %{buildroot}%{_libdir}/systemd/system/net-config.service
 %if "%{?_lib}" == "lib64"
 cp resources/usr/lib/systemd/system/net-config.service %{buildroot}%{_unitdir}/net-config.service
 %endif
-%endif
 
 mkdir -p %{buildroot}%{_libdir}/systemd/system/multi-user.target.wants/
 ln -s ../net-config.service %{buildroot}%{_libdir}/systemd/system/multi-user.target.wants/net-config.service
@@ -162,11 +171,19 @@ ln -sf %{_unitdir}/net-config.service %{_sysconfdir}/systemd/default-extra-depen
 %attr(644,root,root) %{_unitdir}/multi-user.target.wants/net-config.service
 %endif
 %{_datadir}/license/net-config
-%if "%{profile}" == "tv"
-%attr(644,root,root) %{_libdir}/udev/rules.d/99-wifiusb-dev.rules
-%endif
 %if 0%{?model_build_feature_wlan_wearable} == 1
 %attr(700,root,root) /usr/system/RestoreDir/softreset/network_softreset.sh
 %endif
 %{upgrade_script_path}/500.netconfig_upgrade.sh
 
+%post profile_tv
+mv %{_libdir}/systemd/system/net-config.service.tv %{_libdir}/systemd/system/net-config.service
+%if "%{?_lib}" == "lib64"
+mv %{_unitdir}/net-config.service.tv %{_unitdir}/net-config.service
+%endif
+%files profile_tv
+%attr(644,root,root) %{_libdir}/udev/rules.d/99-wifiusb-dev.rules
+%attr(644,root,root) %{_libdir}/systemd/system/net-config.service.tv
+%if "%{?_lib}" == "lib64"
+%attr(644,root,root) %{_unitdir}/net-config.service.tv
+%endif
index 6dda9ac..c3a3584 100755 (executable)
@@ -24,6 +24,7 @@
 #include <system_info.h>
 
 #include "log.h"
+#include "util.h"
 #include "wifi.h"
 #include "netdbus.h"
 #include "emulator.h"
@@ -62,9 +63,8 @@ void _got_name_cb(void)
        register_gdbus_signal();
        connman_register_agent();
 
-#if defined TIZEN_TV
-       __netconfig_set_ether_macaddr();
-#endif
+       if (TIZEN_TV)
+               __netconfig_set_ether_macaddr();
 }
 
 static void _objects_deinit(void)
@@ -118,9 +118,8 @@ int main(int argc, char *argv[])
 
        netconfig_error_init();
 
-#if defined TIZEN_NTP_ENABLE
-       netconfig_clock_init();
-#endif
+       if (TIZEN_NTP_ENABLE)
+               netconfig_clock_init();
 
        /* If its environment uses Emulator, network configuration is set by emulator default */
        emulator_test_and_start();
@@ -128,15 +127,12 @@ int main(int argc, char *argv[])
        /* For device policy manager */
        netconfig_dpm_init();
 
-#if defined TIZEN_WLAN_BOARD_SPRD
-       wifi_firmware_download();
-#endif
+       if (TIZEN_WLAN_BOARD_SPRD)
+               wifi_firmware_download();
 
        /*In case no emulator, set the ETH0 Mac address*/
-#if defined TIZEN_TV
-       if (emulator_is_emulated() == FALSE)
+       if (TIZEN_TV && emulator_is_emulated() == FALSE)
                __netconfig_set_ether_macaddr();
-#endif
 
        if (!system_info_get_platform_bool(ETHERNET_FEATURE, &ethernet_feature_supported)) {
                if (ethernet_feature_supported == TRUE) {
@@ -159,9 +155,8 @@ int main(int argc, char *argv[])
 
        netconfig_dpm_deinit();
 
-#if defined TIZEN_NTP_ENABLE
-       netconfig_clock_deinit();
-#endif
+       if (TIZEN_NTP_ENABLE)
+               netconfig_clock_deinit();
 
 
        /*remove the Timer*/
index 3124924..6fbba12 100755 (executable)
@@ -36,6 +36,7 @@
 #include <bundle_internal.h>
 #include <eventsystem.h>
 #include <tzplatform_config.h>
+#include <system_info.h>
 
 #include "log.h"
 #include "util.h"
@@ -1084,3 +1085,36 @@ void netconfig_set_mac_address_from_file(void)
        g_free(mac_lower_str);
        fclose(file);
 }
+
+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 unknown ==> ALL ARE COMMON.
+               profile = TIZEN_PROFILE_COMMON;
+       }
+       free(profileName);
+
+       return profile;
+}
index 3476576..28facba 100755 (executable)
@@ -103,41 +103,42 @@ static gboolean __get_mac_address(gchar **mac_address)
        gchar *tmp = NULL;
        gchar mac[13] = { 0, };
        gint i = 0, j = 0;
-#if defined TIZEN_TV
-       FILE *fp = NULL;
-       char buf[WIFI_MAC_ADD_LENGTH + 1];
-       if (0 == access(WIFI_MAC_ADD_PATH, F_OK))
-               fp = fopen(WIFI_MAC_ADD_PATH, "r");
-
-       if (fp == NULL) {
-               ERR("Failed to open file %s\n", WIFI_MAC_ADD_PATH);
-               *mac_address = NULL;
-               return FALSE;
-       }
 
-       if (fgets(buf, sizeof(buf), fp) == NULL) {
-               ERR("Failed to get MAC info from %s\n", WIFI_MAC_ADD_PATH);
-               *mac_address = NULL;
-               fclose(fp);
-               return FALSE;
-       }
-       tmp_mac = (char *)g_try_malloc0(WIFI_MAC_ADD_LENGTH + 1);
-       if (tmp_mac == NULL) {
-               ERR("malloc() failed");
-               *mac_address = NULL;
+       if (TIZEN_TV) {
+               FILE *fp = NULL;
+               char buf[WIFI_MAC_ADD_LENGTH + 1];
+               if (0 == access(WIFI_MAC_ADD_PATH, F_OK))
+                       fp = fopen(WIFI_MAC_ADD_PATH, "r");
+
+               if (fp == NULL) {
+                       ERR("Failed to open file %s\n", WIFI_MAC_ADD_PATH);
+                       *mac_address = NULL;
+                       return FALSE;
+               }
+
+               if (fgets(buf, sizeof(buf), fp) == NULL) {
+                       ERR("Failed to get MAC info from %s\n", WIFI_MAC_ADD_PATH);
+                       *mac_address = NULL;
+                       fclose(fp);
+                       return FALSE;
+               }
+               tmp_mac = (char *)g_try_malloc0(WIFI_MAC_ADD_LENGTH + 1);
+               if (tmp_mac == NULL) {
+                       ERR("malloc() failed");
+                       *mac_address = NULL;
+                       fclose(fp);
+                       return FALSE;
+               }
+               g_strlcpy(tmp_mac, buf, WIFI_MAC_ADD_LENGTH + 1);
                fclose(fp);
-               return FALSE;
-       }
-       g_strlcpy(tmp_mac, buf, WIFI_MAC_ADD_LENGTH + 1);
-       fclose(fp);
-#else
-       tmp_mac = vconf_get_str(VCONFKEY_WIFI_BSSID_ADDRESS);
-       if (tmp_mac == NULL) {
-               ERR("vconf_get_str(WIFI_BSSID_ADDRESS) Failed");
-               *mac_address = NULL;
-               return FALSE;
+       } else {
+               tmp_mac = vconf_get_str(VCONFKEY_WIFI_BSSID_ADDRESS);
+               if (tmp_mac == NULL) {
+                       ERR("vconf_get_str(WIFI_BSSID_ADDRESS) Failed");
+                       *mac_address = NULL;
+                       return FALSE;
+               }
        }
-#endif
        tmp = g_ascii_strdown(tmp_mac, (gssize)strlen(tmp_mac));
        g_free(tmp_mac);
        while (tmp && tmp[i]) {
index 797e3c4..d9a41f9 100755 (executable)
 #define WLAN_DRIVER_SCRIPT                     "/usr/bin/wlan.sh"
 #define WLAN_IFACE_NAME                                "wlan0"
 
-#if defined(TIZEN_TV)
-#define WLAN_P2P_IFACE_NAME                    "p2p0"
-#else /* defined(TIZEN_TV) */
-#define WLAN_P2P_IFACE_NAME                    "wlan0"
-#endif /* defined(TIZEN_TV) */
+#define WLAN_P2P_IFACE_NAME_TV                 "p2p0"
+#define WLAN_P2P_IFACE_NAME_COMMON                     "wlan0"
+#define WLAN_P2P_IFACE_NAME ((TIZEN_TV) ? (WLAN_P2P_IFACE_NAME_TV) : (WLAN_P2P_IFACE_NAME_COMMON))
 
 static int __netconfig_sta_firmware_start(void)
 {
index fe43bf5..fc4ca6b 100755 (executable)
 #define WLAN_MAC_ADDR_MAX          20
 #define VCONF_WIFI_BSSID_ADDRESS       "db/wifi/bssid_address"
 
-#if defined TIZEN_TV
 #define ETH_MAC_ADDR_SIZE 6
 #define VCONF_ETH_MAC_ADDRESS  "db/dnet/mac_address"
 #define NET_EXEC_PATH "/sbin/ifconfig"
 #define OS_RANDOM_FILE "/dev/urandom"
-#endif
 
 static gboolean connman_wifi_technology_state = FALSE;
 static gboolean wifi_firmware_recovery_mode = FALSE;
@@ -647,7 +645,6 @@ static void __pm_state_changed_cb(keynode_t* node, void* user_data)
        prev_state = new_state;
 }
 
-#if defined TIZEN_TELEPHONY_ENABLE
 static void _tapi_noti_sim_status_cb(TapiHandle *handle, const char *noti_id,
                                                                                void *data, void *user_data)
 {
@@ -740,7 +737,6 @@ static void __netconfig_telephony_ready_changed_cb(keynode_t * node, void *data)
 done:
        vconf_ignore_key_changed(VCONFKEY_TELEPHONY_READY, __netconfig_telephony_ready_changed_cb);
 }
-#endif
 
 int wifi_power_driver_and_supplicant(gboolean enable)
 {
@@ -874,18 +870,18 @@ void wifi_power_initialize(void)
        /* Update the last Wi-Fi power state */
        netconfig_vconf_get_int(VCONF_WIFI_LAST_POWER_STATE, &wifi_last_power_state);
        if (wifi_last_power_state > VCONFKEY_WIFI_OFF) {
-#if defined TIZEN_TELEPHONY_ENABLE
-               int telephony_ready = 0;
-               netconfig_vconf_get_bool(VCONFKEY_TELEPHONY_READY, &telephony_ready);
-               if (telephony_ready == 0) {
-                       DBG("Telephony API is not initialized yet");
-                       vconf_notify_key_changed(VCONFKEY_TELEPHONY_READY,
-                                       __netconfig_telephony_ready_changed_cb, NULL);
-               } else {
-                       if (netconfig_tapi_check_sim_state() == FALSE)
-                               DBG("SIM is not initialized yet");
+               if (TIZEN_TELEPHONY_ENABLE) {
+                       int telephony_ready = 0;
+                       netconfig_vconf_get_bool(VCONFKEY_TELEPHONY_READY, &telephony_ready);
+                       if (telephony_ready == 0) {
+                               DBG("Telephony API is not initialized yet");
+                               vconf_notify_key_changed(VCONFKEY_TELEPHONY_READY,
+                                               __netconfig_telephony_ready_changed_cb, NULL);
+                       } else {
+                               if (netconfig_tapi_check_sim_state() == FALSE)
+                                       DBG("SIM is not initialized yet");
+                       }
                }
-#endif
                DBG("Turn Wi-Fi on automatically");
 #if defined TIZEN_WEARABLE
                wifi_power_on_wearable(TRUE);
@@ -929,9 +925,8 @@ gboolean handle_load_driver(Wifi *wifi,
                return TRUE;
        }
 
-#if defined TIZEN_WLAN_BOARD_SPRD
-       wifi_firmware_download();
-#endif
+       if (TIZEN_WLAN_BOARD_SPRD)
+               wifi_firmware_download();
 
 #if defined TIZEN_WEARABLE
        err = wifi_power_on_wearable(device_picker_test);
@@ -1005,7 +1000,6 @@ gboolean handle_remove_p2p_driver(Wifi *wifi, GDBusMethodInvocation *context)
        return TRUE;
 }
 
-#if defined TIZEN_TV
 static int __netconfig_get_random_mac(unsigned char *mac_buf, int mac_len)
 {
        DBG("Generate Random Mac address of ethernet");
@@ -1077,4 +1071,3 @@ void __netconfig_set_ether_macaddr()
        g_free(mac_addr);
 
 }
-#endif
index 544751e..b1771cb 100755 (executable)
@@ -537,7 +537,6 @@ gboolean handle_request_wps_scan(Wifi *wifi, GDBusMethodInvocation *context)
        return TRUE;
 }
 
-#if defined TIZEN_TV
 static void __interface_wps_cancel_result(GObject *source_object,
                        GAsyncResult *res, gpointer user_data)
 {
@@ -586,16 +585,15 @@ static gboolean __netconfig_wifi_invoke_wps_cancel()
 
        return reply;
 }
-#endif
 
 gboolean netconfig_iface_wifi_request_wps_cancel(Wifi *wifi, GDBusMethodInvocation **context)
 {
-#if defined TIZEN_TV
-       DBG("Received WPS PBC Cancel Request");
-       g_return_val_if_fail(wifi != NULL, FALSE);
-       return __netconfig_wifi_invoke_wps_cancel();
-#else
-       /*Not supported for mobile and Wearable profile*/
-       return FALSE;
-#endif
+       if (TIZEN_TV) {
+               DBG("Received WPS PBC Cancel Request");
+               g_return_val_if_fail(wifi != NULL, FALSE);
+               return __netconfig_wifi_invoke_wps_cancel();
+       } else {
+               /*Not supported for mobile and Wearable profile*/
+               return FALSE;
+       }
 }
index 86c3bb6..255b0e9 100755 (executable)
 #include "wifi-config.h"
 #include "wifi-tdls.h"
 
-#if defined TIZEN_WLAN_BOARD_SPRD
 #define SPRD_CP2_FIRMWARE_PATH "/usr/bin/cp2-downloader"
 static int is_wifi_firmware_downloaded = FALSE;
-#endif
 
 static Wifi *wifi_object = NULL;
 static NetConnmanAgent *connman_agent_object = NULL;
@@ -108,7 +106,6 @@ void __netconfig_wifi_connect_reply(GObject *source_object, GAsyncResult *res,
        return;
 }
 
-#if defined TIZEN_WLAN_BOARD_SPRD
 int wifi_firmware_download(void)
 {
        int rv = 0;
@@ -128,7 +125,6 @@ int wifi_firmware_download(void)
 
        return 0;
 }
-#endif
 
 void wifi_object_create_and_init(void)
 {