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 mount_read_only_ops;
34 static const struct popup_ops check_smack_ops;
35 static const struct popup_ops ode_encrypt_ops;
36 static const struct popup_ops ode_decrypt_ops;
38 static void remove_other_mmc_popups(const struct popup_ops *ops)
40 if (ops != &mount_error_ops)
41 unload_simple_popup(&mount_error_ops);
43 if (ops != &mount_read_only_ops)
44 unload_simple_popup(&mount_read_only_ops);
46 if (ops != &check_smack_ops)
47 unload_simple_popup(&check_smack_ops);
49 if (ops != &ode_encrypt_ops)
50 unload_simple_popup(&ode_encrypt_ops);
52 if (ops != &ode_decrypt_ops)
53 unload_simple_popup(&ode_decrypt_ops);
56 static bool mmc_inserted(void)
59 if (vconf_get_int(VCONFKEY_SYSMAN_MMC_STATUS, &val) == 0
60 && val != VCONFKEY_SYSMAN_MMC_REMOVED)
65 static bool mmc_mounted(void)
68 if (vconf_get_int(VCONFKEY_SYSMAN_MMC_MOUNT, &val) == 0
69 && val == VCONFKEY_SYSMAN_MMC_MOUNT_FAILED)
74 static void send_mount_signal(char *signal)
81 ret = broadcast_dbus_signal(
83 DD_INTERFACE_NAME_ODE,
87 _E("FAIL: broadcast_dbus_signal(%s:%d)", signal, ret);
90 static void launch_app(char *appname)
100 ret = aul_launch_app(appname, b);
102 _E("FAIL: aul_launch_app(%d)", ret);
103 if (bundle_free(b) != 0)
104 _E("FAIL: bundle_free(b);");
106 _E("Failed to create bundle");
110 static void send_general_mount_signal(const struct popup_ops *ops)
112 unload_simple_popup(ops);
113 send_mount_signal(DD_SIGNAL_GENERAL_MOUNT);
114 terminate_if_no_popup();
117 static void send_ode_mount_signal(const struct popup_ops *ops)
119 unload_simple_popup(ops);
120 send_mount_signal(DD_SIGNAL_ODE_MOUNT);
121 terminate_if_no_popup();
124 static void ode_launch_settings(const struct popup_ops *ops)
126 unload_simple_popup(ops);
127 launch_app(SETTING_MMC_ENCRYPTION_UG);
128 terminate_if_no_popup();
131 static bool skip_mount_error_popup(bundle *b, const struct popup_ops *ops)
133 return mmc_mounted();
136 static bool skip_ode_popup(bundle *b, const struct popup_ops *ops)
138 return !mmc_inserted();
141 static E_DBus_Signal_Handler *mmc_removed_handler= NULL;
143 static void unregister_ode_handler(const struct popup_ops *ops)
145 if (mmc_removed_handler) {
146 unregister_dbus_signal_handler(mmc_removed_handler);
147 mmc_removed_handler = NULL;
151 static void mmc_removed(void *data, DBusMessage *msg)
153 const struct popup_ops *ops = data;
155 unregister_ode_handler(ops);
156 unload_simple_popup(ops);
157 terminate_if_no_popup();
160 static void register_ode_handler(const struct popup_ops *ops)
164 unregister_ode_handler(ops);
166 ret = register_dbus_signal_handler(&mmc_removed_handler,
168 DD_INTERFACE_NAME_ODE,
169 DD_SIGNAL_REMOVE_MMC,
173 _E("Failed to register mmc removed signal handler(%d)", ret);
176 static void mmc_mount_status_changed(keynode_t *in_key, void *data)
178 const struct popup_ops *ops = data;
180 if (vconf_keynode_get_int(in_key) == VCONFKEY_SYSMAN_MMC_MOUNT_FAILED)
183 unload_simple_popup(ops);
184 terminate_if_no_popup();
187 static void register_mmc_mount_handler(const struct popup_ops *ops)
189 if (vconf_notify_key_changed(VCONFKEY_SYSMAN_MMC_MOUNT,
190 mmc_mount_status_changed, (void *)ops) != 0)
191 _E("Failed to register mmc mount handler");
194 static void unregister_mmc_mount_handler(const struct popup_ops *ops)
196 vconf_ignore_key_changed(VCONFKEY_SYSMAN_MMC_MOUNT,
197 mmc_mount_status_changed);
200 static int launch_mmc_popup(bundle *b, const struct popup_ops *ops)
202 remove_other_mmc_popups(ops);
203 unregister_ode_handler(ops);
205 if (ops == &mount_error_ops)
206 register_mmc_mount_handler(ops);
208 if (ops == &ode_encrypt_ops ||
209 ops == &ode_decrypt_ops)
210 register_ode_handler(ops);
215 static void terminate_mmc_popup(const struct popup_ops *ops)
217 unregister_mmc_mount_handler(ops);
218 unregister_ode_handler(ops);
221 static const struct popup_ops mount_error_ops = {
222 .name = "mounterr",//"mmc_mount_error",
223 .show = load_simple_popup,
224 .content = "IDS_DN_POP_FAILED_TO_MOUNT_SD_CARD_REINSERT_OR_FORMAT_SD_CARD",
225 .left_text = "IDS_COM_SK_OK",
226 .skip = skip_mount_error_popup,
227 .pre = launch_mmc_popup,
230 static const struct popup_ops mount_read_only_ops = {
231 .name = "mountrdonly",//"mmc_mount_read_only",
232 .show = load_simple_popup,
233 .content = "IDS_ST_BODY_SD_CARD_MOUNTED_READ_ONLY",
234 .left_text = "IDS_COM_SK_OK",
235 .pre = launch_mmc_popup,
238 static const struct popup_ops check_smack_ops = {
239 .name = "checksmack",//"mmc_check_smack",
240 .show = load_simple_popup,
241 .content = "IDS_MF_BODY_MMC_DATA_IS_INITIALIZING_ING",
242 .left_text = "IDS_COM_SK_OK",
243 .pre = launch_mmc_popup,
246 static const struct popup_ops ode_encrypt_ops = {
247 .name = "odeencrypt",//"mmc_ode_encrypt",
248 .show = load_simple_popup,
249 .title = "IDS_DN_BODY_ENCRYPT_SD_CARD",
250 .content = "IDS_ST_POP_TO_USE_YOUR_SD_CARD_IT_MUST_BE_ENCRYPTED_ENCRYPT_SD_CARD_OR_DISABLE_DEVICE_ENCRYPTION_Q",
251 .left_text = "IDS_ST_BUTTON_ENCRYPT_SD_CARD_ABB",
252 .left = ode_launch_settings,
253 .right_text = "IDS_ST_BUTTON_DISABLE_ENCRYPTION_ABB",
254 .right = send_general_mount_signal,
255 .skip = skip_ode_popup,
256 .pre = launch_mmc_popup,
257 .terminate = terminate_mmc_popup,
260 static const struct popup_ops ode_decrypt_ops = {
261 .name = "odedecrypt",//"mmc_ode_decrypt",
262 .show = load_simple_popup,
263 .title = "IDS_DN_BODY_DECRYPT_SD_CARD",
264 .content = "IDS_ST_POP_TO_USE_YOUR_SD_CARD_IT_MUST_BE_DECRYPTED_DECRYPT_SD_CARD_OR_ENABLE_DEVICE_ENCRYPTION_Q",
265 .left_text = "IDS_ST_BUTTON_DECRYPT_SD_CARD_ABB",
266 .left = ode_launch_settings,
267 .right_text = "IDS_ST_BUTTON_ENABLE_ENCRYPTION_ABB",
268 .right = send_ode_mount_signal,
269 .skip = skip_ode_popup,
270 .pre = launch_mmc_popup,
271 .terminate = terminate_mmc_popup,
274 /* Constructor to register mmc popup */
275 static __attribute__ ((constructor)) void register_mmc_popup(void)
277 register_popup(&mount_error_ops);
278 register_popup(&mount_read_only_ops);
279 register_popup(&check_smack_ops);
280 register_popup(&ode_encrypt_ops);
281 register_popup(&ode_decrypt_ops);