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.
27 #include <notification.h>
29 #include "media-util.h"
30 #include "media-server-ipc.h"
31 #include "media-common-dbg.h"
32 #include "media-common-utils.h"
33 #include "media-common-drm.h"
34 #include "media-common-external-storage.h"
36 #define MMC_INFO_SIZE 256
38 char default_path[][MS_FILE_NAME_LEN_MAX + 1] = {
39 {"/opt/storage/sdcard/Images"},
40 {"/opt/storage/sdcard/Videos"},
41 {"/opt/storage/sdcard/Sounds"},
42 {"/opt/storage/sdcard/Downloads"},
43 {"/opt/storage/sdcard/Camera"}
46 #define DIR_NUM ((int)(sizeof(default_path)/sizeof(default_path[0])))
49 ms_make_default_path_mmc(void)
55 for (i = 0; i < DIR_NUM; ++i) {
56 dp = opendir(default_path[i]);
58 ret = mkdir(default_path[i], 0777);
60 MS_DBG_ERR("make fail");
62 /*this fuction for emulator*/
63 /*at the first time, the directroies are made permission 755*/
64 ret = chmod(default_path[i], 0777);
66 MS_DBG_ERR("chmod failed [%s]", strerror(errno));
68 ret = chown(default_path[i], 5000, 5000);
70 MS_DBG_ERR("chown failed [%s]", strerror(errno));
79 _ms_update_mmc_info(const char *cid)
84 MS_DBG_ERR("Parameters are invalid");
85 return MS_MEDIA_ERR_INVALID_PARAMETER;
88 res = ms_config_set_str(MS_MMC_INFO_KEY, cid);
90 MS_DBG_ERR("fail to get MS_MMC_INFO_KEY");
91 return MS_MEDIA_ERR_VCONF_SET_FAIL;
94 return MS_MEDIA_ERR_NONE;
98 _ms_check_mmc_info(const char *cid)
100 char pre_mmc_info[MMC_INFO_SIZE] = { 0 };
104 MS_DBG_ERR("Parameters are invalid");
108 res = ms_config_get_str(MS_MMC_INFO_KEY, pre_mmc_info);
110 MS_DBG_ERR("fail to get MS_MMC_INFO_KEY");
114 MS_DBG("Last MMC info = %s", pre_mmc_info);
115 MS_DBG("Current MMC info = %s", cid);
117 if (strcmp(pre_mmc_info, cid) == 0) {
125 _get_contents(const char *filename, char *buf)
129 fp = fopen(filename, "rt");
131 MS_DBG_ERR("fp is NULL. file name : %s", filename);
132 return MS_MEDIA_ERR_FILE_OPEN_FAIL;
134 if (fgets(buf, 255, fp) == NULL)
135 MS_DBG_ERR("fgets failed");
139 return MS_MEDIA_ERR_NONE;
144 _ms_get_mmc_info(char *cid)
150 bool getdata = false;
151 bool bHasColon = false;
152 char path[MS_FILE_PATH_LEN_MAX] = { 0 };
153 char mmcpath[MS_FILE_PATH_LEN_MAX] = { 0 };
157 struct dirent *res = NULL;
159 /* mmcblk0 and mmcblk1 is reserved for movinand */
160 for (j = 1; j < 3; j++) {
161 len = snprintf(mmcpath, MS_FILE_PATH_LEN_MAX, "/sys/class/mmc_host/mmc%d/", j);
163 MS_DBG_ERR("FAIL : snprintf");
164 return MS_MEDIA_ERR_INTERNAL;
170 dp = opendir(mmcpath);
172 MS_DBG_ERR("dp is NULL");
173 return MS_MEDIA_ERR_DIR_OPEN_FAIL;
176 while (!readdir_r(dp, &ent, &res)) {
182 if (ent.d_name[0] == '.')
185 if (ent.d_type == DT_DIR) {
186 /*ent->d_name is including ':' */
187 for (i = 0; i < strlen(ent.d_name); i++) {
188 if (ent.d_name[i] == ':') {
196 err = ms_strappend(path, sizeof(path), "%s%s/cid", mmcpath, ent.d_name);
198 MS_DBG_ERR("ms_strappend error : %d", err);
202 if (_get_contents(path, cid) != MS_MEDIA_ERR_NONE)
211 if (getdata == true) {
216 return MS_MEDIA_ERR_NONE;
220 ms_get_mmc_state(void)
222 char cid[MMC_INFO_SIZE] = { 0 };
223 ms_dir_scan_type_t ret = MS_SCAN_ALL;
226 _ms_get_mmc_info(cid);
228 /*check it's same mmc */
229 if (_ms_check_mmc_info(cid)) {
237 ms_update_mmc_info(void)
240 char cid[MMC_INFO_SIZE] = { 0 };
242 err = _ms_get_mmc_info(cid);
244 err = _ms_update_mmc_info(cid);
248 MS_DBG_ERR("malloc_trim is failed");
253 #define _GETSYSTEMSTR(ID) dgettext("sys_string", (ID))
255 void update_lang(void)
260 lang = vconf_get_str(VCONFKEY_LANGSET);
262 setenv("LANG", lang, 1);
263 setenv("LC_MESSAGES", lang, 1);
264 r = setlocale(LC_ALL, "");
266 r = setlocale(LC_ALL, vconf_get_str(VCONFKEY_LANGSET));
267 MS_DBG_ERR("*****appcore setlocale=%s\n", r);
274 ms_present_mmc_status(ms_sdcard_status_type_t status)
276 int ret = NOTIFICATION_ERROR_NONE;
280 if (status == MS_SDCARD_INSERTED)
281 ret = notification_status_message_post(_GETSYSTEMSTR("IDS_COM_BODY_PREPARING_SD_CARD"));
282 else if (status == MS_SDCARD_REMOVED)
283 ret = notification_status_message_post(_GETSYSTEMSTR("IDS_COM_BODY_SD_CARD_REMOVED"));
285 if(ret != NOTIFICATION_ERROR_NONE)
286 return MS_MEDIA_ERR_INTERNAL;
288 return MS_MEDIA_ERR_NONE;