Revert model-config
authorNam KwanWoo <kw46.nam@samsung.com>
Mon, 24 Jun 2013 08:52:51 +0000 (17:52 +0900)
committerNam KwanWoo <kw46.nam@samsung.com>
Mon, 24 Jun 2013 08:52:51 +0000 (17:52 +0900)
Change-Id: I7819792bb21a5b0d896ca8e708ead9b5545a737f

CMakeLists.txt
include/system_info.h
include/system_info_private.h
packaging/capi-system-info.spec
src/system_info.c
src/system_info_device.c
src/system_info_screen.c
src/system_info_vconf.c [new file with mode: 0644]

index a276b01..7dfb933 100644 (file)
@@ -10,7 +10,7 @@ SET(PREFIX ${CMAKE_INSTALL_PREFIX})
 SET(INC_DIR include)
 INCLUDE_DIRECTORIES(${INC_DIR})
 
-SET(requires "dlog capi-base-common iniparser libxml-2.0")
+SET(requires "dlog capi-base-common x11 xi xrandr xproto vconf iniparser libxml-2.0")
 SET(pc_requires "capi-base-common")
 
 INCLUDE(FindPkgConfig)
index 7b6133f..6227be5 100644 (file)
@@ -143,6 +143,11 @@ int system_info_get_value_double(system_info_key_e key, double *value);
  */
 int system_info_get_value_string(system_info_key_e key, char **value);
 
