4 * Copyright (c) 2016 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 #include <app_control.h>
25 #define SETTING_MMC_ENCRYPTION_UG "setting-mmc-encryption-efl"
26 #define EXTENDED_SD_APPNAME "org.tizen.extended-sd"
27 #define ODE_APPNAME "org.tizen.ode"
28 #define SDCARD_KEY "_SDCARD_NUM_"
29 #define VIEWTYPE_KEY "viewtype"
30 #define DEVPATH_KEY "dev_path"
31 #define MAPPINGNODE_KEY "mapping_node"
33 #define DD_BUS_NAME "org.tizen.system.deviced"
34 #define DD_OBJECT_PATH_ODE "/Org/Tizen/System/DeviceD/Ode"
35 #define DD_INTERFACE_NAME_ODE DD_BUS_NAME".ode"
36 #define DD_SIGNAL_GENERAL_MOUNT "RequestGeneralMount"
37 #define DD_SIGNAL_ODE_MOUNT "RequestOdeMount"
38 #define DD_SIGNAL_REMOVE_MMC "RemoveMmc"
46 static const struct popup_ops mount_error_ops;
47 static const struct popup_ops unmount_error_ops;
48 static const struct popup_ops mount_read_only_ops;
49 static const struct popup_ops check_smack_ops;
50 static const struct popup_ops ode_encrypt_ops;
51 static const struct popup_ops ode_decrypt_ops;
52 static const struct popup_ops sdcard_setup_ops;
53 static const struct popup_ops unlock_extendedsd_ops;
55 static char *Sdcard_ID = NULL;
56 static char *View_Type = NULL;
57 static char *Dev_Path = NULL;
58 static char *Mapping_Node = NULL;
60 static void remove_other_mmc_popups(const struct popup_ops *ops)
62 if (ops != &sdcard_setup_ops)
63 unload_simple_popup(&sdcard_setup_ops);
65 if (ops != &mount_error_ops)
66 unload_simple_popup(&mount_error_ops);
68 if (ops != &unmount_error_ops)
69 unload_simple_popup(&unmount_error_ops);
71 if (ops != &mount_read_only_ops)
72 unload_simple_popup(&mount_read_only_ops);
74 if (ops != &check_smack_ops)
75 unload_simple_popup(&check_smack_ops);
77 if (ops != &ode_encrypt_ops)
78 unload_simple_popup(&ode_encrypt_ops);
80 if (ops != &ode_decrypt_ops)
81 unload_simple_popup(&ode_decrypt_ops);
84 static bool mmc_inserted(void)
87 if (vconf_get_int(VCONFKEY_SYSMAN_MMC_STATUS, &val) == 0
88 && val != VCONFKEY_SYSMAN_MMC_REMOVED)
93 static bool mmc_mounted(void)
96 if (vconf_get_int(VCONFKEY_SYSMAN_MMC_MOUNT, &val) == 0
97 && val == VCONFKEY_SYSMAN_MMC_MOUNT_FAILED)
102 static bool mmc_unmounted(void)
106 if (vconf_get_int(VCONFKEY_SYSMAN_MMC_UNMOUNT, &val) == 0
107 && val == VCONFKEY_SYSMAN_MMC_UNMOUNT_FAILED)
112 static void send_mount_signal(char *signal)
119 ret = broadcast_dbus_signal(
121 DD_INTERFACE_NAME_ODE,
125 _E("FAIL: broadcast_dbus_signal(%s:%d)", signal, ret);
128 static void launch_app(int type)
130 app_control_h app_control = NULL;
133 ret = app_control_create(&app_control);
134 if (ret != APP_CONTROL_ERROR_NONE)
137 if (type == EXT_SETTING_MMC_UG)
138 ret = app_control_set_app_id(app_control, SETTING_MMC_ENCRYPTION_UG);
139 else if (type == EXT_SD_SETTING) {
140 app_control_add_extra_data(app_control, SDCARD_KEY, Sdcard_ID);
141 ret = app_control_set_app_id(app_control, EXTENDED_SD_APPNAME);
142 } else if (type == EXT_ODE) {
143 app_control_add_extra_data(app_control, VIEWTYPE_KEY, View_Type);
144 app_control_add_extra_data(app_control, DEVPATH_KEY, Dev_Path);
145 app_control_add_extra_data(app_control, MAPPINGNODE_KEY, Mapping_Node);
146 ret = app_control_set_app_id(app_control, ODE_APPNAME);
148 _E("No matched type(%d)", type);
152 if (ret != APP_CONTROL_ERROR_NONE) {
153 _E("Fail to set app id");
157 ret = app_control_send_launch_request(app_control, NULL, NULL);
158 if (ret != APP_CONTROL_ERROR_NONE)
159 _E("Fail to send launch request");
163 (void)app_control_destroy(app_control);
168 static void send_general_mount_signal(const struct popup_ops *ops)
170 unload_simple_popup(ops);
171 send_mount_signal(DD_SIGNAL_GENERAL_MOUNT);
172 terminate_if_no_popup();
175 static void send_ode_mount_signal(const struct popup_ops *ops)
177 unload_simple_popup(ops);
178 send_mount_signal(DD_SIGNAL_ODE_MOUNT);
179 terminate_if_no_popup();
182 static void ode_launch_settings(const struct popup_ops *ops)
184 unload_simple_popup(ops);
185 launch_app(EXT_SETTING_MMC_UG);
186 terminate_if_no_popup();
189 static bool skip_mount_error_popup(bundle *b, const struct popup_ops *ops)
191 return mmc_mounted();
194 static bool skip_unmount_error_popup(bundle *b, const struct popup_ops *ops)
196 return mmc_unmounted();
199 static bool skip_ode_popup(bundle *b, const struct popup_ops *ops)
201 return !mmc_inserted();
204 static E_DBus_Signal_Handler *mmc_removed_handler = NULL;
206 static void unregister_ode_handler(const struct popup_ops *ops)
208 if (mmc_removed_handler) {
209 unregister_dbus_signal_handler(mmc_removed_handler);
210 mmc_removed_handler = NULL;
214 static void mmc_removed(void *data, DBusMessage *msg)
216 const struct popup_ops *ops = data;
218 unregister_ode_handler(ops);
219 unload_simple_popup(ops);
220 terminate_if_no_popup();
223 static void register_ode_handler(const struct popup_ops *ops)
227 unregister_ode_handler(ops);
229 ret = register_dbus_signal_handler(&mmc_removed_handler,
231 DD_INTERFACE_NAME_ODE,
232 DD_SIGNAL_REMOVE_MMC,
236 _E("Failed to register mmc removed signal handler(%d)", ret);
239 static void mmc_mount_status_changed(keynode_t *in_key, void *data)
241 const struct popup_ops *ops = data;
243 if (vconf_keynode_get_int(in_key) == VCONFKEY_SYSMAN_MMC_MOUNT_FAILED)
246 unload_simple_popup(ops);
247 terminate_if_no_popup();
250 static void mmc_unmount_status_changed(keynode_t *in_key, void *data)
252 const struct popup_ops *ops = data;
254 if (vconf_keynode_get_int(in_key) == VCONFKEY_SYSMAN_MMC_UNMOUNT_FAILED)
257 unload_simple_popup(ops);
258 terminate_if_no_popup();
261 static void register_mmc_mount_handler(const struct popup_ops *ops)
263 if (vconf_notify_key_changed(VCONFKEY_SYSMAN_MMC_MOUNT,
264 mmc_mount_status_changed, (void *)ops) != 0)
265 _E("Failed to register mmc mount handler");
268 static void unregister_mmc_mount_handler(const struct popup_ops *ops)
270 vconf_ignore_key_changed(VCONFKEY_SYSMAN_MMC_MOUNT,
271 mmc_mount_status_changed);
274 static void register_mmc_unmount_handler(const struct popup_ops *ops)
276 if (vconf_notify_key_changed(VCONFKEY_SYSMAN_MMC_UNMOUNT,
277 mmc_unmount_status_changed, (void *)ops) != 0)
278 _E("Failed to register mmc mount handler");
281 static void unregister_mmc_unmount_handler(const struct popup_ops *ops)
283 vconf_ignore_key_changed(VCONFKEY_SYSMAN_MMC_UNMOUNT,
284 mmc_unmount_status_changed);
287 static int launch_mmc_popup(bundle *b, const struct popup_ops *ops)
289 remove_other_mmc_popups(ops);
290 unregister_ode_handler(ops);
292 if (ops == &mount_error_ops)
293 register_mmc_mount_handler(ops);
295 if (ops == &unmount_error_ops)
296 register_mmc_unmount_handler(ops);
298 if (ops == &ode_encrypt_ops ||
299 ops == &ode_decrypt_ops)
300 register_ode_handler(ops);
305 static void terminate_mmc_popup(const struct popup_ops *ops)
307 unregister_mmc_mount_handler(ops);
308 unregister_mmc_unmount_handler(ops);
309 unregister_ode_handler(ops);
312 static void launch_sdcard_setup(const struct popup_ops *ops)
314 unload_simple_popup(ops);
315 launch_app(EXT_SD_SETTING);
316 terminate_if_no_popup();
319 static int launch_ode(bundle *b, const struct popup_ops *ops)
324 View_Type = (char *)bundle_get_val(b, VIEWTYPE_KEY);
325 Dev_Path = (char *)bundle_get_val(b, DEVPATH_KEY);
326 Mapping_Node = (char *)bundle_get_val(b, MAPPINGNODE_KEY);
328 if (!View_Type || !Dev_Path || !Mapping_Node) {
329 _E("Failed to get data for ode");
337 static int sdcard_setup_get_content(const struct popup_ops *ops, char *content, unsigned int len)
341 struct object_ops *obj;
343 if (!ops || !content)
346 ret = get_object_by_ops(ops, &obj);
348 _E("Failed to get object (%d)", ret);
352 Sdcard_ID = (char *)bundle_get_val(obj->b, SDCARD_KEY);
354 _E("Failed to get SDCARD ID");
358 text = _("IDS_ST_BODY_THERE_IS_ALREADY_DATA_FROM_ANOTHER_PHONE_STORED_ON_THIS_SD_CARD_TO_USE_THIS_SD_CARD_ON_THIS_PHONE_TAP_SET_UP_TO_FORMAT_MSG");
359 snprintf(content, len, "%s", text);
364 static const struct popup_ops mount_error_ops = {
365 .name = "mounterr",//"mmc_mount_error",
366 .pattern = FEEDBACK_PATTERN_LOWBATT,
367 .show = load_simple_popup,
368 .title = "IDS_IDLE_HEADER_COULDNT_MOUNT_SD_CARD_ABB",
369 .content = "IDS_IDLE_POP_REMOVE_AND_REINSERT_YOUR_SD_CARD_OR_FORMAT_IT_THEN_TRY_AGAIN",
370 .left_text = "IDS_COM_SK_OK",
371 .skip = skip_mount_error_popup,
372 .pre = launch_mmc_popup,
375 static const struct popup_ops unmount_error_ops = {
376 .name = "unmounterr",//"mmc_unmount_error",
377 .pattern = FEEDBACK_PATTERN_LOWBATT,
378 .show = load_simple_popup,
379 .title = "IDS_IDLE_HEADER_COULDNT_UNMOUNT_SD_CARD_ABB",
380 .content = "IDS_IDLE_POP_THE_SD_CARD_MAY_BE_IN_USE_TRY_AGAIN_LATER",
381 .left_text = "IDS_COM_SK_OK",
382 .skip = skip_unmount_error_popup,
383 .pre = launch_mmc_popup,
386 static const struct popup_ops mount_read_only_ops = {
387 .name = "mountrdonly",//"mmc_mount_read_only",
388 .pattern = FEEDBACK_PATTERN_LOWBATT,
389 .show = load_simple_popup,
390 .content = "IDS_ST_BODY_SD_CARD_MOUNTED_READ_ONLY",
391 .left_text = "IDS_COM_SK_OK",
392 .pre = launch_mmc_popup,
395 static const struct popup_ops check_smack_ops = {
396 .name = "checksmack",//"mmc_check_smack",
397 .pattern = FEEDBACK_PATTERN_LOWBATT,
398 .show = load_simple_popup,
399 .content = "IDS_MF_BODY_MMC_DATA_IS_INITIALIZING_ING",
400 .left_text = "IDS_COM_SK_OK",
401 .pre = launch_mmc_popup,
404 static const struct popup_ops ode_encrypt_ops = {
405 .name = "odeencrypt",//"mmc_ode_encrypt",
406 .pattern = FEEDBACK_PATTERN_LOWBATT,
407 .show = load_simple_popup,
408 .title = "IDS_DN_BODY_ENCRYPT_SD_CARD",
409 .content = "IDS_ST_POP_TO_USE_YOUR_SD_CARD_IT_MUST_BE_ENCRYPTED_ENCRYPT_SD_CARD_OR_DISABLE_DEVICE_ENCRYPTION_Q",
410 .left_text = "IDS_ST_BUTTON_ENCRYPT_SD_CARD_ABB",
411 .left = ode_launch_settings,
412 .right_text = "IDS_ST_BUTTON_DISABLE_ENCRYPTION_ABB",
413 .right = send_general_mount_signal,
414 .skip = skip_ode_popup,
415 .pre = launch_mmc_popup,
416 .terminate = terminate_mmc_popup,
419 static const struct popup_ops ode_decrypt_ops = {
420 .name = "odedecrypt",//"mmc_ode_decrypt",
421 .pattern = FEEDBACK_PATTERN_LOWBATT,
422 .show = load_simple_popup,
423 .title = "IDS_DN_BODY_DECRYPT_SD_CARD",
424 .content = "IDS_ST_POP_TO_USE_YOUR_SD_CARD_IT_MUST_BE_DECRYPTED_DECRYPT_SD_CARD_OR_ENABLE_DEVICE_ENCRYPTION_Q",
425 .left_text = "IDS_ST_BUTTON_DECRYPT_SD_CARD_ABB",
426 .left = ode_launch_settings,
427 .right_text = "IDS_ST_BUTTON_ENABLE_ENCRYPTION_ABB",
428 .right = send_ode_mount_signal,
429 .skip = skip_ode_popup,
430 .pre = launch_mmc_popup,
431 .terminate = terminate_mmc_popup,
434 static const struct popup_ops sdcard_setup_ops = {
435 .name = "sdcardsetup",
436 .pattern = FEEDBACK_PATTERN_LOWBATT,
437 .show = load_simple_popup,
438 .title = "IDS_ST_HEADER_COULDNT_USE_SD_CARD",
439 .get_content = sdcard_setup_get_content,
440 .left_text = "IDS_COM_SK_CANCEL",
441 .right_text = "IDS_TPLATFORM_BUTTON_SET_UP_ABB",
442 .right = launch_sdcard_setup,
443 .pre = launch_mmc_popup,
446 static const struct popup_ops unlock_extendedsd_ops = {
447 .name = "unlockextendedsd",
451 /* Constructor to register mmc popup */
452 static __attribute__ ((constructor)) void register_mmc_popup(void)
454 register_popup(&mount_error_ops);
455 register_popup(&unmount_error_ops);
456 register_popup(&mount_read_only_ops);
457 register_popup(&check_smack_ops);
458 register_popup(&ode_encrypt_ops);
459 register_popup(&ode_decrypt_ops);
460 register_popup(&sdcard_setup_ops);
461 register_popup(&unlock_extendedsd_ops);