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 #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 .pattern = FEEDBACK_PATTERN_LOWBATT,
271 .show = load_simple_popup,
272 .title = "IDS_IDLE_HEADER_COULDNT_MOUNT_SD_CARD_ABB",
273 .content = "IDS_IDLE_POP_REMOVE_AND_REINSERT_OR_FORMAT_YOUR_SD_CARD_THEN_TRY_AGAIN",
274 .left_text = "IDS_COM_SK_OK",
275 .skip = skip_mount_error_popup,
276 .pre = launch_mmc_popup,
279 static const struct popup_ops unmount_error_ops = {
280 .name = "unmounterr",//"mmc_unmount_error",
281 .pattern = FEEDBACK_PATTERN_LOWBATT,
282 .show = load_simple_popup,
283 .title = "IDS_IDLE_HEADER_COULDNT_UNMOUNT_SD_CARD_ABB",
284 .content = "IDS_IDLE_POP_THE_SD_CARD_MAY_BE_IN_USE_TRY_AGAIN_LATER",
285 .left_text = "IDS_COM_SK_OK",
286 .skip = skip_unmount_error_popup,
287 .pre = launch_mmc_popup,
290 static const struct popup_ops mount_read_only_ops = {
291 .name = "mountrdonly",//"mmc_mount_read_only",
292 .pattern = FEEDBACK_PATTERN_LOWBATT,
293 .show = load_simple_popup,
294 .content = "IDS_ST_BODY_SD_CARD_MOUNTED_READ_ONLY",
295 .left_text = "IDS_COM_SK_OK",
296 .pre = launch_mmc_popup,
299 static const struct popup_ops check_smack_ops = {
300 .name = "checksmack",//"mmc_check_smack",
301 .pattern = FEEDBACK_PATTERN_LOWBATT,
302 .show = load_simple_popup,
303 .content = "IDS_MF_BODY_MMC_DATA_IS_INITIALIZING_ING",
304 .left_text = "IDS_COM_SK_OK",
305 .pre = launch_mmc_popup,
308 static const struct popup_ops ode_encrypt_ops = {
309 .name = "odeencrypt",//"mmc_ode_encrypt",
310 .pattern = FEEDBACK_PATTERN_LOWBATT,
311 .show = load_simple_popup,
312 .title = "IDS_DN_BODY_ENCRYPT_SD_CARD",
313 .content = "IDS_ST_POP_TO_USE_YOUR_SD_CARD_IT_MUST_BE_ENCRYPTED_ENCRYPT_SD_CARD_OR_DISABLE_DEVICE_ENCRYPTION_Q",
314 .left_text = "IDS_ST_BUTTON_ENCRYPT_SD_CARD_ABB",
315 .left = ode_launch_settings,
316 .right_text = "IDS_ST_BUTTON_DISABLE_ENCRYPTION_ABB",
317 .right = send_general_mount_signal,
318 .skip = skip_ode_popup,
319 .pre = launch_mmc_popup,
320 .terminate = terminate_mmc_popup,
323 static const struct popup_ops ode_decrypt_ops = {
324 .name = "odedecrypt",//"mmc_ode_decrypt",
325 .pattern = FEEDBACK_PATTERN_LOWBATT,
326 .show = load_simple_popup,
327 .title = "IDS_DN_BODY_DECRYPT_SD_CARD",
328 .content = "IDS_ST_POP_TO_USE_YOUR_SD_CARD_IT_MUST_BE_DECRYPTED_DECRYPT_SD_CARD_OR_ENABLE_DEVICE_ENCRYPTION_Q",
329 .left_text = "IDS_ST_BUTTON_DECRYPT_SD_CARD_ABB",
330 .left = ode_launch_settings,
331 .right_text = "IDS_ST_BUTTON_ENABLE_ENCRYPTION_ABB",
332 .right = send_ode_mount_signal,
333 .skip = skip_ode_popup,
334 .pre = launch_mmc_popup,
335 .terminate = terminate_mmc_popup,
338 /* Constructor to register mmc popup */
339 static __attribute__ ((constructor)) void register_mmc_popup(void)
341 register_popup(&mount_error_ops);
342 register_popup(&unmount_error_ops);
343 register_popup(&mount_read_only_ops);
344 register_popup(&check_smack_ops);
345 register_popup(&ode_encrypt_ops);
346 register_popup(&ode_decrypt_ops);