2 * Copyright (c) 2009-2015 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include <Elementary.h>
21 #include <syspopup_caller.h>
22 #include <pkgmgr-info.h>
23 #include <bundle_internal.h>
24 #include <notification.h>
25 #include <notification_internal.h>
26 #include <notification_list.h>
29 #include <tzsh_quickpanel_service.h>
34 #include "emergency_mode.h"
35 #include "quickpanel-ui.h"
37 #ifdef QP_SETTING_ENABLE
38 extern QP_Module settings_view_featured;
40 #ifdef QP_BRIGHTNESS_ENABLE
41 extern QP_Module brightness_ctrl;
44 #define SETTING_SYSPOPUP "mode-syspopup"
45 #define BT_SHARE_DAEMON "/usr/bin/bluetooth-share"
46 #define BT_SHARE_SERVER "bluetooth-share-opp-server"
47 #define BT_SHARE_CLIENT "bluetooth-share-opp-client"
48 #define SCREEN_SHOT "shot-tizen"
52 Eina_List *permitted_apps;
55 .permitted_apps = NULL,
58 static void _delete_unpermitted_app(void)
60 notification_list_h noti_list = NULL;
61 notification_list_h list_traverse = NULL;
62 notification_h noti = NULL;
64 notification_get_list(NOTIFICATION_TYPE_NONE, -1, ¬i_list);
66 list_traverse = noti_list;
68 while (list_traverse != NULL) {
69 noti = notification_list_get_data(list_traverse);
71 quickpanel_emergency_mode_notification_filter(noti, 1);
73 list_traverse = notification_list_get_next(list_traverse);
76 if (noti_list != NULL) {
77 notification_free_list(noti_list);
82 static void _emergency_mode_start(void *data)
84 struct appdata *ad = data;
85 retif(ad == NULL, , "Invalid parameter!");
87 if (s_info.is_enabled) {
91 quickpanel_datetime_datentime_event_set(0);
92 #ifdef QP_SETTING_ENABLE
93 if (settings_view_featured.fini != NULL) {
94 settings_view_featured.fini(ad);
97 #ifdef QP_BRIGHTNESS_ENABLE
98 if (brightness_ctrl.fini != NULL) {
99 brightness_ctrl.fini(ad);
103 _delete_unpermitted_app();
104 s_info.is_enabled = 1;
105 ERR("emergency mode is enabled");
108 static void _emergency_mode_stop(void *data)
110 struct appdata *ad = data;
111 retif(ad == NULL, , "Invalid parameter!");
113 if (!s_info.is_enabled) {
117 quickpanel_datetime_datentime_event_set(1);
119 #ifdef QP_SETTING_ENABLE
120 if (settings_view_featured.init != NULL) {
121 settings_view_featured.init(ad);
123 if (settings_view_featured.init_job_cb != NULL) {
124 settings_view_featured.init_job_cb(ad);
127 #ifdef QP_BRIGHTNESS_ENABLE
128 if (brightness_ctrl.init != NULL) {
129 brightness_ctrl.init(ad);
133 _delete_unpermitted_app();
134 s_info.is_enabled = 0;
135 ERR("emergency mode is disabled");
138 static void _vconf_cb(keynode_t *node, void *data)
142 if (vconf_get_int(VCONFKEY_SETAPPL_PSMODE, &mode) == 0) {
143 if (mode == SETTING_PSMODE_EMERGENCY) {
144 _emergency_mode_start(data);
146 _emergency_mode_stop(data);
149 ERR("failed to get the value of VCONFKEY_SETAPPL_PSMODE");
153 static int _app_list_cb(pkgmgrinfo_appinfo_h handle, void *user_data)
156 char *permitted_appid = NULL;
157 pkgmgrinfo_appinfo_get_appid(handle, &appid);
159 permitted_appid = strdup(appid);
161 s_info.permitted_apps = eina_list_append(s_info.permitted_apps, permitted_appid);
162 DBG("%s is permitted.", permitted_appid);
168 static int _register_permitted_apps(void)
171 pkgmgrinfo_appinfo_filter_h handle;
173 s_info.permitted_apps = eina_list_append(s_info.permitted_apps, BT_SHARE_DAEMON);
174 s_info.permitted_apps = eina_list_append(s_info.permitted_apps, SCREEN_SHOT);
175 s_info.permitted_apps = eina_list_append(s_info.permitted_apps, BT_SHARE_SERVER);
176 s_info.permitted_apps = eina_list_append(s_info.permitted_apps, BT_SHARE_CLIENT);
178 ret = pkgmgrinfo_appinfo_filter_create(&handle);
179 if (ret != PMINFO_R_OK) {
183 ret = pkgmgrinfo_appinfo_filter_add_int(handle, PMINFO_APPINFO_PROP_APP_SUPPORT_MODE, 1);
184 if (ret != PMINFO_R_OK) {
185 pkgmgrinfo_appinfo_filter_destroy(handle);
189 ret = pkgmgrinfo_appinfo_filter_foreach_appinfo(handle, _app_list_cb, NULL);
190 if (ret != PMINFO_R_OK) {
191 pkgmgrinfo_appinfo_filter_destroy(handle);
195 pkgmgrinfo_appinfo_filter_destroy(handle);
200 static int _delete_permitted_apps(void)
202 Eina_List *list = NULL;
205 if (!s_info.permitted_apps) {
206 EINA_LIST_FOREACH(s_info.permitted_apps, list, appid)
208 eina_list_free(s_info.permitted_apps);
209 s_info.permitted_apps = NULL;
215 HAPI void quickpanel_emergency_mode_init(void *data)
218 struct appdata *ad = data;
219 retif(ad == NULL, , "Invalid parameter!");
221 ret = _register_permitted_apps();
222 msgif(ret !=0, "failed to register permitted apps");
224 ret = vconf_notify_key_changed(VCONFKEY_SETAPPL_PSMODE,
226 msgif(ret != 0, "failed to notify key(VCONFKEY_SETAPPL_PSMODE) : %d", ret);
228 if (quickpanel_emergency_mode_is_on()) {
229 s_info.is_enabled = 1;
233 HAPI void quickpanel_emergency_mode_fini(void *data)
236 struct appdata *ad = data;
237 retif(ad == NULL, , "Invalid parameter!");
239 ret = _delete_permitted_apps();
240 msgif(ret !=0, "failed to delete permitted apps");
242 ret = vconf_ignore_key_changed(VCONFKEY_SETAPPL_PSMODE, _vconf_cb);
243 msgif(ret != 0, "failed to ignore key(VCONFKEY_SETAPPL_PSMODE) : %d", ret);
246 HAPI int quickpanel_emergency_mode_is_permitted_app(const char *appid)
250 char *permitted_app = NULL;
251 retif(appid == NULL, 0, "Invalid parameter!");
253 count = eina_list_count(s_info.permitted_apps);
254 for(i = 0; i < count; i++) {
255 permitted_app = (char *)eina_list_nth(s_info.permitted_apps, i);
256 if (permitted_app != NULL && strcmp(permitted_app, appid) == 0) {
264 HAPI int quickpanel_emergency_mode_is_on(void)
268 if (vconf_get_int(VCONFKEY_SETAPPL_PSMODE, &mode) == 0) {
269 if (mode == SETTING_PSMODE_EMERGENCY) {
277 HAPI int quickpanel_emergency_mode_notification_filter(notification_h noti, int is_delete)
280 char *pkgname = NULL;
282 notification_get_pkgname(noti, &pkgname);
283 notification_get_id(noti, NULL, &priv_id);
285 DBG("Emergency mode filter is called: %s", pkgname);
286 if (!quickpanel_emergency_mode_is_permitted_app(pkgname)) {
288 notification_delete_by_priv_id(pkgname, NOTIFICATION_TYPE_NONE, priv_id);
296 HAPI int quickpanel_emergency_mode_syspopup_launch(void)
308 bundle_add(b, "_MODE_SYSTEM_POPUP_TYPE_", "POPUP_EMERGENCY_PSMODE");
309 ret = syspopup_launch(SETTING_SYSPOPUP, b);
311 ERR("failed to launch syspopup (%s):%d\n", SETTING_SYSPOPUP, ret);