power: add power lock expired popup 83/91183/2
authortaeyoung <ty317.kim@samsung.com>
Thu, 6 Oct 2016 07:00:53 +0000 (16:00 +0900)
committertaeyoung <ty317.kim@samsung.com>
Fri, 7 Oct 2016 06:14:28 +0000 (15:14 +0900)
- When an app locks power for a long time,
  the popup is launched for user to decide
  whether or not system terminates the app.

Change-Id: Ie8240a3210eeb1dbc13473b1d2158ff68ffd3c88
Signed-off-by: taeyoung <ty317.kim@samsung.com>
packaging/system-servant.spec
src/CMakeLists.txt
src/power/power.c [new file with mode: 0755]

index 18aa305..cdfe603 100755 (executable)
@@ -16,6 +16,7 @@
 %define battery_popup off
 %define cooldown_popup off
 %define mmc_popup off
+%define power_popup off
 %define usb_popup off
 %define watchdog_popup off
 %define storage_popup off
@@ -35,6 +36,7 @@
 %define battery_popup on
 %define cooldown_popup on
 %define mmc_popup on
+%define power_popup on
 %define usb_popup on
 %define watchdog_popup on
 %define storage_popup on
@@ -53,6 +55,7 @@
 %define watchdog_popup on
 %define battery_popup on
 %define cooldown_popup on
+%define power_popup on
 %endif
 
 %if "%{?profile}" == "tv"
@@ -236,6 +239,7 @@ cp %{SOURCE2003} .
                -DUSB_POPUP=%{usb_popup} \
                -DWATCHDOG_POPUP=%{watchdog_popup} \
                -DOVERHEAT_POPUP=%{overheat_popup} \
+               -DPOWER_POPUP=%{power_popup} \
 
 make %{?jobs:-j%jobs}
 
index 9657ace..97695bb 100755 (executable)
@@ -48,6 +48,10 @@ IF(MMC_POPUP STREQUAL on)
        ENDIF()
 ENDIF(MMC_POPUP STREQUAL on)
 
+IF(POWER_POPUP STREQUAL on)
+       SET(SRCS ${SRCS} power/power.c)
+ENDIF()
+
 IF(USB_POPUP STREQUAL on)
        IF(PROFILE_MOBILE)
                SET(SRCS ${SRCS}
diff --git a/src/power/power.c b/src/power/power.c
new file mode 100755 (executable)
index 0000000..8f2ccff
--- /dev/null
@@ -0,0 +1,138 @@
+/*
+ *  system-popup
+ *
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+*/
+
+#include <app_manager.h>
+#include "popup-common.h"
+
+#define APP_PID       "_APP_PID_"
+
+#define DBUS_POWER_PATH "/Org/Tizen/System/DeviceD/Power"
+#define DBUS_POWER_IFACE "org.tizen.system.deviced.power"
+#define METHOD_POWER_LOCK_EXPIRED "PowerLockExpired"
+
+static const struct popup_ops power_lock_expired_ops;
+static bool signal_broadcasted;
+
+enum button_selected {
+       ALLOW_APP,
+       CLOSE_APP,
+};
+
+static void send_result_dbus_signal(int result)
+{
+       int ret;
+       char buf[8];
+       char *param[1];
+
+       if (signal_broadcasted)
+               return;
+
+       signal_broadcasted = true;
+
+       snprintf(buf, sizeof(buf), "%d", result);
+       param[0] = buf;
+       ret = broadcast_dbus_signal(DBUS_POWER_PATH,
+                       DBUS_POWER_IFACE,
+                       METHOD_POWER_LOCK_EXPIRED,
+                       "i", param);
+       if (ret < 0)
+               _E("FAIL: broadcast_dbus_signal(%d)", ret);
+}
+
+static int power_lock_expired_get_content(const struct popup_ops *ops, char *content, unsigned int len)
+{
+       char *text, *pid_str, *name;
+       struct object_ops *obj;
+       int ret;
+       int pid;
+
+       if (!ops || !content)
+               return -EINVAL;
+
+       ret = get_object_by_ops(ops, &obj);
+       if (ret < 0) {
+               _E("Failed to get object (%d)", ret);
+               return -ENOENT;
+       }
+
+       pid_str = (char *)bundle_get_val(obj->b, APP_PID);
+       if (!pid_str) {
+               _E("Failed to get app pid");
+               return -ENOENT;
+       }
+
+       pid = atoi(pid_str);
+       ret = app_manager_get_app_id(pid, &name);
+       if (ret != APP_MANAGER_ERROR_NONE) {
+               _E("Failed to get app name(%d)", ret);
+               return -ENOENT;
+       }
+
+       text = _("\"%s\" is using too much battery power. Close \"%s\" ?");
+
+       snprintf(content, len, text, name, name);
+       free(name);
+
+       return 0;
+}
+
+static void power_lock_expired_allow_app(const struct popup_ops *ops)
+{
+       _I("Allow is selected");
+
+       unload_simple_popup(ops);
+
+       send_result_dbus_signal(ALLOW_APP);
+
+       terminate_if_no_popup();
+}
+
+static void power_lock_expired_close_app(const struct popup_ops *ops)
+{
+       _I("Close is selected");
+
+       unload_simple_popup(ops);
+
+       send_result_dbus_signal(CLOSE_APP);
+
+       terminate_if_no_popup();
+}
+
+static void power_lock_expired_terminate(const struct popup_ops *ops)
+{
+       send_result_dbus_signal(CLOSE_APP);
+       signal_broadcasted = false;
+}
+
+static const struct popup_ops power_lock_expired_ops = {
+       .name                   = "power_lock_expired",
+       .show                   = load_simple_popup,
+       .get_content    = power_lock_expired_get_content,
+       .left_text              = "IDS_COM_SK_CANCEL",
+       .left                   = power_lock_expired_allow_app,
+       .right_text             = "IDS_COM_SK_OK",
+       .right                  = power_lock_expired_close_app,
+       .terminate              = power_lock_expired_terminate,
+};
+
+/* Constructor to register Power popup */
+static __attribute__ ((constructor)) void power_register_popup(void)
+{
+       register_popup(&power_lock_expired_ops);
+}