4 * Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
23 #include <sys/types.h>
27 /* For multi-user support */
28 #include <tzplatform_config.h>
31 #include "bt-share-common.h"
32 #include "bluetooth-api.h"
33 #include "bt-share-noti-handler.h"
34 #include "bt-share-main.h"
35 #include "bt-share-notification.h"
36 #include "obex-event-handler.h"
39 static void __bt_default_memory_changed_cb(keynode_t *node, void *data)
44 int default_memory = 0;
45 char *root_path = NULL;
46 char *download_path = NULL;
48 DBG_SECURE("key=%s\n", vconf_keynode_get_name(node));
50 if (vconf_keynode_get_type(node) == VCONF_TYPE_INT) {
51 /* Phone memory is 0, MMC is 1 */
52 default_memory = vconf_keynode_get_int(node);
54 if (default_memory == BT_DEFAULT_MEM_MMC) /* MMC */ {
55 download_path = _bt_share_get_storage_path(default_memory);
56 root_path = _bt_share_get_storage_path(default_memory);
58 if (download_path == NULL)
59 download_path = g_strdup(BT_DOWNLOAD_DEFAULT_MEDIA_FOLDER);
61 if (root_path == NULL)
62 root_path = g_strdup(BT_DOWNLOAD_DEFAULT_MEDIA_FOLDER);
65 download_path = g_strdup(BT_DOWNLOAD_DEFAULT_MEDIA_FOLDER);
66 root_path = g_strdup(BT_DOWNLOAD_DEFAULT_MEDIA_FOLDER);
69 if (access(download_path, W_OK) != 0) {
70 warn_if(mkdir(download_path, 0755) < 0,
71 "mkdir fail![%s]", download_path);
74 bluetooth_obex_server_set_root(root_path);
75 bluetooth_obex_server_set_destination_path(download_path);
77 g_free(download_path);
86 static void __bt_mmc_status_changed_cb(keynode_t *node, void *data)
89 retm_if(!node || !data, "invalid param!");
92 int default_memory = 0;
93 int ret = NOTIFICATION_ERROR_NONE;
94 char *root_path = NULL;
95 char *download_path = NULL;
97 DBG_SECURE("key=%s", vconf_keynode_get_name(node));
98 bt_appdata_t *ad = (bt_appdata_t *)data;
100 if (vconf_keynode_get_type(node) == VCONF_TYPE_INT) {
101 /* Phone memory is 0, MMC is 1 */
102 mmc_status = vconf_keynode_get_int(node);
104 if (mmc_status == VCONFKEY_SYSMAN_MMC_REMOVED ||
105 mmc_status == VCONFKEY_SYSMAN_MMC_INSERTED_NOT_MOUNTED) {
106 retm_if(vconf_get_int(VCONFKEY_SETAPPL_DEFAULT_MEM_BLUETOOTH_INT,
107 &default_memory) != 0,
108 "vconf_get_int failed");
110 if (ad->opc_noti) { /* sending case */
111 DBG("cancel outbound transfer");
112 bluetooth_opc_cancel_push();
113 ret = _bt_delete_notification(ad->opc_noti);
114 if (ret == NOTIFICATION_ERROR_NONE) {
118 } else { /* receiving case */
119 DBG("cancel inbound transfer");
120 if (default_memory == BT_DEFAULT_MEM_MMC) {
121 _bt_obex_cancel_transfer(data);
122 retm_if(vconf_set_int(
123 VCONFKEY_SETAPPL_DEFAULT_MEM_BLUETOOTH_INT,
124 BT_DEFAULT_MEM_PHONE) != 0, "vconf_set_int failed");
125 DBG_SECURE("Default Memory set to Phone");
128 } else if (mmc_status == VCONFKEY_SYSMAN_MMC_MOUNTED) {
129 vconf_get_int(VCONFKEY_SETAPPL_DEFAULT_MEM_BLUETOOTH_INT, &default_memory);
130 if (default_memory == BT_DEFAULT_MEM_MMC) /* MMC */ {
131 download_path = _bt_share_get_storage_path(default_memory);
132 root_path = _bt_share_get_storage_path(default_memory);
134 if (download_path == NULL)
135 download_path = g_strdup(BT_DOWNLOAD_DEFAULT_MEDIA_FOLDER);
137 if (root_path == NULL)
138 root_path = g_strdup(BT_DOWNLOAD_DEFAULT_MEDIA_FOLDER);
141 download_path = g_strdup(BT_DOWNLOAD_DEFAULT_MEDIA_FOLDER);
142 root_path = g_strdup(BT_DOWNLOAD_DEFAULT_MEDIA_FOLDER);
145 if (access(download_path, W_OK) != 0) {
146 warn_if(mkdir(download_path, 0755) < 0,
147 "mkdir fail![%s]", download_path);
150 bluetooth_obex_server_set_root(root_path);
151 bluetooth_obex_server_set_destination_path(download_path);
153 g_free(download_path);
162 void _bt_init_vconf_notification(void *data)
164 retm_if(!data, "invalid param!");
168 ret = vconf_notify_key_changed(VCONFKEY_SETAPPL_DEFAULT_MEM_BLUETOOTH_INT,
169 __bt_default_memory_changed_cb, NULL);
170 warn_if(ret != VCONF_OK, "vconf_notify_key_changed init failed");
172 ret = vconf_notify_key_changed(VCONFKEY_SYSMAN_MMC_STATUS,
173 __bt_mmc_status_changed_cb, data);
174 warn_if(ret != VCONF_OK, "vconf_notify_key_changed init failed");
177 void _bt_deinit_vconf_notification(void)
180 ret = vconf_ignore_key_changed(VCONFKEY_SETAPPL_DEFAULT_MEM_BLUETOOTH_INT,
181 (vconf_callback_fn) __bt_default_memory_changed_cb);
182 warn_if(ret != VCONF_OK, "vconf_notify_key_changed deinit failed");
184 ret = vconf_ignore_key_changed(VCONFKEY_SYSMAN_MMC_STATUS,
185 (vconf_callback_fn) __bt_mmc_status_changed_cb);
186 warn_if(ret != VCONF_OK, "vconf_notify_key_changed deinit failed");