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;34mAPP STATUS\033[0;m: PkgID[\033[0;34m%s\033[0;m] "
92 "AppID[\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)
132 ret_value_msg_if(stc == NULL, STC_ERROR_INVALID_PARAMETER, "failed to get stc data");
134 size = sizeof(signal_map) / sizeof(signal_map[0]);
136 for (i = 0; signal_map[i].member != NULL && i < size; i++) {
137 signal_map[i].sub_id =
138 g_dbus_connection_signal_subscribe(stc->connection,
140 signal_map[i].interface,
141 signal_map[i].member,
144 G_DBUS_SIGNAL_FLAGS_NONE,
145 signal_map[i].callback,
146 signal_map[i].user_data,
148 STC_LOGI("Successfully subscribed [%s] signal",
149 signal_map[i].member);
152 return STC_ERROR_NONE;
155 static stc_error_e __ground_status_monitor_deinit(stc_s *stc)
160 ret_value_msg_if(stc == NULL, STC_ERROR_INVALID_PARAMETER, "failed to get stc data");
162 size = sizeof(signal_map) / sizeof(signal_map[0]);
164 for (i = 0; signal_map[i].member != NULL && i < size; i++) {
165 g_dbus_connection_signal_unsubscribe(stc->connection,
166 signal_map[i].sub_id);
167 signal_map[i].sub_id = 0;
168 STC_LOGD("Successfully unsubscribed [%s] signal",
169 signal_map[i].member);
172 return STC_ERROR_NONE;
175 int stc_plugin_appstatus_register_changed_cb(stc_s *stc,
176 stc_plugin_app_state_changed_cb cb,
179 state_changed_cb = cb;
180 __ground_status_monitor_init(stc);
185 int stc_plugin_appstatus_deregister_changed_cb(stc_s *stc)
187 state_changed_cb = NULL;
188 __ground_status_monitor_deinit(stc);
192 int stc_plugin_popup_send_message(const char *content,
193 const char *type, const char *app_id, const char *iftype, const char *limit)
196 bundle *b = bundle_create();
198 bundle_add(b, "_SYSPOPUP_CONTENT_", content);
199 bundle_add(b, "_SYSPOPUP_TYPE_", type);
200 bundle_add(b, "_APP_ID_", app_id);
201 bundle_add(b, "_IF_TYPE_", iftype);
203 if (g_strcmp0(type, "warning_noti") == 0) {
204 bundle_add(b, "_WARN_LIMIT_", limit);
205 STC_LOGD("Warn message : content[%s] type[%s] app_id[%s] limit[%s]",
206 content, type, app_id, limit);
208 bundle_add(b, "_RESTRICTION_LIMIT_", limit);
209 STC_LOGD("Restriction message : content[%s] type[%s] app_id[%s] limit[%s]",
210 content, type, app_id, limit);
213 ret = syspopup_launch("net-popup", b);
220 API stc_plugin_appstatus_s stc_plugin_appstatus = {
221 .send_message_to_net_popup =
222 stc_plugin_popup_send_message,
223 .register_state_changed_cb =
224 stc_plugin_appstatus_register_changed_cb,
225 .deregister_state_changed_cb =
226 stc_plugin_appstatus_deregister_changed_cb