diff options
author | Nikita Kalyazin <nkalyazin@gmail.com> | 2014-01-08 21:25:59 +0400 |
---|---|---|
committer | Nikita Kalyazin <nkalyazin@gmail.com> | 2014-01-18 14:59:41 +0400 |
commit | ce07cd168635261330e243e155920ad739e5d0f3 (patch) | |
tree | 8616a46403b8ff75e457ab1650b84868aca7e2a3 | |
parent | 3bb3d3e107b5ba86236ae2ed8912368fecd6d6fd (diff) | |
download | swap-manager-ce07cd168635261330e243e155920ad739e5d0f3.tar.gz swap-manager-ce07cd168635261330e243e155920ad739e5d0f3.tar.bz2 swap-manager-ce07cd168635261330e243e155920ad739e5d0f3.zip |
[REFACTOR] split system info to separate files
Put the following to new files:
- vconf related stuff;
- system_info related stuff;
- camera count obtaining;
- smack stuff.
Change-Id: I9811d66404d068e2495253a0f6f73a3938aefe2a
Signed-off-by: Nikita Kalyazin <nkalyazin@gmail.com>
-rw-r--r-- | daemon/Makefile | 6 | ||||
-rw-r--r-- | daemon/daemon.c | 8 | ||||
-rw-r--r-- | daemon/device_camera.c | 62 | ||||
-rw-r--r-- | daemon/device_camera.h | 36 | ||||
-rw-r--r-- | daemon/device_system_info.c | 105 | ||||
-rw-r--r-- | daemon/device_system_info.h | 48 | ||||
-rw-r--r-- | daemon/device_vconf.c | 196 | ||||
-rw-r--r-- | daemon/device_vconf.h | 45 | ||||
-rw-r--r-- | daemon/main.c | 5 | ||||
-rw-r--r-- | daemon/smack.c | 48 | ||||
-rw-r--r-- | daemon/smack.h | 38 | ||||
-rw-r--r-- | daemon/sys_stat.c | 317 | ||||
-rw-r--r-- | daemon/utils.c | 36 |
13 files changed, 619 insertions, 331 deletions
diff --git a/daemon/Makefile b/daemon/Makefile index 0cbb803..7f93393 100644 --- a/daemon/Makefile +++ b/daemon/Makefile @@ -38,7 +38,11 @@ DAEMON_SRCS = \ utils.c \ da_protocol_check.c \ md5.c \ - input_events.c + input_events.c \ + device_vconf.c \ + device_system_info.c \ + device_camera.c \ + smack.c DAEMON_OBJS = $(patsubst %.c,%.o, $(DAEMON_SRCS)) diff --git a/daemon/daemon.c b/daemon/daemon.c index 9d24220..f84feb2 100644 --- a/daemon/daemon.c +++ b/daemon/daemon.c @@ -46,9 +46,6 @@ #include <ctype.h> -#include <attr/xattr.h> // for fsetxattr -#include <sys/smack.h> - #include <fcntl.h> #include <assert.h> @@ -62,6 +59,7 @@ #include "da_inst.h" #include "da_data.h" #include "input_events.h" +#include "smack.h" #include "debug.h" #define DA_WORK_DIR "/home/developer/sdk_tools/da/" @@ -419,7 +417,7 @@ int start_profiling(void) LOGW("Failed to create directory for screenshot : %s\n", strerror(errno)); - smack_lsetlabel(SCREENSHOT_DIR, "*", SMACK_LABEL_ACCESS); + set_label_for_all(SCREENSHOT_DIR); if (samplingStart() < 0) { LOGE("Cannot start sampling\n"); @@ -611,7 +609,7 @@ static int targetServerHandler(void) if (manager.target[index].socket >= 0) { /* accept succeed */ - fd_setup_smack_attributes(manager.target[index].socket); + fd_setup_attributes(manager.target[index].socket); /* send config message to target process */ log.type = MSG_OPTION; diff --git a/daemon/device_camera.c b/daemon/device_camera.c new file mode 100644 index 0000000..b2ed596 --- /dev/null +++ b/daemon/device_camera.c @@ -0,0 +1,62 @@ +/* + * DA manager + * + * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * + * Jaewon Lim <jaewon81.lim@samsung.com> + * Woojin Jung <woojin2.jung@samsung.com> + * Juyoung Kim <j0.kim@samsung.com> + * Nikita Kalyazin <n.kalyazin@samsung.com> + * + * 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. + * + * Contributors: + * - S-Core Co., Ltd + * - Samsung RnD Institute Russia + * + */ + + +#include <stdio.h> +#include <string.h> +#include "device_camera.h" + +#define CAMCORDER_FILE "/usr/etc/mmfw_camcorder.ini" +#define CAMERA_COUNT_STR "DeviceCount" +#define BUFFER_MAX 1024 + +int get_camera_count(void) +{ + FILE* fp; + int count = 0; + int size; + char buf[BUFFER_MAX]; + + fp = fopen(CAMCORDER_FILE, "r"); + if (fp == NULL) + return 0; + + size = strlen(CAMERA_COUNT_STR); + while (fgets(buf, BUFFER_MAX, fp) != NULL) { + if (strncmp(buf, CAMERA_COUNT_STR, size) == 0) { + sscanf(buf, CAMERA_COUNT_STR " = %d", &count); + break; + } + } + + fclose(fp); + + return count; +} diff --git a/daemon/device_camera.h b/daemon/device_camera.h new file mode 100644 index 0000000..e04d4c6 --- /dev/null +++ b/daemon/device_camera.h @@ -0,0 +1,36 @@ +/* + * DA manager + * + * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * + * Jaewon Lim <jaewon81.lim@samsung.com> + * Woojin Jung <woojin2.jung@samsung.com> + * Juyoung Kim <j0.kim@samsung.com> + * Nikita Kalyazin <n.kalyazin@samsung.com> + * + * 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. + * + * Contributors: + * - S-Core Co., Ltd + * - Samsung RnD Institute Russia + * + */ + +#ifndef _DEVICE_CAMERA_H_ +#define _DEVICE_CAMERA_H_ + +int get_camera_count(void); + +#endif /* _DEVICE_CAMERA_H_ */ diff --git a/daemon/device_system_info.c b/daemon/device_system_info.c new file mode 100644 index 0000000..ede6b1a --- /dev/null +++ b/daemon/device_system_info.c @@ -0,0 +1,105 @@ +/* + * DA manager + * + * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * + * Jaewon Lim <jaewon81.lim@samsung.com> + * Woojin Jung <woojin2.jung@samsung.com> + * Juyoung Kim <j0.kim@samsung.com> + * Nikita Kalyazin <n.kalyazin@samsung.com> + * + * 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. + * + * Contributors: + * - S-Core Co., Ltd + * - Samsung RnD Institute Russia + * + */ + + +#include <system_info.h> +#include <runtime_info.h> +#include <telephony_network.h> +#include <call.h> +#include "device_system_info.h" + +static int is_available(const char *path) +{ + bool res; + + system_info_get_platform_bool(path, &res); + + return res; +} + +int is_cdma_available(void) +{ + return is_available("tizen.org/feature/network.telephony.service.cdma"); +} + +int is_edge_available(void) +{ + return is_available("tizen.org/feature/network.telephony.service.edge"); +} + +int is_gprs_available(void) +{ + return is_available("tizen.org/feature/network.telephony.service.gprs"); +} + +int is_gsm_available(void) +{ + return is_available("tizen.org/feature/network.telephony.service.gsm"); +} + +int is_hsdpa_available(void) +{ + return is_available("tizen.org/feature/network.telephony.service.hsdpa"); +} + +int is_hspa_available(void) +{ + return is_available("tizen.org/feature/network.telephony.service.hspa"); +} + +int is_hsupa_available(void) +{ + return is_available("tizen.org/feature/network.telephony.service.hsupa"); +} + +int is_umts_available(void) +{ + return is_available("tizen.org/feature/network.telephony.service.umts"); +} + +int is_lte_available(void) +{ + return is_available("tizen.org/feature/network.telephony.service.lte"); +} + +int is_bluetooth_available(void) +{ + return is_available("tizen.org/feature/network.bluetooth"); +} + +int is_gps_available(void) +{ + return is_available("tizen.org/feature/location.gps"); +} + +int is_wifi_available(void) +{ + return is_available("tizen.org/feature/network.wifi"); +} diff --git a/daemon/device_system_info.h b/daemon/device_system_info.h new file mode 100644 index 0000000..dce5ca7 --- /dev/null +++ b/daemon/device_system_info.h @@ -0,0 +1,48 @@ +/* + * DA manager + * + * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * + * Jaewon Lim <jaewon81.lim@samsung.com> + * Woojin Jung <woojin2.jung@samsung.com> + * Juyoung Kim <j0.kim@samsung.com> + * Nikita Kalyazin <n.kalyazin@samsung.com> + * + * 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. + * + * Contributors: + * - S-Core Co., Ltd + * - Samsung RnD Institute Russia + * + */ + +#ifndef _DEVICE_SYSTEM_INFO_H_ +#define _DEVICE_SYSTEM_INFO_H_ + +int is_cdma_available(void); +int is_edge_available(void); +int is_gprs_available(void); +int is_gsm_available(void); +int is_hsdpa_available(void); +int is_hsupa_available(void); +int is_hspa_available(void); +int is_umts_available(void); +int is_lte_available(void); + +int is_bluetooth_available(void); +int is_gps_available(void); +int is_wifi_available(void); + +#endif /* _DEVICE_SYSTEM_INFO_H_ */ diff --git a/daemon/device_vconf.c b/daemon/device_vconf.c new file mode 100644 index 0000000..4d18eca --- /dev/null +++ b/daemon/device_vconf.c @@ -0,0 +1,196 @@ +/* + * DA manager + * + * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * + * Jaewon Lim <jaewon81.lim@samsung.com> + * Woojin Jung <woojin2.jung@samsung.com> + * Juyoung Kim <j0.kim@samsung.com> + * Nikita Kalyazin <n.kalyazin@samsung.com> + * + * 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. + * + * Contributors: + * - S-Core Co., Ltd + * - Samsung RnD Institute Russia + * + */ + + +#include <vconf.h> +#include "debug.h" +#include "device_vconf.h" + +int get_wifi_status(void) +{ + int wifi_status = 0; + int res = 0; + + res = vconf_get_int(VCONFKEY_WIFI_STATE, &wifi_status); + if (res < 0) { + LOG_ONCE_W("get error #%d\n", res); + wifi_status = VCONFKEY_WIFI_OFF; + } + + return wifi_status; +} + +int get_bt_status(void) +{ + int bt_status = 0; + int res = 0; + + res = vconf_get_int(VCONFKEY_BT_STATUS, &bt_status); + if (res < 0) { + LOG_ONCE_W("get error #%d\n", res); + bt_status = VCONFKEY_BT_STATUS_OFF; + } + + return bt_status; +} + +int get_gps_status(void) +{ + int gps_status = 0; + int res = 0; + + res = vconf_get_int(VCONFKEY_LOCATION_ENABLED, &gps_status); + if (res < 0) { + LOG_ONCE_W("get error #%d\n", res); + gps_status = VCONFKEY_LOCATION_GPS_OFF; + } else if (gps_status != 0) { + res = vconf_get_int(VCONFKEY_LOCATION_GPS_STATE, &gps_status); + if (res < 0) { + LOG_ONCE_W("get error #%d\n", res); + gps_status = VCONFKEY_LOCATION_GPS_OFF; + } + } + + return gps_status; +} + +int get_rssi_status(void) +{ + + int flightmode_status; + int res = 0; + + int rssi_status; + res = vconf_get_bool(VCONFKEY_TELEPHONY_FLIGHT_MODE, + &flightmode_status); + if (res < 0) { + LOG_ONCE_W("get err #%d <%s>\n", res, + VCONFKEY_TELEPHONY_FLIGHT_MODE); + flightmode_status = 0; + } + + if (!flightmode_status) { + res = vconf_get_int(VCONFKEY_TELEPHONY_RSSI, &rssi_status); + if (res < 0) { + LOG_ONCE_W("rssi get err #%d\n", res); + rssi_status = VCONFKEY_TELEPHONY_RSSI_0; + } + } else { + rssi_status = VCONFKEY_TELEPHONY_RSSI_0; + } + + return rssi_status; + + return 0; +} + +int get_call_status(void) +{ + int call_status = 0; + int res = 0; + + res = vconf_get_int(VCONFKEY_CALL_STATE, &call_status); + if (res < 0) { + LOG_ONCE_W("get err #%d\n", res); + call_status = VCONFKEY_CALL_OFF; + } + + return call_status; +} + +int get_dnet_status(void) +{ + int dnet_status = 0; + int res = 0; + + res = vconf_get_int(VCONFKEY_DNET_STATE, &dnet_status); + if (res < 0) { + LOG_ONCE_W("get err #%d <%s>\n", res, VCONFKEY_DNET_STATE); + dnet_status = VCONFKEY_DNET_OFF; + } + + return dnet_status; +} + +int get_camera_status(void) +{ + int camera_status = 0; + + if (vconf_get_int(VCONFKEY_CAMERA_STATE, &camera_status) < 0) { + camera_status = VCONFKEY_CAMERA_STATE_NULL; + } + + return camera_status; +} + +int get_sound_status(void) +{ + int sound_status = 0; + int res = 0; + + res = vconf_get_bool(VCONFKEY_SETAPPL_SOUND_STATUS_BOOL, + &sound_status); + if (res < 0) { + LOG_ONCE_W("get err #%d\n", res); + sound_status = 0; + } + + return sound_status; +} + +int get_audio_status(void) +{ + int audio_state = 0; + int res = 0; + + res = vconf_get_int(VCONFKEY_SOUND_STATUS, + &audio_state); + if (res < 0) { + LOG_ONCE_W("get err #%d\n", res); + audio_state = 0; + } + + return !!audio_state; +} + +int get_vibration_status(void) +{ + int vibration_status = 0; + int res = 0; + + res = vconf_get_bool(VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL, + &vibration_status); + if (res < 0) { + LOG_ONCE_W("get err #%d\n", res); + vibration_status = 0; + } + + return vibration_status; +} diff --git a/daemon/device_vconf.h b/daemon/device_vconf.h new file mode 100644 index 0000000..0bb965a --- /dev/null +++ b/daemon/device_vconf.h @@ -0,0 +1,45 @@ +/* + * DA manager + * + * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * + * Jaewon Lim <jaewon81.lim@samsung.com> + * Woojin Jung <woojin2.jung@samsung.com> + * Juyoung Kim <j0.kim@samsung.com> + * Nikita Kalyazin <n.kalyazin@samsung.com> + * + * 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. + * + * Contributors: + * - S-Core Co., Ltd + * - Samsung RnD Institute Russia + * + */ + +#ifndef _DEVICE_VCONF_H_ +#define _DEVICE_VCONF_H_ + +int get_wifi_status(void); +int get_bt_status(void); +int get_gps_status(void); +int get_rssi_status(void); +int get_call_status(void); +int get_dnet_status(void); +int get_camera_status(void); +int get_sound_status(void); +int get_audio_status(void); +int get_vibration_status(void); + +#endif /* _DEVICE_VCONF_H_ */ diff --git a/daemon/main.c b/daemon/main.c index 9e97717..a304837 100644 --- a/daemon/main.c +++ b/daemon/main.c @@ -41,14 +41,15 @@ #include <signal.h> // for signal #include <unistd.h> // for unlink #include <fcntl.h> // for open, fcntl +#include <errno.h> #include <stdbool.h> -#include <attr/xattr.h> // for fsetxattr #include "daemon.h" #include "da_protocol.h" #include "sys_stat.h" #include "buffer.h" #include "debug.h" #include "utils.h" +#include "smack.h" #define SINGLETON_LOCKFILE "/tmp/da_manager.lock" #define PORTFILE "/tmp/port.da" @@ -153,7 +154,7 @@ static int makeTargetServerSocket() return -1; } - fd_setup_smack_attributes(manager.target_server_socket); + fd_setup_attributes(manager.target_server_socket); memset(&serverAddrUn, '\0', sizeof(serverAddrUn)); serverAddrUn.sun_family = AF_UNIX; diff --git a/daemon/smack.c b/daemon/smack.c new file mode 100644 index 0000000..74ed91c --- /dev/null +++ b/daemon/smack.c @@ -0,0 +1,48 @@ +/* + * DA manager + * + * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * + * Jaewon Lim <jaewon81.lim@samsung.com> + * Woojin Jung <woojin2.jung@samsung.com> + * Juyoung Kim <j0.kim@samsung.com> + * Nikita Kalyazin <n.kalyazin@samsung.com> + * + * 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. + * + * Contributors: + * - S-Core Co., Ltd + * - Samsung RnD Institute Russia + * + */ + + +#include <sys/smack.h> +#include <attr/xattr.h> +#include "smack.h" + +#define SELF_LABEL_FILE "/proc/self/attr/current" +#define SMACK_LABEL_LEN 255 + +void fd_setup_attributes(int fd) +{ + fsetxattr(fd, "security.SMACK64IPIN", "*", 1, 0); + fsetxattr(fd, "security.SMACK64IPOUT", "*", 1, 0); +} + +void set_label_for_all(const char *path) +{ + smack_lsetlabel(path, "*", SMACK_LABEL_ACCESS); +} diff --git a/daemon/smack.h b/daemon/smack.h new file mode 100644 index 0000000..ddfbd5a --- /dev/null +++ b/daemon/smack.h @@ -0,0 +1,38 @@ +/* + * DA manager + * + * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * + * Jaewon Lim <jaewon81.lim@samsung.com> + * Woojin Jung <woojin2.jung@samsung.com> + * Juyoung Kim <j0.kim@samsung.com> + * Nikita Kalyazin <n.kalyazin@samsung.com> + * + * 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. + * + * Contributors: + * - S-Core Co., Ltd + * - Samsung RnD Institute Russia + * + */ + + +#ifndef _SMACK_H_ +#define _SMACK_H_ + +void fd_setup_attributes(int fd); +void set_label_for_all(const char *path); + +#endif /* _SMACK_H_ */ diff --git a/daemon/sys_stat.c b/daemon/sys_stat.c index 5cd5e3f..ea9f2c1 100644 --- a/daemon/sys_stat.c +++ b/daemon/sys_stat.c @@ -47,18 +47,13 @@ #include <inttypes.h> #include <stdint.h> -#include <system_info.h> -#include <runtime_info.h> -#include <telephony_network.h> -#include <call.h> - #include "da_protocol.h" #include "da_data.h" - -#include "vconf.h" - #include "sys_stat.h" #include "daemon.h" +#include "device_system_info.h" +#include "device_vconf.h" +#include "device_camera.h" #include "debug.h" // defines for runtime environment @@ -85,8 +80,6 @@ #define CPUMHZ "cpu MHz" #define DA_PROBE_TIZEN_SONAME "da_probe_tizen.so" #define DA_PROBE_OSP_SONAME "da_probe_osp.so" -#define CAMCORDER_FILE "/usr/etc/mmfw_camcorder.ini" -#define CAMERA_COUNT_STR "DeviceCount" // define for correct difference of system feature vars #define val_diff(v_new, v_old) ((v_new < v_old) ? v_new : v_new - v_old) @@ -156,53 +149,6 @@ int get_file_status(int *pfd, const char *filename) // ============================================================================= // device status information getter functions // ============================================================================= -static int get_wifi_status() -{ - int wifi_status = 0; - int res = 0; - - res = vconf_get_int(VCONFKEY_WIFI_STATE, &wifi_status); - if (unlikely(res < 0)) { - LOG_ONCE_W("get error #%d\n", res); - wifi_status = VCONFKEY_WIFI_OFF; - } - - return wifi_status; -} - -static int get_bt_status() -{ - int bt_status = false; - int res = 0; - - res = vconf_get_int(VCONFKEY_BT_STATUS, &bt_status); - if (unlikely(res < 0)) { - LOG_ONCE_W("get error #%d\n", res); - bt_status = VCONFKEY_BT_STATUS_OFF; - } - - return bt_status; -} - -static int get_gps_status() -{ - int gps_status = 0; - int res = 0; - - res = vconf_get_int(VCONFKEY_LOCATION_ENABLED, &gps_status); - if(unlikely(res < 0)) { - LOG_ONCE_W("get error #%d\n", res); - gps_status = VCONFKEY_LOCATION_GPS_OFF; - } else if(gps_status != 0) { - res = vconf_get_int(VCONFKEY_LOCATION_GPS_STATE, &gps_status); - if (unlikely(res < 0)) { - LOG_ONCE_W("get error #%d\n", res); - gps_status = VCONFKEY_LOCATION_GPS_OFF; - } - } - - return gps_status; -} static void init_brightness_status() { @@ -306,122 +252,6 @@ static int get_video_status() return video_status; } -static int get_rssi_status() -{ - - int flightmode_status; - int res = 0; - - int rssi_status; - res = vconf_get_bool(VCONFKEY_TELEPHONY_FLIGHT_MODE, - &flightmode_status); - if(unlikely(res < 0)) { - LOG_ONCE_W("get err #%d <%s>\n", res, - VCONFKEY_TELEPHONY_FLIGHT_MODE); - flightmode_status = 0; - } - - if(!flightmode_status) { - res = vconf_get_int(VCONFKEY_TELEPHONY_RSSI, &rssi_status); - if(unlikely(res < 0)) { - LOG_ONCE_W("rssi get err #%d\n", res); - rssi_status = VCONFKEY_TELEPHONY_RSSI_0; - } - } else { - rssi_status = VCONFKEY_TELEPHONY_RSSI_0; - } - - return rssi_status; - - return 0; -} - -static int get_call_status() -{ - int call_status = 0; - int res = 0; - - res = vconf_get_int(VCONFKEY_CALL_STATE, &call_status); - if(unlikely(res < 0)) { - LOG_ONCE_W("get err #%d\n", res); - call_status = VCONFKEY_CALL_OFF; - } - - return call_status; -} - -/* dnet means 3G? */ -static int get_dnet_status() -{ - int dnet_status = false; - int res = 0; - - res = vconf_get_int(VCONFKEY_DNET_STATE, &dnet_status); - if(unlikely(res < 0)) { - LOG_ONCE_W("get err #%d <%s>\n", res, VCONFKEY_DNET_STATE); - dnet_status = VCONFKEY_DNET_OFF; - } - - return dnet_status; -} - -static int get_camera_status() -{ - int camera_status = 0; - - if (unlikely(vconf_get_int(VCONFKEY_CAMERA_STATE, &camera_status) < 0)) { - camera_status = VCONFKEY_CAMERA_STATE_NULL; - } - - return camera_status; -} - -// this means silent mode? -static int get_sound_status() -{ - int sound_status = 0; - int res = 0; - - res = vconf_get_bool(VCONFKEY_SETAPPL_SOUND_STATUS_BOOL, - &sound_status); - if (unlikely(res < 0)) { - LOG_ONCE_W("get err #%d\n", res); - sound_status = 0; - } - - return sound_status; -} - -static int get_audio_status() -{ - int audio_state = 0; - int res = 0; - - res = vconf_get_int(VCONFKEY_SOUND_STATUS, - &audio_state); - if (unlikely(res < 0)) { - LOG_ONCE_W("get err #%d\n", res); - audio_state = 0; - } - - return !!audio_state; -} - -static int get_vibration_status() -{ - int vibration_status = 0; - int res = 0; - - res = vconf_get_bool(VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL, - &vibration_status); - if(unlikely(res < 0)) { - LOG_ONCE_W("get err #%d\n", res); - vibration_status = 0; - } - - return vibration_status; -} - static void init_voltage_status() { get_file_status(&manager.fd.voltage, VOLTAGEFD); @@ -1311,124 +1141,41 @@ static int update_thread_data(int pid) // overall information getter functions // ======================================================================== -static int get_camera_count(void) +static int get_device_network_type(char* buf, int buflen) { - FILE* fp; - int count = 0; - int size; - char buf[BUFFER_MAX]; + int len = 0; - fp = fopen(CAMCORDER_FILE, "r"); - if(fp != NULL) - { - size = strlen(CAMERA_COUNT_STR); + if (is_cdma_available()) + len += sprintf(buf + len, "CDMA,"); - while(fgets(buf, BUFFER_MAX, fp) != NULL) - { - if(strncmp(buf, CAMERA_COUNT_STR, size) == 0) { - sscanf(buf, CAMERA_COUNT_STR " = %d", &count); - break; - } - } + if (is_edge_available()) + len += sprintf(buf + len, "EDGE,"); - fclose(fp); - } else { - //can not open file - } + if (is_gprs_available()) + len += sprintf(buf + len, "GPRS,"); - return count; -} + if (is_gsm_available()) + len += sprintf(buf + len, "GSM,"); -static int get_device_network_type(char* buf, int buflen) -{ - int len = 0; - bool bool_var; - - system_info_get_platform_bool("tizen.org/feature/network.telephony.service.cdma", &bool_var); - if(bool_var) len += sprintf(buf + len, "CDMA,"); - system_info_get_platform_bool("tizen.org/feature/network.telephony.service.edge", &bool_var); - if(bool_var) len += sprintf(buf + len, "EDGE,"); - system_info_get_platform_bool("tizen.org/feature/network.telephony.service.gprs", &bool_var); - if(bool_var) len += sprintf(buf + len, "GPRS,"); - system_info_get_platform_bool("tizen.org/feature/network.telephony.service.gsm", &bool_var); - if(bool_var) len += sprintf(buf + len, "GSM,"); - system_info_get_platform_bool("tizen.org/feature/network.telephony.service.hsdpa", &bool_var); - if(bool_var) len += sprintf(buf + len, "HSDPA,"); - system_info_get_platform_bool("tizen.org/feature/network.telephony.service.hspa", &bool_var); - if(bool_var) len += sprintf(buf + len, "HSPA,"); - system_info_get_platform_bool("tizen.org/feature/network.telephony.service.hsupa", &bool_var); - if(bool_var) len += sprintf(buf + len, "HSUPA,"); - system_info_get_platform_bool("tizen.org/feature/network.telephony.service.umts", &bool_var); - if(bool_var) len += sprintf(buf + len, "UMTS,"); - system_info_get_platform_bool("tizen.org/feature/network.telephony.service.lte", &bool_var); - if(bool_var) len += sprintf(buf + len, "LTE,"); - - if (len != 0) { - buf[--len] = 0; - } - return len; -} + if (is_hsdpa_available()) + len += sprintf(buf + len, "HSDPA,"); + if (is_hspa_available()) + len += sprintf(buf + len, "HSPA,"); -static int get_device_availability_info(char* buf, int buflen) -{ - int camera_count = 0; - bool blue_support = false; - bool gps_support = false; - bool wifi_support = false; - char* networktype = NULL; - int loglen = 0; - char network_type[128]; - int network_len; - - system_info_get_platform_bool("tizen.org/feature/network.bluetooth", &blue_support); - camera_count = get_camera_count(); - system_info_get_platform_bool("tizen.org/feature/location.gps", &gps_support); - network_len = get_device_network_type(networktype, 128); - system_info_get_platform_bool("tizen.org/feature/network.wifi", &wifi_support); - - loglen += sprintf(buf, "%d`,%d`,%d`,%d`,", - (int)blue_support, - (int)gps_support, - (int)wifi_support, - camera_count); - - if(network_type != NULL && network_len > 0) { - loglen += sprintf(buf + loglen, "%s", networktype); - free(networktype); - } + if (is_hsupa_available()) + len += sprintf(buf + len, "HSUPA,"); - return loglen; -} + if (is_umts_available()) + len += sprintf(buf + len, "UMTS,"); -int get_device_info(char* buffer, int buffer_len) -{ - int res = 0; -/* - char width[BUFFER_MAX]; - char height[BUFFER_MAX]; - char theme[BUFFER_MAX]; - char version[BUFFER_MAX]; - char scale[BUFFER_MAX]; - char removable[BUFFER_MAX]; - char comment[BUFFER_MAX * 2]; - - memset(width, 0, sizeof(width)); - memset(height, 0, sizeof(height)); - memset(theme, 0, sizeof(theme)); - memset(version, 0, sizeof(version)); - memset(scale, 0, sizeof(scale)); - memset(removable, 0, sizeof(removable)); - memset(comment, 0, sizeof(comment)); -*/ - res += sprintf(buffer, "%lu`,%d`,", get_system_total_memory(), get_total_drive()); - res += get_device_availability_info(buffer + res, buffer_len - res); - res += sprintf(buffer + res, "`,%d", get_max_brightness()); + if (is_lte_available()) + len += sprintf(buf + len, "LTE,"); - res += sprintf(buffer + res, "`,`,`,`,`,`,`,"); -// res += sprintf(buffer + res, "`,%s`,%s`,%s`,%s`,%s`,%s`,%s", width, height, theme, version, scale, removable, comment); + if (len != 0) + buf[--len] = 0; - return res; + return len; } static int update_cpus_info(int event_num, float elapsed) @@ -2312,15 +2059,9 @@ int fill_target_info(struct target_info_t *target_info) target_info->storage_size = stat_get_storageinfo(FSINFO_TYPE_TOTAL) * 1024 * 1024; - system_info_get_platform_bool("tizen.org/feature/network.bluetooth", - (_Bool *)&target_info->bluetooth_supp); - - - system_info_get_platform_bool("tizen.org/feature/location.gps", - (_Bool *)&target_info->gps_supp); - - system_info_get_platform_bool("tizen.org/feature/network.wifi", - (_Bool *)&target_info->wifi_supp); + target_info->bluetooth_supp = is_bluetooth_available(); + target_info->gps_supp = is_gps_available(); + target_info->wifi_supp = is_wifi_available(); target_info->camera_count = get_camera_count(); diff --git a/daemon/utils.c b/daemon/utils.c index 2930a25..f635b23 100644 --- a/daemon/utils.c +++ b/daemon/utils.c @@ -42,22 +42,14 @@ #include <sys/stat.h> // for open #include <fcntl.h> // for open #include <grp.h> // for setgroups -#include <sys/smack.h> -#include <attr/xattr.h> - #include <sys/wait.h> /* waitpid */ #include "daemon.h" #include "utils.h" +#include "smack.h" #include "debug.h" #define BUFFER_MAX 1024 -#define APP_GROUPS_MAX 100 -#define APP_GROUP_LIST "/usr/share/privilege-control/app_group_list" -#define SELF_LABEL_FILE "/proc/self/attr/current" - -#define SMACK_LABEL_LEN 255 - #define SID_APP 5000 #define MANIFEST_PATH "/info/manifest.xml" @@ -108,26 +100,6 @@ int64_t str_to_int64(char* str) return (res * factor); } -int smack_set_label_for_self(const char *label) -{ - int len; - int fd; - int ret; - - len = strnlen(label, SMACK_LABEL_LEN + 1); - if (len > SMACK_LABEL_LEN) - return -1; - - fd = open(SELF_LABEL_FILE, O_WRONLY); - if (fd < 0) - return -1; - - ret = write(fd, label, len); - close(fd); - - return (ret < 0) ? -1 : 0; -} - // return 0 if succeed // return -1 if error occured int remove_indir(const char *dirname) @@ -540,12 +512,6 @@ char *dereference_tizen_exe_path(const char *path, char *resolved) return res; } -void fd_setup_smack_attributes(int fd) -{ - fsetxattr(fd, "security.SMACK64IPIN", "*", 1, 0); - fsetxattr(fd, "security.SMACK64IPOUT", "*", 1, 0); -} - float get_uptime(void) { const char *LINUX_UPTIME_FILE = "/proc/uptime"; |