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"
22 static const struct popup_ops usb_error_ops;
23 static const struct popup_ops usb_restrict_ops;
25 static int state_handler = -1;
27 static void usb_state_changed(keynode_t *key, void *data)
30 const struct popup_ops *ops = data;
32 if (vconf_get_int(VCONFKEY_SYSMAN_USB_STATUS, &state) != 0)
36 case VCONFKEY_SYSMAN_USB_DISCONNECTED:
37 _I("USB cabel is disconnected.");
38 unload_simple_popup(ops);
39 if (state_handler == 0) {
40 vconf_ignore_key_changed(
41 VCONFKEY_SYSMAN_USB_STATUS,
45 terminate_if_no_popup();
47 case VCONFKEY_SYSMAN_USB_CONNECTED:
48 case VCONFKEY_SYSMAN_USB_AVAILABLE:
54 static int usb_launch(bundle *b, const struct popup_ops *ops)
56 const struct popup_ops *remove;
58 if (ops == &usb_error_ops)
59 remove = &usb_restrict_ops;
60 else if (ops == &usb_restrict_ops)
61 remove = &usb_error_ops;
66 unload_simple_popup(remove);
68 if (state_handler != 0) {
69 state_handler = vconf_notify_key_changed(
70 VCONFKEY_SYSMAN_USB_STATUS,
71 usb_state_changed, (void *)ops);
72 if (state_handler != 0)
73 _E("Failed to register usb state change event().");
79 static void usb_terminate(const struct popup_ops *ops)
81 if (state_handler == 0) {
82 vconf_ignore_key_changed(
83 VCONFKEY_SYSMAN_USB_STATUS,
87 terminate_if_no_popup();
90 static const struct popup_ops usb_error_ops = {
92 .pattern = FEEDBACK_PATTERN_LOWBATT,
93 .show = load_simple_popup,
94 .content = "IDS_USB_POP_USB_CONNECTION_FAILED",
95 .left_text = "IDS_COM_SK_OK",
97 .terminate = usb_terminate,
100 static const struct popup_ops usb_restrict_ops = {
101 .name = "usb_restrict",
102 .pattern = FEEDBACK_PATTERN_LOWBATT,
103 .show = load_simple_popup,
104 .content = "IDS_ST_POP_SECURITY_POLICY_PREVENTS_USE_OF_DESKTOP_SYNC",
105 .left_text = "IDS_COM_SK_OK",
107 .terminate = usb_terminate,
111 /* Constructor to register mount_failed button */
112 static __attribute__ ((constructor)) void usb_register_popup(void)
114 register_popup(&usb_error_ops);
115 register_popup(&usb_restrict_ops);