4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Yong Yeon Kim <yy9875.kim@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
23 #include <sys/types.h>
30 #include <dbus/dbus-glib.h>
31 #include <dbus/dbus.h>
32 #include <dbus/dbus-glib-lowlevel.h>
33 #include <sys/statvfs.h>
35 #ifdef _SET_VIP_PROCESS
36 #include <sys/prctl.h>
38 #include <system_info.h>
39 #include <dd-display.h>
41 #ifndef _USE_DEVICED_DBUS
42 #include <usb-device.h>
45 #include "media-util.h"
46 #include "media-server-ipc.h"
47 #include "media-common-dbg.h"
48 #include "media-common-system.h"
49 #include "media-common-utils.h"
51 #define MS_DRM_CONTENT_TYPE_LENGTH 100
53 /* it's for 32bit file offset */
55 unsigned long int f_bsize;
56 unsigned long int f_frsize;
57 unsigned long int f_blocks;
58 unsigned long int f_bfree;
59 unsigned long int f_bavail;
60 unsigned long int f_files;
61 unsigned long int f_ffree;
62 unsigned long int f_favail;
63 unsigned long int f_fsid;
64 #ifdef _STATVFSBUF_F_UNUSED
67 unsigned long int f_flag;
68 unsigned long int f_namemax;
72 bool ms_is_mmc_inserted(void)
75 ms_stg_type_e stg_type = MS_STG_TYPE_MMC;
76 GArray *dev_list = NULL;
78 ret = ms_sys_get_device_list(stg_type, &dev_list);
79 if (ret == MS_MEDIA_ERR_NONE) {
80 if (dev_list != NULL) {
81 MS_DBG_ERR("MMC FOUND[%d]", dev_list->len);
82 ms_sys_release_device_list(&dev_list);
85 MS_DBG_ERR("MMC NOT FOUND");
88 MS_DBG_ERR("ms_sys_get_device_list failed");
94 static char* __media_get_path(uid_t uid)
98 char *result_passwd = NULL;
100 struct group *grpresult = NULL;
103 grpbufsize = sysconf(_SC_GETGR_R_SIZE_MAX);
104 if (grpbufsize == -1) /* Value was indeterminate */
105 grpbufsize = 16384; /* Should be more than enough (16*1024) */
107 grpbuf = malloc(grpbufsize);
108 if (grpbuf == NULL) {
109 MS_DBG_ERR("malloc grpbuf grpbufsize[%d] failed", grpbufsize);
113 ret = getgrnam_r("users", &grpinfo, grpbuf, grpbufsize, &grpresult);
114 if((ret == 0) && (grpresult != NULL)) {
115 // MS_DBG("getgrnam_r users success...\n");
117 MS_DBG_ERR("getgrnam_r users failed ret[%d]", ret);
121 if (uid == getuid()) {
122 if (MS_STRING_VALID(MEDIA_ROOT_PATH_INTERNAL))
123 result_passwd = strndup(MEDIA_ROOT_PATH_INTERNAL, strlen(MEDIA_ROOT_PATH_INTERNAL));
125 struct passwd pwdinfo;
126 struct passwd *pwdresult = NULL;
130 pwdbufsize = sysconf(_SC_GETPW_R_SIZE_MAX);
131 if (pwdbufsize == -1) /* Value was indeterminate */
132 pwdbufsize = 16384; /* Should be more than enough (16*1024) */
134 pwdbuf = malloc(pwdbufsize);
135 if (pwdbuf == NULL) {
136 MS_DBG_ERR("malloc pwdbuf pwdbufsize[%d] failed", pwdbufsize);
140 ret = getpwuid_r(uid, &pwdinfo, pwdbuf, pwdbufsize, &pwdresult);
141 if((ret == 0) && (pwdresult != NULL)) {
142 // MS_DBG("getpwuid uid[%d] success\n", uid);
144 MS_DBG_ERR("getpwuid uid[%d] failed ret[%d]", uid, ret);
145 MS_SAFE_FREE(pwdbuf);
149 // Compare git_t type and not group name
150 if (grpinfo.gr_gid != pwdinfo.pw_gid) {
151 MS_DBG_ERR("UID [%d] does not belong to 'users' group!", uid);
152 MS_SAFE_FREE(pwdbuf);
155 result_passwd = strndup(pwdinfo.pw_dir, strlen(pwdinfo.pw_dir));
157 MS_SAFE_FREE(pwdbuf);
161 MS_SAFE_FREE(grpbuf);
163 return result_passwd;
167 ms_storage_type_t ms_get_storage_type_by_full(const char *path, uid_t uid)
170 int ret = MS_MEDIA_ERR_NONE;
171 char * user_path = NULL;
174 return MS_MEDIA_ERR_INVALID_PATH;
176 #ifdef _USE_SENIOR_MODE
177 if(ms_is_support_senior_mode()) {
178 if (strncmp(path, MEDIA_ROOT_PATH_SENIOR_MODE, strlen(MEDIA_ROOT_PATH_SENIOR_MODE)) == 0) {
179 return MS_STORAGE_EXTERNAL;
184 user_path = __media_get_path(uid);
185 if (user_path == NULL)
186 return MS_MEDIA_ERR_OUT_OF_MEMORY;
188 length_path = strlen(user_path);
190 if (strncmp(path, user_path, length_path) == 0) {
191 ret = MS_STORAGE_INTERNAL;
192 } else if (MS_STRING_VALID(MEDIA_ROOT_PATH_SDCARD) && (strncmp(path, MEDIA_ROOT_PATH_SDCARD, strlen(MEDIA_ROOT_PATH_SDCARD)) == 0)) {
193 ret = MS_STORAGE_EXTERNAL;
194 } else if (MS_STRING_VALID(MEDIA_ROOT_PATH_USB) && (strncmp(path, MEDIA_ROOT_PATH_USB, strlen(MEDIA_ROOT_PATH_USB)) == 0)) {
195 ret = MS_STORAGE_EXTERNAL_USB;
197 MS_DBG_ERR("[%s][%s][%s]", MEDIA_ROOT_PATH_SDCARD, MEDIA_ROOT_PATH_USB, path);
198 ret = MS_MEDIA_ERR_INVALID_PATH;
201 MS_SAFE_FREE(user_path);
206 int ms_strappend(char *res, const int size, const char *pattern, const char *str1, const char *str2)
209 int real_size = size - 1;
211 if (!res || !pattern || !str1 || !str2)
212 return MS_MEDIA_ERR_INVALID_PARAMETER;
214 if (real_size < (int)(strlen(str1) + strlen(str2)))
215 return MS_MEDIA_ERR_INVALID_PARAMETER;
217 len = snprintf(res, real_size, pattern, str1, str2);
219 return MS_MEDIA_ERR_INVALID_PARAMETER;
224 return MS_MEDIA_ERR_NONE;
227 int ms_strcopy(char *res, const int size, const char *pattern, const char *str1)
230 int real_size = size;
232 if (!res || !pattern || !str1) {
233 MS_DBG_ERR("parameta is invalid");
234 return MS_MEDIA_ERR_INVALID_PARAMETER;
237 if (real_size < (int)(strlen(str1))) {
238 MS_DBG_ERR("size is wrong");
239 return MS_MEDIA_ERR_INVALID_PARAMETER;
242 len = snprintf(res, real_size, pattern, str1);
244 MS_DBG_ERR("snprintf failed");
245 return MS_MEDIA_ERR_INVALID_PARAMETER;
250 return MS_MEDIA_ERR_NONE;
253 bool ms_config_get_int(const char *key, int *value)
257 if (!key || !value) {
258 MS_DBG_ERR("Arguments key or value is NULL");
262 err = vconf_get_int(key, value);
268 MS_DBG_ERR("Unexpected error code: %d", err);
273 bool ms_config_set_int(const char *key, int value)
278 MS_DBG_ERR("Arguments key is NULL");
282 err = vconf_set_int(key, value);
288 MS_DBG_ERR("Unexpected error code: %d", err);
293 bool ms_config_get_str(const char *key, char **value)
297 if (key == NULL || value == NULL) {
298 MS_DBG_ERR("Arguments key or value is NULL");
302 res = vconf_get_str(key);
303 if (MS_STRING_VALID(res)) {
304 *value = strdup(res);
312 bool ms_config_set_str(const char *key, const char *value)
316 if (!key || !value) {
317 MS_DBG_ERR("Arguments key or value is NULL");
321 err = vconf_set_str(key, value);
325 MS_DBG_ERR("fail to vconf_set_str %d", err);
330 bool ms_config_get_bool(const char *key, int *value)
334 if (!key || !value) {
335 MS_DBG_ERR("Arguments key or value is NULL");
339 err = vconf_get_bool(key, value);
345 MS_DBG_ERR("Unexpected error code: %d", err);
350 static int get_memory_size(const char *path, struct statvfs_32 *buf)
355 ret = statvfs(path, &s);
357 MS_DBG_ERR("statvfs failed[%d]", ret);
359 return MS_MEDIA_ERR_INTERNAL;
362 buf->f_bsize = s.f_bsize;
363 buf->f_frsize = s.f_frsize;
364 buf->f_blocks = (unsigned long)s.f_blocks;
365 buf->f_bfree = (unsigned long)s.f_bfree;
366 buf->f_bavail = (unsigned long)s.f_bavail;
367 buf->f_files = (unsigned long)s.f_files;
368 buf->f_ffree = (unsigned long)s.f_ffree;
369 buf->f_favail = (unsigned long)s.f_favail;
370 buf->f_fsid = s.f_fsid;
371 buf->f_flag = s.f_flag;
372 buf->f_namemax = s.f_namemax;
374 return MS_MEDIA_ERR_NONE;
377 int ms_get_remain_space(double *free_space)
379 int ret = MS_MEDIA_ERR_NONE;
380 struct statvfs_32 temp;
382 ret = get_memory_size("/opt", &temp);
383 if (ret != MS_MEDIA_ERR_NONE) {
384 MS_DBG_ERR("fail to get memory size");
388 // MS_DBG_ERR("Total mem : %lf, Avail mem : %lf", (double)temp.f_frsize*temp.f_blocks, (double)temp.f_bsize*temp.f_bavail);
390 *free_space = (double)temp.f_bsize*temp.f_bavail;
395 #ifdef _USE_RECORDED_CONTENT
396 bool ms_is_support_pvr(void)
400 if (system_info_get_value_int(SYSTEM_INFO_KEY_PVR_SUPPORTED, &nSupportPVR) != SYSTEM_INFO_ERROR_NONE) {
401 MS_DBG_ERR("Get PVR Support failed");
405 MS_DBG("PVR Support : [%d]", nSupportPVR);
407 return (nSupportPVR != 0);
411 #ifdef _USE_SENIOR_MODE
412 bool ms_is_support_senior_mode()
414 bool bSupportSeniorMode = false;
416 if(system_info_get_value_bool(SYSTEM_INFO_KEY_GET_SENIOR_MODE_SUPPORTED, &bSupportSeniorMode) != SYSTEM_INFO_ERROR_NONE) {
417 MS_DBG_ERR("Get senior mode support failed");
421 MS_DBG("Senior mode support : [%d]", bSupportSeniorMode);
423 return bSupportSeniorMode;
427 int ms_check_file_path(const char *file_path, uid_t uid)
432 /* check location of file */
433 /* file must exists under "/opt/usr/media" or "/opt/storage/sdcard" */
434 if (!ms_is_valid_path(file_path, uid)) {
435 MS_DBG_ERR("Invalid path : %s", file_path);
436 return MS_MEDIA_ERR_INVALID_PATH;
439 /* check the file exits actually */
440 exist = open(file_path, O_RDONLY);
442 MS_DBG_ERR("[%s]open files");
443 return MS_MEDIA_ERR_INVALID_PATH;
447 /* check type of the path */
448 /* It must be a regular file */
449 memset(&file_st, 0, sizeof(struct stat));
450 if (stat(file_path, &file_st) == 0) {
451 if (!S_ISREG(file_st.st_mode)) {
452 /* In this case, it is not a regula file */
453 MS_DBG_ERR("this path is not a file");
454 return MS_MEDIA_ERR_INVALID_PATH;
457 MS_DBG_STRERROR("stat failed");
458 return MS_MEDIA_ERR_INVALID_PATH;
461 return MS_MEDIA_ERR_NONE;
464 int ms_check_ignore_dir(const char *full_path, uid_t uid)
466 int ret = MS_MEDIA_ERR_NONE;
467 char *dir_path = NULL;
468 char *leaf_path = NULL;
469 char *usr_path = NULL;
471 ret = ms_check_file_path(full_path, uid);
472 if (ret != MS_MEDIA_ERR_NONE) {
473 MS_DBG_ERR("invalid path : %s", full_path);
474 return MS_MEDIA_ERR_INVALID_PATH;
477 dir_path = g_path_get_dirname(full_path);
478 if (dir_path == NULL || strcmp(dir_path, ".") == 0) {
479 MS_DBG_ERR("getting directory path is failed : %s", full_path);
480 MS_SAFE_FREE(dir_path);
481 return MS_MEDIA_ERR_INVALID_PATH;
484 usr_path = ms_get_path(uid);
485 if (usr_path == NULL) {
486 MS_DBG_ERR("ms_get_path() fail");
487 MS_SAFE_FREE(dir_path);
488 return MS_MEDIA_ERR_INTERNAL;
492 if (ms_check_scan_ignore(dir_path) != MS_MEDIA_ERR_NONE) {
493 ret = MS_MEDIA_ERR_INVALID_PATH;
497 #ifdef _USE_SENIOR_MODE
498 if(ms_is_support_senior_mode()) {
499 if(strcmp(dir_path, MEDIA_ROOT_PATH_SENIOR_MODE) == 0)
503 if (strcmp(dir_path, usr_path) == 0)
505 else if (MS_STRING_VALID(MEDIA_ROOT_PATH_SDCARD) && (strncmp(dir_path, MEDIA_ROOT_PATH_SDCARD, strlen(MEDIA_ROOT_PATH_SDCARD)) == 0))
507 else if (MS_STRING_VALID(MEDIA_ROOT_PATH_USB) && (strncmp(dir_path, MEDIA_ROOT_PATH_USB, strlen(MEDIA_ROOT_PATH_USB)) == 0))
510 leaf_path = strrchr(dir_path, '/');
511 if (leaf_path != NULL) {
512 int seek_len = leaf_path -dir_path;
513 dir_path[seek_len] = '\0';
515 MS_DBG_ERR("Fail to find leaf path");
516 ret = MS_MEDIA_ERR_INVALID_PATH;
521 MS_SAFE_FREE(dir_path);
522 MS_SAFE_FREE(usr_path);
527 int ms_check_scan_ignore(char * path)
531 const char *ignore_path = "/.scan_ignore";
532 char *check_ignore_file = NULL;
533 int ret = MS_MEDIA_ERR_NONE;
535 if (strstr(path, "/.")) {
536 MS_DBG_ERR("hidden path");
537 ret = MS_MEDIA_ERR_INVALID_PATH;
541 fd = open(path, O_RDONLY | O_DIRECTORY);
543 MS_DBG_ERR("%s folder opendir fails", path);
544 ret = MS_MEDIA_ERR_INVALID_PATH;
546 if (!MS_STRING_VALID(MEDIA_ROOT_PATH_USB)) {
547 MS_DBG_ERR("Fail to get USB path");
551 if (strstr(path, MEDIA_ROOT_PATH_USB) != NULL) {
552 if (errno == ENOENT) {
553 /*if the directory does not exist, check the device is unmounted*/
554 if (!ms_storage_mount_status(path)) {
555 MS_DBG_ERR("Device is unmounted[%s]", path);
556 ret = MS_MEDIA_ERR_USB_UNMOUNTED;
562 struct stat folder_st;
563 if (stat(path, &folder_st) == 0) {
564 MS_DBG_ERR("DEV[%ld] INODE[%lld] UID[%ld] GID[%ld] MODE[%lo] PATH[%s]", (long)folder_st.st_dev, (long long)folder_st.st_ino,
565 (long)folder_st.st_uid, (long)folder_st.st_gid, (unsigned long) folder_st.st_mode, path);
567 MS_DBG_ERR("%s folder stat fails", path);
572 /* check the file exits actually */
575 path_len = strlen(path) + strlen(ignore_path) + 1;
576 check_ignore_file = malloc(path_len);
577 if (check_ignore_file != NULL) {
578 memset(check_ignore_file, 0x0, path_len);
579 snprintf(check_ignore_file, path_len, "%s%s", path, ignore_path);
581 exist = open(check_ignore_file, O_RDONLY);
583 MS_DBG_ERR("scan_ignore exists [%s]", check_ignore_file);
584 ret = MS_MEDIA_ERR_INVALID_PATH;
587 MS_SAFE_FREE(check_ignore_file);
589 MS_DBG_ERR("malloc failed");
590 ret = MS_MEDIA_ERR_OUT_OF_MEMORY;
601 if (exist >= 0) close(exist);
606 char* ms_get_path(uid_t uid)
609 char *result_passwd = NULL;
612 struct group grpinfo;
613 struct group* grpresult = NULL;
616 grpbufsize = sysconf(_SC_GETGR_R_SIZE_MAX);
617 if (grpbufsize == -1) /* Value was indeterminate */
618 grpbufsize = 16384; /* Should be more than enough (16*1024) */
620 grpbuf = malloc(grpbufsize);
621 if (grpbuf == NULL) {
622 MS_DBG_ERR("malloc grpbuf grpbufsize[%d] failed", grpbufsize);
626 ret = getgrnam_r("users", &grpinfo, grpbuf, grpbufsize, &grpresult);
627 if((ret == 0) && (grpresult != NULL)) {
628 // MS_DBG("getgrnam_r users success...\n");
630 MS_DBG_ERR("getgrnam_r users failed ret[%d]", ret);
634 if (uid == getuid()) {
635 if (MS_STRING_VALID(MEDIA_ROOT_PATH_INTERNAL))
636 result_passwd = strndup(MEDIA_ROOT_PATH_INTERNAL, strlen(MEDIA_ROOT_PATH_INTERNAL));
638 char passwd_str[MAX_FILEPATH_LEN] = {0, };
639 struct passwd pwdinfo;
640 struct passwd* pwdresult = NULL;
644 pwdbufsize = sysconf(_SC_GETPW_R_SIZE_MAX);
645 if (pwdbufsize == -1) /* Value was indeterminate */
646 pwdbufsize = 16384; /* Should be more than enough (16*1024) */
648 pwdbuf = malloc(pwdbufsize);
649 if (pwdbuf == NULL) {
650 MS_DBG_ERR("malloc pwdbuf pwdbufsize[%d] failed", pwdbufsize);
654 ret = getpwuid_r(uid, &pwdinfo, pwdbuf, pwdbufsize, &pwdresult);
655 if((ret == 0) && (pwdresult != NULL)) {
656 // MS_DBG("getpwuid uid[%d] success\n", uid);
658 MS_DBG_ERR("getpwuid uid[%d] failed ret[%d]", uid, ret);
659 MS_SAFE_FREE(pwdbuf);
663 // Compare git_t type and not group name
664 if (grpinfo.gr_gid != pwdinfo.pw_gid) {
665 MS_DBG_ERR("UID [%d] does not belong to 'users' group!", uid);
666 MS_SAFE_FREE(pwdbuf);
670 len = snprintf(passwd_str, sizeof(passwd_str), "%s/%s", pwdinfo.pw_dir, MEDIA_CONTENT_PATH);
672 result_passwd = strndup(passwd_str, len);
674 MS_SAFE_FREE(pwdbuf);
678 MS_SAFE_FREE(grpbuf);
680 return result_passwd;
683 bool ms_storage_mount_status(const char* start_path)
686 #ifndef _USE_DEVICED_DBUS
689 usb_device_list_h list;
691 char *mount_path = NULL;
693 char *storage_path = NULL;
694 char *remain_path = NULL;
697 remain_path = strstr(start_path+strlen(MEDIA_ROOT_PATH_USB) +1, "/");
698 if (remain_path != NULL)
699 remain_len = strlen(remain_path);
701 storage_path = strndup(start_path, strlen(start_path) - remain_len);
703 MS_DBG_ERR("storage_path [%s]", storage_path);
705 err = usb_device_get_device_list(USB_MASS_STORAGE, &list);
707 count = usb_device_list_get_count(list);
709 err = usb_device_list_get_first(list, &device);
710 if(err != USB_ERROR_LIST_FAILED_TO_GET && device != NULL) {
711 mount_path = usb_device_get_mountpath(device);
712 if (mount_path != NULL) {
713 MS_DBG_ERR("mount_path [%s]", mount_path);
714 if (strlen(mount_path) == strlen(storage_path)) {
715 if (strncmp(mount_path, storage_path, strlen(mount_path)) == 0) {
716 MS_DBG_ERR("start path is mounted [%s]", start_path);
724 while(usb_device_list_get_next(list, &device) == 0) {
726 mount_path = usb_device_get_mountpath(device);
727 if (mount_path != NULL) {
728 MS_DBG_ERR("mount_path [%s]", mount_path);
729 if (strlen(mount_path) == strlen(storage_path)) {
730 if (strncmp(mount_path, storage_path, strlen(mount_path)) == 0) {
731 MS_DBG_ERR("start path is mounted [%s]", start_path);
742 usb_device_free_device_list(list);
744 MS_DBG_ERR("usb_device_get_device_list falied [%d]", err);
747 MS_SAFE_FREE(storage_path);
752 bool ms_is_valid_path(const char *path, uid_t uid)
755 char *usr_path = NULL;
760 usr_path = ms_get_path(uid);
761 if (usr_path == NULL)
764 #ifdef _USE_SENIOR_MODE
765 if(ms_is_support_senior_mode()) {
766 if (strncmp(path, MEDIA_ROOT_PATH_SENIOR_MODE, strlen(MEDIA_ROOT_PATH_SENIOR_MODE)) == 0)
771 if (strncmp(path, usr_path, strlen(usr_path)) == 0)
773 else if (MS_STRING_VALID(MEDIA_ROOT_PATH_SDCARD) && (strncmp(path, MEDIA_ROOT_PATH_SDCARD, strlen(MEDIA_ROOT_PATH_SDCARD)) == 0))
775 else if (MS_STRING_VALID(MEDIA_ROOT_PATH_USB) && (strncmp(path, MEDIA_ROOT_PATH_USB, strlen(MEDIA_ROOT_PATH_USB)) == 0))
780 MS_SAFE_FREE(usr_path);
785 int ms_set_db_status(ms_db_status_type_t status, ms_storage_type_t storage_type)
787 int res = MS_MEDIA_ERR_NONE;
790 if (status == MS_DB_UPDATING) {
791 if (!ms_config_set_int(VCONFKEY_FILEMANAGER_DB_STATUS, VCONFKEY_FILEMANAGER_DB_UPDATING)) {
792 res = MS_MEDIA_ERR_VCONF_SET_FAIL;
793 MS_DBG_ERR("ms_config_set_int failed");
796 if (storage_type == MS_STORAGE_EXTERNAL) {
797 if (!ms_config_set_int(VCONFKEY_FILEMANAGER_MMC_STATUS, VCONFKEY_FILEMANAGER_MMC_LOADING)) {
798 res = MS_MEDIA_ERR_VCONF_SET_FAIL;
799 MS_DBG_ERR("ms_config_set_int failed");
803 if (!ms_config_set_int(VCONFKEY_FILEMANAGER_DB_STATUS, VCONFKEY_FILEMANAGER_DB_UPDATED)) {
804 res = MS_MEDIA_ERR_VCONF_SET_FAIL;
805 MS_DBG_ERR("ms_config_set_int failed");
808 if (storage_type == MS_STORAGE_EXTERNAL) {
809 if (!ms_config_set_int(VCONFKEY_FILEMANAGER_MMC_STATUS, VCONFKEY_FILEMANAGER_MMC_LOADED)) {
810 res = MS_MEDIA_ERR_VCONF_SET_FAIL;
811 MS_DBG_ERR("ms_config_set_int failed");
816 err = ms_set_power_mode(status);
817 if (err != MS_MEDIA_ERR_NONE) {
818 MS_DBG_ERR("ms_set_power_mode fail");
825 int ms_set_power_mode(ms_db_status_type_t status)
827 int res = MS_MEDIA_ERR_NONE;
832 err = display_lock_state(LCD_OFF, STAY_CUR_STATE, 0);
834 res = MS_MEDIA_ERR_INTERNAL;
837 err = display_unlock_state(LCD_OFF, PM_RESET_TIMER);
839 res = MS_MEDIA_ERR_INTERNAL;
842 MS_DBG_ERR("Unacceptable type : %d", status);
849 void ms_trim_dir_path(char *dir_path)
851 /* need implementation */
852 /* if dir_path is not NULL terminated, this function will occure crash */
853 int len = strlen(dir_path);
855 if (dir_path[len -1] == '/')
856 dir_path[len -1] = '\0';
859 bool ms_check_folder_path(const char *folder_path)
863 dp = opendir(folder_path);
865 MS_DBG_ERR("Deleted folder path");
873 int ms_check_size_mediadb(uid_t uid, double *db_size)
875 int ret = MS_MEDIA_ERR_NONE;
876 char *db_path = NULL;
879 ret = media_db_get_media_db_path(uid, &db_path);
881 if(stat(db_path, &buf) == 0) {
882 *db_size = buf.st_size;
884 MS_DBG_STRERROR("stat failed");
885 ret = MS_MEDIA_ERR_INTERNAL;
888 MS_SAFE_FREE(db_path);
893 #ifdef _SET_VIP_PROCESS
894 #define PROC_OOM_SCORE_ADJ_PATH "/proc/%d/oom_score_adj"
895 #define VIP_OOM_SCORE_ADJ (-1000)
896 #define PROC_NAME_MAX 1024
897 #define PROC_BUF_MAX 64
899 static int ms_get_cmdline_from_proc(pid_t pid, char *cmdline)
901 char buf[PROC_BUF_MAX];
902 char cmdline_buf[PROC_NAME_MAX];
906 snprintf(buf, sizeof(buf), "/proc/%d/cmdline", pid);
907 fp = fopen(buf, "r");
909 return MS_MEDIA_ERR_INTERNAL;
911 if (fgets(cmdline_buf, PROC_NAME_MAX-1, fp) == NULL) {
913 return MS_MEDIA_ERR_INTERNAL;
917 filename = strrchr(cmdline_buf, '/');
918 if (filename == NULL)
919 filename = cmdline_buf;
921 filename = filename + 1;
923 strncpy(cmdline, filename, PROC_NAME_MAX-1);
925 return MS_MEDIA_ERR_NONE;
928 int ms_set_vip_process(void)
932 static pid_t pid = 0;
933 static char process_name[PROC_NAME_MAX] = {0};
934 static char *appid = NULL;
938 if (ms_get_cmdline_from_proc(pid, process_name)) {
939 MS_DBG_ERR("%s: Read process name failed pid[%d]\n", __func__, pid);
940 return MS_MEDIA_ERR_INTERNAL;
942 appid = process_name;
944 MS_DBG("Process name[%s]:Pid[%d]", appid, pid);
946 if (prctl(PR_GET_DUMPABLE) == 0)
947 prctl(PR_SET_DUMPABLE, 1);
949 snprintf(buf, sizeof(buf), PROC_OOM_SCORE_ADJ_PATH, pid);
950 id = open(buf, O_WRONLY, 0777);
952 MS_DBG_ERR("fopen %s failed errno:%d", buf, errno);
953 return MS_MEDIA_ERR_INTERNAL;
955 snprintf(buf, sizeof(buf), "%d", VIP_OOM_SCORE_ADJ);
956 if (write(id, buf, strlen(buf)) < 0) {
957 MS_DBG_ERR("write() failed errno=%d", errno);
959 return MS_MEDIA_ERR_INTERNAL;
962 return MS_MEDIA_ERR_NONE;