+int system_info_get_external_bool(const char *key, bool *value);
+int system_info_get_external_int(const char *key, int *value);
+int system_info_get_external_double(const char *key, double *value);
+int system_info_get_external_string(const char *key, char **value);
+
 /**
  * @brief   Gets the boolean value of the platform feature
  * @param[in] key The name of the platform feature to get
index 398a16d..ec09ad6 100644 (file)
@@ -27,9 +27,12 @@ extern "C"
 #define OS_RELEASE_FILE_PATH "/etc/os-release"
 #define CPU_INFO_FILE_PATH "/proc/cpuinfo"
 #define CPU_INFO_MAX_FREQ_PATH "/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq"
+#define CMDLINE_PATH "/proc/cmdline"
 #define CONFIG_FILE_PATH "/etc/config/model-config.xml"
 #define MAXBUFSIZE 512
 
+#define EXTERNAL_VCONF_PREFIX "db/externals/"
+
 #define PLATFORM_TAG   "platform"
 #define CUSTOM_TAG     "custom"
 #define INTERNAL_TAG   "internal"
index 769c985..e0ed85c 100644 (file)
@@ -9,6 +9,11 @@ Source0:       %{name}-%{version}.tar.gz
 BuildRequires: cmake
 BuildRequires: pkgconfig(dlog)
 BuildRequires: pkgconfig(capi-base-common)
+BuildRequires:  pkgconfig(vconf)
+BuildRequires:  pkgconfig(x11)
+BuildRequires:  pkgconfig(xi)
+BuildRequires: pkgconfig(xrandr)
+BuildRequires: pkgconfig(xproto)
 BuildRequires: pkgconfig(iniparser)
 BuildRequires:         pkgconfig(libxml-2.0)
 
index fb627bc..09c676a 100644 (file)
@@ -20,6 +20,7 @@
 #include <string.h>
 #include <unistd.h>
 
+#include <vconf.h>
 #include <dlog.h>
 
 #include <system_info.h>
@@ -681,6 +682,61 @@ int system_info_get_custom_int(const char *key, int *value)
        return SYSTEM_INFO_ERROR_NONE;
 }
 
+int system_info_get_external_bool(const char *key, bool *value)
+{
+       char vconfkey[MAXBUFSIZE] = {0,};
+
+       snprintf(vconfkey, strlen(EXTERNAL_VCONF_PREFIX)+strlen(key)+1, "%s%s", EXTERNAL_VCONF_PREFIX, key);
+
+       if (system_info_vconf_get_value_bool(vconfkey, value)) {
+               LOGE("key : %s, failed get bool value", key);
+               return SYSTEM_INFO_ERROR_IO_ERROR;
+       }
+
+       return SYSTEM_INFO_ERROR_NONE;
+}
+
+int system_info_get_external_int(const char *key, int *value)
+{
+       char vconfkey[MAXBUFSIZE] = {0,};
+
+       snprintf(vconfkey, strlen(EXTERNAL_VCONF_PREFIX)+strlen(key)+1, "%s%s", EXTERNAL_VCONF_PREFIX, key);
+
+       if (system_info_vconf_get_value_int(vconfkey, value)) {
+               LOGE("key : %s, failed get int value", key);
+               return SYSTEM_INFO_ERROR_IO_ERROR;
+       }
+
+       return SYSTEM_INFO_ERROR_NONE;
+}
+
+int system_info_get_external_double(const char *key, double *value)
+{
+       char vconfkey[MAXBUFSIZE] = {0,};
+
+       snprintf(vconfkey, strlen(EXTERNAL_VCONF_PREFIX)+strlen(key)+1, "%s%s", EXTERNAL_VCONF_PREFIX, key);
+
+       if (system_info_vconf_get_value_double(vconfkey, value)) {
+               LOGE("key : %s, failed get double value", key);
+               return SYSTEM_INFO_ERROR_IO_ERROR;
+       }
+
+       return SYSTEM_INFO_ERROR_NONE;
+}
+
+int system_info_get_external_string(const char *key, char **value)
+{
+       char vconfkey[MAXBUFSIZE] = {0,};
+
+       snprintf(vconfkey, strlen(EXTERNAL_VCONF_PREFIX)+strlen(key)+1, "%s%s", EXTERNAL_VCONF_PREFIX, key);
+
+       if (system_info_vconf_get_value_string(vconfkey, value)) {
+               LOGE("key : %s, failed get string value", key);
+               return SYSTEM_INFO_ERROR_IO_ERROR;
+       }
+
+       return SYSTEM_INFO_ERROR_NONE;
+}
 int system_info_get_custom_double(const char *key, double *value)
 {
        int ret;
index d3c502e..b01cf21 100644 (file)
 #include <string.h>
 #include <unistd.h>
 
+#include <X11/extensions/XI2.h>
+#include <X11/extensions/XI2proto.h>
+#include <X11/Xlib.h>
+#include <X11/Xatom.h>
+#include <X11/extensions/XInput2.h>
+
 #include <dlog.h>
 
 #include <system_info.h>
@@ -30,6 +36,8 @@
 
 #define LOG_TAG "CAPI_SYSTEM_INFO"
 
+#define PROP_MULTITOUCH        "EvdevMultitouch MultiTouch"
+
 #define TETHERING_INFO_FILE_PATH "/etc/config/connectivity/sysinfo-tethering.xml"
 #define CAMERA_INFO_FILE_PATH  "/usr/etc/mmfw_camcorder.ini"
 
@@ -78,9 +86,126 @@ int system_info_get_keyboard_type(system_info_key_e key, system_info_data_type_e
        return system_info_get_platform_string("tizen.org/feature/input.keyboard.layout", (char**)value);
 }
 
+extern char *strcasestr(const char *s, const char *find);
+
+int xinput_extension_init(Display *disp)
+{
+       int opcode;
+       int event, error;
+       int major = XI_2_Major, minor = XI_2_Minor;
+
+       if (!XQueryExtension(disp, "XInputExtension", &opcode, &event, &error)) {
+               LOGE("XInput Extension isn't supported.");
+               return SYSTEM_INFO_ERROR_IO_ERROR;
+       }
+
+       if (XIQueryVersion(disp, &major, &minor) == BadRequest) {
+               LOGE("Failed to query XI version.");
+               return SYSTEM_INFO_ERROR_IO_ERROR;
+       }
+
+       if (!(major >= XI_2_Major && minor >= XI_2_Minor)) {
+               LOGE("XI2 is not supported ! (major:%d, minor:%d)", major, minor);
+               return SYSTEM_INFO_ERROR_IO_ERROR;
+       }
+       return opcode;
+}
+
+int get_device_property_value(Display *disp, int deviceid, Atom prop)
+{
+       Atom act_type;
+       unsigned long nitems, bytes_after;
+       unsigned char *data;
+       int act_format, ret = -1;
+
+       if (XIGetProperty(disp, deviceid, prop, 0, 1000, False,
+                                                       XA_INTEGER, &act_type, &act_format,
+                                                       &nitems, &bytes_after, &data) != Success) {
+               LOGE("Failed to get XI2 device property !(deviceid=%d)", deviceid);
+               return SYSTEM_INFO_ERROR_IO_ERROR;
+       }
+
+       if (!nitems)
+               goto out;
+
+       ret = (int)*data;
+
+out:
+       if (data)
+               XFree(data);
+
+       return ret;
+}
+
+int get_multitouch_max_count(Display *disp)
+{
+       int i;
+       int max_count;
+       int ndevices;
+       XIDeviceInfo *dev, *info = NULL;
+       Atom atomMultiTouch;
+       int xi_opcode = xinput_extension_init(disp);
+
+       if (0 >= xi_opcode) {
+               LOGE("Failed to initialize X Input Extension !");
+               return SYSTEM_INFO_ERROR_IO_ERROR;
+       }
+
+       atomMultiTouch = XInternAtom(disp, PROP_MULTITOUCH, True);
+
+       if (!atomMultiTouch) {
+               LOGE("Failed to make an atom for multitouch property !");
+               return SYSTEM_INFO_ERROR_IO_ERROR;
+       }
+
+       info = XIQueryDevice(disp, XIAllDevices, &ndevices);
+
+       if (!info) {
+               LOGE("Failed to query XI device.");
+               return SYSTEM_INFO_ERROR_IO_ERROR;
+       }
+
+       for (i = 0; i < ndevices ; i++) {
+               dev = &info[i];
+
+               switch (dev->use) {
+               case XISlavePointer:
+                       if (strcasestr(dev->name, "virtual") && !strcasestr(dev->name, "maru"))
+                               continue;
+                       if (strcasestr(dev->name, "extended"))
+                               continue;
+                       if (!strcasestr(dev->name, "touch"))
+                               continue;
+                       max_count = get_device_property_value(disp, dev->deviceid, atomMultiTouch);
+                       goto out;
+               }
+       }
+
+       XIFreeDeviceInfo(info);
+       return -1;
+
+out:
+       XIFreeDeviceInfo(info);
+       return max_count;
+}
+
 int system_info_get_multi_point_touch_count(system_info_key_e key, system_info_data_type_e data_type, void **value)
 {
-       return system_info_get_platform_int("tizen.org/feature/multi_point_touch.point_count", (int *)value);
+       int *count;
+       Display *disp;
+
+       count = (int *)value;
+
+       disp = XOpenDisplay(NULL);
+
+       if (!disp) {
+               LOGE("Failed to open display!");
+               return SYSTEM_INFO_ERROR_IO_ERROR;
+       }
+
+       *count = get_multitouch_max_count(disp);
+
+       return SYSTEM_INFO_ERROR_NONE;
 }
 
 int system_info_get_nfc_supported(system_info_key_e key, system_info_data_type_e data_type, void **value)
index b28f058..707adc7 100644 (file)
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <math.h>
 
 #include <dlog.h>
 
+#include <X11/X.h>
+#include <X11/Xlib.h>
+#include <X11/extensions/Xrandr.h>
+
 #include <system_info.h>
 #include <system_info_private.h>
 
 
 #define LOG_TAG "CAPI_SYSTEM_INFO"
 
+typedef struct _progInfo ProgInfo;
+
+/* globals */
+ProgInfo g_pinfo;
+
+struct _progInfo {
+       Display *dpy;
+       Window root;
+       int screen;
+       int event_base, error_base;
+       int major, minor;
+       XRRScreenResources *res;
+};
+
+static int RCA_SUPPORTED;
+static int HDMI_SUPPORTED;
+static int SCREEN_DPI;
+static int BITS_PER_PIXEL;
+static int SCREEN_WIDTH;
+static int SCREEN_HEIGHT;
+static int PHYSICAL_SCREEN_WIDTH;
+static int PHYSICAL_SCREEN_HEIGHT;
+int system_info_screen_initialized;
+
+int system_info_screen_init()
+{
+       int i, n;
+       XPixmapFormatValues *pmf = NULL;
+
+       memset(&g_pinfo, 0x0, sizeof(ProgInfo));
+
+       g_pinfo.dpy = XOpenDisplay(NULL);
+       if (NULL == g_pinfo.dpy) {
+               LOGE("XOpenDisplay Failed");
+               return -1;
+       }
+
+       if (0 > g_pinfo.screen)
+               g_pinfo.screen = DefaultScreen(g_pinfo.dpy);
+       g_pinfo.root = RootWindow(g_pinfo.dpy, g_pinfo.screen);
+
+       if (!XRRQueryExtension(g_pinfo.dpy, &g_pinfo.event_base, &g_pinfo.error_base) ||
+               !XRRQueryVersion(g_pinfo.dpy, &g_pinfo.major, &g_pinfo.minor)) {
+               LOGE("XRRQuery Failed");
+               XCloseDisplay(g_pinfo.dpy);
+               return -1;
+       }
+
+       g_pinfo.res = XRRGetScreenResources(g_pinfo.dpy, g_pinfo.root);
+
+       if (!g_pinfo.res) {
+               LOGE("XRRGetScreenResources Failed");
+               XCloseDisplay(g_pinfo.dpy);
+               return -1;
+       }
+
+       pmf = XListPixmapFormats(g_pinfo.dpy, &n);
+
+       if (!pmf) {
+               LOGE("XListPixmapFormats Failed");
+               XCloseDisplay(g_pinfo.dpy);
+               return -1;
+       }
+
+       for (i = 0; i < n; i++) {
+               if (BITS_PER_PIXEL < pmf[i].bits_per_pixel)
+                       BITS_PER_PIXEL = pmf[i].bits_per_pixel;
+       }
+       XFree(pmf);
+       pmf = NULL;
+
+       for (i = 0; i < g_pinfo.res->noutput; i++) {
+               XRROutputInfo *output_info = XRRGetOutputInfo(g_pinfo.dpy, g_pinfo.res, g_pinfo.res->outputs[i]);
+               if (!output_info) {
+                       LOGE("XRRGetOutputInfo Failed");
+                       XCloseDisplay(g_pinfo.dpy);
+                       return -1;
+               }
+
+               /* find target lcd */
+               if (!strcmp(output_info->name, "LVDS1")) {
+                       /* XRRCrtcInfo information */
+                       XRRCrtcInfo *crtc_info = XRRGetCrtcInfo(g_pinfo.dpy, g_pinfo.res, output_info->crtc);
+                       if (!crtc_info)
+                               break;
+
+                       SCREEN_WIDTH = crtc_info->width;
+                       SCREEN_HEIGHT = crtc_info->height;
+                       PHYSICAL_SCREEN_WIDTH = output_info->mm_width;
+                       PHYSICAL_SCREEN_HEIGHT = output_info->mm_height;
+
+                       XRRFreeCrtcInfo(crtc_info);
+               } else if (!strcmp(output_info->name, "HDMI1"))
+                       HDMI_SUPPORTED = true;
+               XRRFreeOutputInfo(output_info);
+       }
+
+       if (BITS_PER_PIXEL == 0) {
+               LOGE("BIT PER PIXEL is Zero");
+               XCloseDisplay(g_pinfo.dpy);
+               return -1;
+       }
+
+       if (!SCREEN_WIDTH)
+               SCREEN_WIDTH = DisplayWidth(g_pinfo.dpy, DefaultScreen(g_pinfo.dpy));
+
+       if (!SCREEN_WIDTH) {
+               LOGE("SCREEN WIDTH is Zero");
+               XCloseDisplay(g_pinfo.dpy);
+               return -1;
+       }
+
+       if (!SCREEN_HEIGHT)
+               SCREEN_HEIGHT = DisplayHeight(g_pinfo.dpy, DefaultScreen(g_pinfo.dpy));
+
+       if (!SCREEN_HEIGHT) {
+               LOGE("SCREEN HEIGHT is Zero");
+               XCloseDisplay(g_pinfo.dpy);
+               return -1;
+       }
+
+       if (system_info_get_system_info_model_type() == SYSTEM_INFO_MODEL_TYPE_EMULATOR) {
+               FILE *cmdline;
+               char *dpi;
+               char str[MAXBUFSIZE];
+
+               cmdline = fopen(CMDLINE_PATH, "r");
+               if (NULL == cmdline) {
+                       LOGE("cannot file open %s file!!!", CPU_INFO_FILE_PATH);
+                       XCloseDisplay(g_pinfo.dpy);
+                       return SYSTEM_INFO_ERROR_IO_ERROR;
+               } else {
+                       while (fgets(str, MAXBUFSIZE, cmdline)) {
+                               dpi = strstr(str, "dpi=");
+                               SCREEN_DPI = atoi(dpi+4) / 10;
+                               break;
+                       }
+               }
+               fclose(cmdline);
+
+       } else {
+               double dp, di;
+
+               /* diagonal size(logical) by pixel */
+               dp = sqrt(SCREEN_WIDTH*SCREEN_WIDTH+SCREEN_HEIGHT*SCREEN_HEIGHT);
+               /* diagonal size(physical) by inch */
+               di = sqrt(PHYSICAL_SCREEN_WIDTH*PHYSICAL_SCREEN_WIDTH + PHYSICAL_SCREEN_HEIGHT*PHYSICAL_SCREEN_HEIGHT) / 10 / 2.54;
+               /* DPI = PPI */
+               SCREEN_DPI = round(dp/di);
+       }
+
+       XCloseDisplay(g_pinfo.dpy);
+
+       system_info_screen_initialized = 1;
+
+       return 0;
+}
+
 int system_info_get_screen_bits_per_pixel(system_info_key_e key, system_info_data_type_e data_type, void **value)
 {
-       return system_info_get_platform_int("tizen.org/feature/screen.bpp", (int *)value);
+       int *bpp;
+       int ret_val;
+
+       bpp = (int *)value;
+
+       if (0 == system_info_screen_initialized) {
+               ret_val = system_info_screen_init();
+               if (ret_val)
+                       return ret_val;
+       }
+
+       *bpp = BITS_PER_PIXEL;
+
+       return SYSTEM_INFO_ERROR_NONE;
 }
 
 int system_info_get_screen_width(system_info_key_e key, system_info_data_type_e data_type, void **value)
 {
-       return system_info_get_platform_int("tizen.org/feature/screen.width", (int *)value);
+       int *width;
+       int ret_val;
+
+       width = (int *)value;
+
+       if (0 == system_info_screen_initialized) {
+               ret_val = system_info_screen_init();
+               if (ret_val)
+                       return ret_val;
+       }
+
+       *width = SCREEN_WIDTH;
+
+       return SYSTEM_INFO_ERROR_NONE;
 }
 
 int system_info_get_screen_height(system_info_key_e key, system_info_data_type_e data_type, void **value)
 {
-       return system_info_get_platform_int("tizen.org/feature/screen.height", (int *)value);
+       int *height;
+       int ret_val;
+
+       height = (int *)value;
+
+       if (0 == system_info_screen_initialized) {
+               ret_val = system_info_screen_init();
+               if (ret_val)
+                       return ret_val;
+       }
+
+       *height = SCREEN_HEIGHT;
+
+       return SYSTEM_INFO_ERROR_NONE;
 }
 
 int system_info_get_screen_DPI(system_info_key_e key, system_info_data_type_e data_type, void **value)
 {
-       return system_info_get_platform_int("tizen.org/feature/screen.dpi", (int *)value);
+       int *bpp;
+       int ret_val;
+
+       bpp = (int *)value;
+
+       if (0 == system_info_screen_initialized) {
+               ret_val = system_info_screen_init();
+               if (ret_val)
+                       return ret_val;
+       }
+
+       *bpp = SCREEN_DPI;
+
+       return SYSTEM_INFO_ERROR_NONE;
 }
 
 int system_info_get_hdmi_supported(system_info_key_e key, system_info_data_type_e data_type, void **value)
 {
-       return system_info_get_platform_bool("tizen.org/feature/screen.output.hdmi", (bool *)value);
+       bool *supported;
+       int ret_val;
+
+       if (0 == system_info_screen_initialized) {
+               ret_val = system_info_screen_init();
+               if (ret_val)
+                       return ret_val;
+       }
+
+       supported = (bool *)value;
+
+       *supported = HDMI_SUPPORTED;
+
+       return SYSTEM_INFO_ERROR_NONE;
 }
 
 int system_info_get_rca_supported(system_info_key_e key, system_info_data_type_e data_type, void **value)
 {
-       return system_info_get_platform_bool("tizen.org/feature/screen.output.rca", (bool *)value);
+       bool *supported;
+
+       supported = (bool *)value;
+
+       *supported = RCA_SUPPORTED;
+
+       return SYSTEM_INFO_ERROR_NONE;
 }
 
 int system_info_get_physical_screen_height(system_info_key_e key, system_info_data_type_e data_type, void **value)
 {
-       return system_info_get_platform_int("tizen.org/feature/screen.height", (int *)value);
+       int *bpp;
+       int ret_val;
+
+       bpp = (int *)value;
+
+       if (0 == system_info_screen_initialized) {
+               ret_val = system_info_screen_init();
+               if (ret_val)
+                       return ret_val;
+       }
+
+       *bpp = PHYSICAL_SCREEN_HEIGHT;
+
+       return SYSTEM_INFO_ERROR_NONE;
 }
 
 int system_info_get_physical_screen_width(system_info_key_e key, system_info_data_type_e data_type, void **value)
 {
-       return system_info_get_platform_int("tizen.org/feature/screen.width", (int *)value);
+       int *bpp;
+       int ret_val;
+
+       bpp = (int *)value;
+
+       if (0 == system_info_screen_initialized) {
+               ret_val = system_info_screen_init();
+               if (ret_val)
+                       return ret_val;
+       }
+
+       *bpp = PHYSICAL_SCREEN_WIDTH;
+
+       return SYSTEM_INFO_ERROR_NONE;
 }
diff --git a/src/system_info_vconf.c b/src/system_info_vconf.c
new file mode 100644 (file)
index 0000000..264dabf
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <vconf.h>
+#include <dlog.h>
+
+#include <system_info.h>
+#include <system_info_private.h>
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+
+#define LOG_TAG "CAPI_SYSTEM_INFO"
+
+int system_info_vconf_get_value_int(const char *vconf_key, int *value)
+{
+       return vconf_get_int(vconf_key, value);
+}
+
+int system_info_vconf_get_value_bool(const char *vconf_key, bool *value)
+{
+       return vconf_get_bool(vconf_key, (int *)value);
+}
+
+int system_info_vconf_get_value_double(const char *vconf_key, double *value)
+{
+       return vconf_get_dbl(vconf_key, value);
+}
+
+int system_info_vconf_get_value_string(const char *vconf_key, char **value)
+{
+       char *str_value = NULL;
+
+       str_value = vconf_get_str(vconf_key);
+
+       if (str_value != NULL) {
+               *value = str_value;
+               return 0;
+       } else {
+               return -1;
+       }
+}