3 * Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
23 #include <bundle_internal.h>
25 #include <appcore-efl.h>
27 #include <Elementary.h>
28 #include <syspopup_caller.h>
29 #include <dbus/dbus.h>
32 #define DBUS_REPLY_TIMEOUT (120 * 1000)
35 #define MMC_ENCRYPTION_UG "setting-mmc-encryption-efl"
36 #define SECURITY_UG "setting-security-efl"
44 static bool (*is_storage_encryption_restricted)(void) = NULL;
46 void register_storage_encryption_restricted_function(bool (*func)(void))
49 is_storage_encryption_restricted = func;
52 static Eina_Bool exit_idler_cb(void *data)
55 return ECORE_CALLBACK_CANCEL;
58 static void sender_terminate(void)
60 if (ecore_idler_add(exit_idler_cb, NULL))
65 static int append_variant(DBusMessageIter *iter, const char *sig, char *param[])
73 for (ch = (char*)sig, i = 0; *ch != '\0'; ++i, ++ch) {
76 dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, ¶m[i]);
79 int_type = atoi(param[i]);
80 dbus_message_iter_append_basic(iter, DBUS_TYPE_INT32, &int_type);
83 _E("ERROR: %s %c", sig, *ch);
90 DBusMessage *call_dbus_method(const char *dest, const char *path,
91 const char *interface, const char *method,
92 const char *sig, char *param[])
95 DBusMessage *msg = NULL;
101 conn = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
107 msg = dbus_message_new_method_call(dest, path, interface, method);
113 dbus_message_iter_init_append(msg, &iter);
114 r = append_variant(&iter, sig, param);
120 /*This function is for synchronous dbus method call */
121 dbus_error_init(&err);
122 ret = dbus_connection_send_with_reply_and_block(conn, msg, DBUS_REPLY_TIMEOUT, &err);
123 dbus_error_free(&err);
126 dbus_message_unref(msg);
131 int call_dbus_method_for_pairs(const char *dest, const char *path,
132 const char *interface, const char *method,
133 int size, char *param[])
135 DBusConnection *conn;
136 DBusMessage *msg = NULL;
138 DBusMessageIter iter, aiter, piter;
143 conn = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
146 _E("dbus_bus_get error");
150 msg = dbus_message_new_method_call(dest, path, interface, method);
152 _E("dbus_message_new_method_call(%s:%s-%s)", path, interface, method);
156 dbus_message_iter_init_append(msg, &iter);
157 dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, "{ss}", &aiter);
158 for (i = 0 ; i < size ; i = i + 2) {
161 _I("key(%s), value(%s)", key, value);
162 dbus_message_iter_open_container(&aiter, DBUS_TYPE_DICT_ENTRY, NULL, &piter);
163 dbus_message_iter_append_basic(&piter, DBUS_TYPE_STRING, &key);
164 dbus_message_iter_append_basic(&piter, DBUS_TYPE_STRING, &value);
165 dbus_message_iter_close_container(&aiter, &piter);
168 dbus_message_iter_close_container(&iter, &aiter);
169 dbus_error_init(&err);
171 reply = dbus_connection_send_with_reply_and_block(conn, msg, DBUS_REPLY_TIMEOUT, &err);
172 dbus_message_unref(msg);
174 _E("dbus_connection_send error(%s:%s) %s %s:%s-%s", err.name, err.message, dest, path, interface, method);
175 dbus_error_free(&err);
179 ret = dbus_message_get_args(reply, &err, DBUS_TYPE_INT32, &result, DBUS_TYPE_INVALID);
180 dbus_message_unref(reply);
182 _E("no message : [%s:%s] %s %s:%s-%s", err.name, err.message, dest, path, interface, method);
183 dbus_error_free(&err);
190 int request_to_launch_by_dbus(char *bus, char *path, char *iface,
191 char *method, char *ptype, char *param[])
199 msg = call_dbus_method(bus, path, iface, method, ptype, param);
203 } while (i < RETRY_MAX);
205 _E("fail to call dbus method");
206 return -ECONNREFUSED;
209 dbus_error_init(&err);
210 r = dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &ret_val, DBUS_TYPE_INVALID);
212 _E("no message : [%s:%s]", err.name, err.message);
216 dbus_message_unref(msg);
217 dbus_error_free(&err);
223 int request_to_launch_by_dbus_for_pairs(char *bus, char *path, char *iface,
224 char *method, int size, char *param[])
226 return (call_dbus_method_for_pairs(bus, path, iface, method, size, param));
229 static int send_recovery_popup_signal(void)
233 param[0] = "_SYSPOPUP_CONTENT_";
234 param[1] = "recovery";
236 return request_to_launch_by_dbus(BUS_NAME, POPUP_PATH_SYSTEM, POPUP_IFACE_SYSTEM,
237 "RecoveryPopupLaunch", "ss", param);
240 static int send_usbstorage_unmount_popup_signal(char *path)
248 snprintf(buf, sizeof(buf), "%s", path);
250 param[0] = "_SYSPOPUP_CONTENT_";
251 param[1] = "usbotg_unmount_storage";
252 param[2] = "_DEVICE_PATH_";
255 return request_to_launch_by_dbus_for_pairs(BUS_NAME, POPUP_PATH_SYSTEM, POPUP_IFACE_SYSTEM,
256 "PopupLaunch", sizeof(param)/sizeof(param[0]), param);
259 static int send_cooldown_popup_signal(void)
263 param[0] = "_SYSPOPUP_CONTENT_";
264 param[1] = "cooldown";
266 return request_to_launch_by_dbus_for_pairs(BUS_NAME, POPUP_PATH_SYSTEM, POPUP_IFACE_SYSTEM,
267 "PopupLaunch", sizeof(param)/sizeof(param[0]), param);
270 static int get_err_and_space(bundle *b, char *type,
271 char *error, int error_len, char *space, int space_len)
276 cErr = (char *)bundle_get_val(b, SIGNAL_SENDER_ERROR_TYPE);
278 _E("Failed to get error type");
282 spc = (char *)bundle_get_val(b, SIGNAL_SENDER_MEMORY_SPACE);
284 _E("Failed to get memory space");
290 case NOT_ENOUGH_SPACE:
291 snprintf(error, error_len, "%s_not_enough_space", type);
293 case OPERATION_FAILED:
294 snprintf(error, error_len, "%s_operation_failed", type);
297 _E("Unknown type (%d)", iErr);
301 snprintf(space, space_len, "%s", spc);
306 static int send_ode_error_popup_signal(bundle *b, char *type)
316 ret = get_err_and_space(b, type,
317 error, sizeof(error), space, sizeof(space));
321 param[0] = "_SYSPOPUP_CONTENT_";
322 param[1] = "ode_error";
323 param[2] = SIGNAL_SENDER_ERROR_TYPE;
325 param[4] = SIGNAL_SENDER_MEMORY_SPACE;
328 return request_to_launch_by_dbus(BUS_NAME, POPUP_PATH_SYSTEM, POPUP_IFACE_SYSTEM,
329 "PopupLaunchTriple", "ssssss", param);
332 static int load_ode_setting_ug(void)
337 bool restricted = false;
339 if (is_storage_encryption_restricted)
340 restricted = is_storage_encryption_restricted();
343 setting_ug = SECURITY_UG;
345 setting_ug = MMC_ENCRYPTION_UG;
351 ret = aul_launch_app(setting_ug, b);
354 _E("Failed to launch app (%s)(%d)", setting_ug, ret);
361 static int app_create(void *data)
366 static int app_terminate(void *data)
371 static int app_pause(void *data)
376 static int app_resume(void *data)
381 static int app_reset(bundle *b, void *data)
392 type = (char *)bundle_get_val(b, SIGNAL_SENDER_TYPE);
394 _E("FAIL: bundle_get_val()");
399 if (!strncmp(type, SIGNAL_SENDER_TYPE_RECOVERY, strlen(SIGNAL_SENDER_TYPE_RECOVERY))) {
400 ret = send_recovery_popup_signal();
404 if (!strncmp(type, SIGNAL_SENDER_TYPE_USBSTORAGE_UNMOUNT,
405 strlen(SIGNAL_SENDER_TYPE_USBSTORAGE_UNMOUNT))) {
406 path = (char *)bundle_get_val(b, "_DEVICE_PATH_");
408 _E("FAIL: bundle_get_val()");
413 ret = send_usbstorage_unmount_popup_signal(path);
417 if (!strncmp(type, SIGNAL_SENDER_TYPE_COOLDOWN, strlen(SIGNAL_SENDER_TYPE_COOLDOWN))) {
418 ret = send_cooldown_popup_signal();
422 if (!strncmp(type, SIGNAL_SENDER_TYPE_ENCRYPT, strlen(SIGNAL_SENDER_TYPE_ENCRYPT))) {
423 ret = send_ode_error_popup_signal(b, type);
427 if (!strncmp(type, SIGNAL_SENDER_TYPE_DECRYPT, strlen(SIGNAL_SENDER_TYPE_DECRYPT))) {
428 ret = send_ode_error_popup_signal(b, type);
432 if (!strncmp(type, SIGNAL_SENDER_TYPE_ODE_UG, strlen(type))) {
433 ret = load_ode_setting_ug();
444 int main(int argc, char *argv[])
446 struct appcore_ops ops = {
447 .create = app_create,
448 .terminate = app_terminate,
450 .resume = app_resume,
454 return appcore_efl_main(PACKAGE, &argc, &argv, &ops);