4 * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved.
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.
20 #include "popup-common.h"
23 #define SETTING_MMC_ENCRYPTION_UG "setting-mmc-encryption-efl"
25 #define DD_BUS_NAME "org.tizen.system.deviced"
26 #define DD_OBJECT_PATH_ODE "/Org/Tizen/System/DeviceD/Ode"
27 #define DD_INTERFACE_NAME_ODE DD_BUS_NAME".ode"
28 #define DD_SIGNAL_GENERAL_MOUNT "RequestGeneralMount"
29 #define DD_SIGNAL_ODE_MOUNT "RequestOdeMount"
30 #define DD_SIGNAL_REMOVE_MMC "RemoveMmc"
32 static const struct popup_ops mount_error_ops;
33 static const struct popup_ops unmount_error_ops;
34 static const struct popup_ops mount_read_only_ops;
35 static const struct popup_ops check_smack_ops;
36 static const struct popup_ops ode_encrypt_ops;
37 static const struct popup_ops ode_decrypt_ops;
39 static void remove_other_mmc_popups(const struct popup_ops *ops)
41 if (ops != &mount_error_ops)
42 unload_simple_popup(&mount_error_ops);
44 if (ops != &unmount_error_ops)
45 unload_simple_popup(&unmount_error_ops);
47 if (ops != &mount_read_only_ops)
48 unload_simple_popup(&mount_read_only_ops);
50 if (ops != &check_smack_ops)
51 unload_simple_popup(&check_smack_ops);
53 if (ops != &ode_encrypt_ops)
54 unload_simple_popup(&ode_encrypt_ops);
56 if (ops != &ode_decrypt_ops)
57 unload_simple_popup(&ode_decrypt_ops);
60 static bool mmc_inserted(void)
63 if (vconf_get_int(VCONFKEY_SYSMAN_MMC_STATUS, &val) == 0
64 && val != VCONFKEY_SYSMAN_MMC_REMOVED)
69 static bool mmc_mounted(void)
72 if (vconf_get_int(VCONFKEY_SYSMAN_MMC_MOUNT, &val) == 0
73 && val == VCONFKEY_SYSMAN_MMC_MOUNT_FAILED)
78 static bool mmc_unmounted(void)
82 if (vconf_get_int(VCONFKEY_SYSMAN_MMC_UNMOUNT, &val) == 0
83 && val == VCONFKEY_SYSMAN_MMC_UNMOUNT_FAILED)
88 static void send_mount_signal(char *signal)
95 ret = broadcast_dbus_signal(
97 DD_INTERFACE_NAME_ODE,
101 _E("FAIL: broadcast_dbus_signal(%s:%d)", signal, ret);
104 static void launch_app(char *appname)
114 ret = aul_launch_app(appname, b);
116 _E("FAIL: aul_launch_app(%d)", ret);
117 if (bundle_free(b) != 0)
118 _E("FAIL: bundle_free(b);");
120 _E("Failed to create bundle");
124 static void send_general_mount_signal(const struct popup_ops *ops)
126 unload_simple_popup(ops);
127 send_mount_signal(DD_SIGNAL_GENERAL_MOUNT);
128 terminate_if_no_popup();
131 static void send_ode_mount_signal(const struct popup_ops *ops)
133 unload_simple_popup(ops);
134 send_mount_signal(DD_SIGNAL_ODE_MOUNT);
135 terminate_if_no_popup();
138 static void ode_launch_settings(const struct popup_ops *ops)
140 unload_simple_popup(ops);
141 launch_app(SETTING_MMC_ENCRYPTION_UG);
142 terminate_if_no_popup();
145 static bool skip_mount_error_popup(bundle *b, const struct popup_ops *ops)
147 return mmc_mounted();
150 static bool skip_unmount_error_popup(bundle *b, const struct popup_ops *ops)
152 return mmc_unmounted();
155 static bool skip_ode_popup(bundle *b, const struct popup_ops *ops)
157 return !mmc_inserted();
160 static E_DBus_Signal_Handler *mmc_removed_handler= NULL;
162 static void unregister_ode_handler(const struct popup_ops *ops)
164 if (mmc_removed_handler) {
165 unregister_dbus_signal_handler(mmc_removed_handler);
166 mmc_removed_handler = NULL;
170 static void mmc_removed(void *data, DBusMessage *msg)
172 const struct popup_ops *ops = data;
174 unregister_ode_handler(ops);
175 unload_simple_popup(ops);
176 terminate_if_no_popup();
179 static void register_ode_handler(const struct popup_ops *ops)
183 unregister_ode_handler(ops);
185 ret = register_dbus_signal_handler(&mmc_removed_handler,
187 DD_INTERFACE_NAME_ODE,
188 DD_SIGNAL_REMOVE_MMC,
192 _E("Failed to register mmc removed signal handler(%d)", ret);
195 static void mmc_mount_status_changed(keynode_t *in_key, void *data)
197 const struct popup_ops *ops = data;
199 if (vconf_keynode_get_int(in_key) == VCONFKEY_SYSMAN_MMC_MOUNT_FAILED)
202 unload_simple_popup(ops);
203 terminate_if_no_popup();
206 static void mmc_unmount_status_changed(keynode_t *in_key, void *data)
208 const struct popup_ops *ops = data;
210 if (vconf_keynode_get_int(in_key) == VCONFKEY_SYSMAN_MMC_UNMOUNT_FAILED)
213 unload_simple_popup(ops);
214 terminate_if_no_popup();
217 static void register_mmc_mount_handler(const struct popup_ops *ops)
219 if (vconf_notify_key_changed(VCONFKEY_SYSMAN_MMC_MOUNT,
220 mmc_mount_status_changed, (void *)ops) != 0)
221 _E("Failed to register mmc mount handler");
224 static void unregister_mmc_mount_handler(const struct popup_ops *ops)
226 vconf_ignore_key_changed(VCONFKEY_SYSMAN_MMC_MOUNT,
227 mmc_mount_status_changed);
230 static void register_mmc_unmount_handler(const struct popup_ops *ops)
232 if (vconf_notify_key_changed(VCONFKEY_SYSMAN_MMC_UNMOUNT,
233 mmc_unmount_status_changed, (void *)ops) != 0)
234 _E("Failed to register mmc mount handler");
237 static void unregister_mmc_unmount_handler(const struct popup_ops *ops)
239 vconf_ignore_key_changed(VCONFKEY_SYSMAN_MMC_UNMOUNT,
240 mmc_unmount_status_changed);
243 static int launch_mmc_popup(bundle *b, const struct popup_ops *ops)
245 remove_other_mmc_popups(ops);
246 unregister_ode_handler(ops);
248 if (ops == &mount_error_ops)
249 register_mmc_mount_handler(ops);
251 if (ops == &unmount_error_ops)
252 register_mmc_unmount_handler(ops);
254 if (ops == &ode_encrypt_ops ||
255 ops == &ode_decrypt_ops)
256 register_ode_handler(ops);
261 static void terminate_mmc_popup(const struct popup_ops *ops)
263 unregister_mmc_mount_handler(ops);
264 unregister_mmc_unmount_handler(ops);
265 unregister_ode_handler(ops);
268 static const struct popup_ops mount_error_ops = {
269 .name = "mounterr",//"mmc_mount_error",
270 .show = load_simple_popup,
271 .title = "IDS_IDLE_HEADER_UNABLE_TO_MOUNT_SD_CARD_ABB",
272 .content = "IDS_DN_POP_FAILED_TO_MOUNT_SD_CARD_REINSERT_OR_FORMAT_SD_CARD",
273 .left_text = "IDS_COM_SK_OK",
274 .skip = skip_mount_error_popup,
275 .pre = launch_mmc_popup,
278 static const struct popup_ops unmount_error_ops = {
279 .name = "unmounterr",//"mmc_unmount_error",
280 .show = load_simple_popup,
281 .title = "IDS_IDLE_HEADER_UNABLE_TO_UNMOUNT_SD_CARD_ABB",
282 .content = "IDS_IDLE_POP_THE_SD_CARD_MAY_BE_IN_USE_TRY_AGAIN_LATER",
283 .left_text = "IDS_COM_SK_OK",
284 .skip = skip_unmount_error_popup,
285 .pre = launch_mmc_popup,
288 static const struct popup_ops mount_read_only_ops = {
289 .name = "mountrdonly",//"mmc_mount_read_only",
290 .show = load_simple_popup,
291 .content = "IDS_ST_BODY_SD_CARD_MOUNTED_READ_ONLY",
292 .left_text = "IDS_COM_SK_OK",
293 .pre = launch_mmc_popup,
296 static const struct popup_ops check_smack_ops = {
297 .name = "checksmack",//"mmc_check_smack",
298 .show = load_simple_popup,
299 .content = "IDS_MF_BODY_MMC_DATA_IS_INITIALIZING_ING",
300 .left_text = "IDS_COM_SK_OK",
301 .pre = launch_mmc_popup,
304 static const struct popup_ops ode_encrypt_ops = {
305 .name = "odeencrypt",//"mmc_ode_encrypt",
306 .show = load_simple_popup,
307 .title = "IDS_DN_BODY_ENCRYPT_SD_CARD",
308 .content = "IDS_ST_POP_TO_USE_YOUR_SD_CARD_IT_MUST_BE_ENCRYPTED_ENCRYPT_SD_CARD_OR_DISABLE_DEVICE_ENCRYPTION_Q",
309 .left_text = "IDS_ST_BUTTON_ENCRYPT_SD_CARD_ABB",
310 .left = ode_launch_settings,
311 .right_text = "IDS_ST_BUTTON_DISABLE_ENCRYPTION_ABB",
312 .right = send_general_mount_signal,
313 .skip = skip_ode_popup,
314 .pre = launch_mmc_popup,
315 .terminate = terminate_mmc_popup,
318 static const struct popup_ops ode_decrypt_ops = {
319 .name = "odedecrypt",//"mmc_ode_decrypt",
320 .show = load_simple_popup,
321 .title = "IDS_DN_BODY_DECRYPT_SD_CARD",
322 .content = "IDS_ST_POP_TO_USE_YOUR_SD_CARD_IT_MUST_BE_DECRYPTED_DECRYPT_SD_CARD_OR_ENABLE_DEVICE_ENCRYPTION_Q",
323 .left_text = "IDS_ST_BUTTON_DECRYPT_SD_CARD_ABB",
324 .left = ode_launch_settings,
325 .right_text = "IDS_ST_BUTTON_ENABLE_ENCRYPTION_ABB",
326 .right = send_ode_mount_signal,
327 .skip = skip_ode_popup,
328 .pre = launch_mmc_popup,
329 .terminate = terminate_mmc_popup,
332 /* Constructor to register mmc popup */
333 static __attribute__ ((constructor)) void register_mmc_popup(void)
335 register_popup(&mount_error_ops);
336 register_popup(&unmount_error_ops);
337 register_popup(&mount_read_only_ops);
338 register_popup(&check_smack_ops);
339 register_popup(&ode_encrypt_ops);
340 register_popup(&ode_decrypt_ops);