2 * Copyright (c) 2016 Samsung Electronics Co., Ltd.
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.
21 #include <syspopup_caller.h>
23 #include <bundle_internal.h>
27 #include "stc-plugin-appstatus.h"
30 #define AUL_APP_STATUS_DBUS_PATH "/Org/Tizen/Aul/AppStatus"
31 #define AUL_APP_STATUS_DBUS_SIGNAL_INTERFACE "org.tizen.aul.AppStatus"
32 #define AUL_APP_STATUS_BUS_NAME AUL_APP_STATUS_DBUS_SIGNAL_INTERFACE
34 #define AUL_APP_STATUS_DBUS_STATUS_CHANGE "AppStatusChange"
35 #define AUL_APP_STATUS_DBUS_STATUS_CHANGE_TYPE "(issss)"
40 const gchar *interface;
42 const gchar *param_type;
43 GDBusSignalCallback callback;
47 stc_error_e(*state_changed_cb)(stc_cmd_type_e cmd, pid_t pid,
48 const gchar *app_id, const gchar *pkg_id,
49 stc_app_type_e app_type);
51 static void __stc_gdbus_handle_aul_changestate(GDBusConnection *connection,
52 const gchar *sender_name,
53 const gchar *object_path,
54 const gchar *interface_name,
55 const gchar *signal_name,
60 stc_cmd_type_e status;
61 stc_app_type_e apptype;
62 gchar *appid, *pkgid, *statstr, *pkgtype;
64 if (g_strcmp0(g_variant_get_type_string(parameters),
65 AUL_APP_STATUS_DBUS_STATUS_CHANGE_TYPE)) {
66 STC_LOGE("Dbus type not matching, do not process");
70 g_variant_get(parameters, AUL_APP_STATUS_DBUS_STATUS_CHANGE_TYPE,
71 &pid, &appid, &pkgid, &statstr, &pkgtype);
73 if (!strncmp(statstr, "fg", 2)) {
74 status = STC_CMD_SET_FOREGRD;
75 } else if (!strncmp(statstr, "bg", 2)) {
76 status = STC_CMD_SET_BACKGRD;
81 if (!strncmp(pkgtype, "svc", 3))
82 apptype = STC_APP_TYPE_SERVICE;
83 else if (!strncmp(pkgtype, "widget", 6))
84 apptype = STC_APP_TYPE_WIDGET;
85 else if (!strncmp(pkgtype, "watch", 5))
86 apptype = STC_APP_TYPE_WATCH;
88 apptype = STC_APP_TYPE_GUI;
91 STC_LOGD("\033[1;36mAPP STATUS\033[0;m: Pkg ID [\033[0;34m%s\033[0;m], "
92 "App ID [\033[0;32m%s\033[0;m], PID [\033[1;33m%d\033[0;m], Status [%s], Type [%s]",
93 pkgid, appid, pid, statstr, pkgtype);
97 state_changed_cb(status, pid, appid, pkgid, apptype);
106 signal_map_s signal_map[] = {
111 AUL_APP_STATUS_DBUS_PATH,
112 AUL_APP_STATUS_DBUS_SIGNAL_INTERFACE,
113 AUL_APP_STATUS_DBUS_STATUS_CHANGE,
114 AUL_APP_STATUS_DBUS_STATUS_CHANGE_TYPE,
115 __stc_gdbus_handle_aul_changestate,
127 static stc_error_e __ground_status_monitor_init(stc_s *stc)
131 ret_value_msg_if(stc == NULL, STC_ERROR_INVALID_PARAMETER, "failed to get stc data");
133 for (i = 0; signal_map[i].member != NULL; i++) {
134 signal_map[i].sub_id =
135 g_dbus_connection_signal_subscribe(stc->connection,
137 signal_map[i].interface,
138 signal_map[i].member,
141 G_DBUS_SIGNAL_FLAGS_NONE,
142 signal_map[i].callback,
143 signal_map[i].user_data,
145 STC_LOGI("Successfully subscribed [%s] signal",
146 signal_map[i].member);
149 return STC_ERROR_NONE;
152 static stc_error_e __ground_status_monitor_deinit(stc_s *stc)
156 ret_value_msg_if(stc == NULL, STC_ERROR_INVALID_PARAMETER, "failed to get stc data");
158 for (i = 0; signal_map[i].member != NULL; i++) {
159 g_dbus_connection_signal_unsubscribe(stc->connection,
160 signal_map[i].sub_id);
161 signal_map[i].sub_id = 0;
162 STC_LOGD("Successfully unsubscribed [%s] signal",
163 signal_map[i].member);
166 return STC_ERROR_NONE;
169 int stc_plugin_appstatus_register_changed_cb(stc_s *stc,
170 stc_plugin_app_state_changed_cb cb,
173 state_changed_cb = cb;
174 __ground_status_monitor_init(stc);
179 int stc_plugin_appstatus_deregister_changed_cb(stc_s *stc)
181 state_changed_cb = NULL;
182 __ground_status_monitor_deinit(stc);
186 int stc_plugin_popup_send_message(const char *content,
187 const char *type, const char *app_id, const char *iftype, const char *limit)
190 bundle *b = bundle_create();
192 bundle_add(b, "_SYSPOPUP_CONTENT_", content);
193 bundle_add(b, "_SYSPOPUP_TYPE_", type);
194 bundle_add(b, "_APP_ID_", app_id);
195 bundle_add(b, "_IF_TYPE_", iftype);
197 if (g_strcmp0(type, "warning_noti") == 0) {
198 bundle_add(b, "_WARN_LIMIT_", limit);
199 STC_LOGD("Warn message : content[%s] type[%s] app_id[%s] limit[%s]",
200 content, type, app_id, limit);
202 bundle_add(b, "_RESTRICTION_LIMIT_", limit);
203 STC_LOGD("Restriction message : content[%s] type[%s] app_id[%s] limit[%s]",
204 content, type, app_id, limit);
207 ret = syspopup_launch("net-popup", b);
214 API stc_plugin_appstatus_s stc_plugin_appstatus = {
215 .send_message_to_net_popup =
216 stc_plugin_popup_send_message,
217 .register_state_changed_cb =
218 stc_plugin_appstatus_register_changed_cb,
219 .deregister_state_changed_cb =
220 stc_plugin_appstatus_deregister_changed_cb