--- /dev/null
+/*
+ * 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);
+}