proc: check application status 61/212361/3
authorByungSoo Kim <bs1770.kim@samsung.com>
Tue, 10 Jan 2017 07:41:41 +0000 (16:41 +0900)
committerMichal Bloch <m.bloch@partner.samsung.com>
Fri, 13 Sep 2019 07:52:57 +0000 (09:52 +0200)
When deviced requests application status,
resourced can identify whether it is normal or malicious.
So, resourced will return good or bad application status to deviced.

Change-Id: I0f0967fc6dc2e50eaaf83771f183999b95adc6fd
Signed-off-by: ByungSoo Kim <bs1770.kim@samsung.com>
src/proc-stat/proc-monitor.c

index fa1e4cc..be3a901 100644 (file)
@@ -52,6 +52,7 @@
 #define WATCHDOG_VALUE_1                       "watchdog"
 
 #define TIZEN_DEBUG_MODE_FILE  RD_SYS_ETC"/.debugmode"
+#define DEFAULT_APPID  "NULL"
 
 #define INIT_PID       1
 #define INIT_PROC_VAL  -1
@@ -180,6 +181,67 @@ static void dbus_pre_poweroff(GDBusMethodInvocation *invocation, GVariant *param
        g_dbus_method_invocation_return_value(invocation, g_variant_new("(i)", -1));
 }
 
+static void dbus_get_checkappstatus(GDBusMethodInvocation *invocation, GVariant *params)
+{
+       int len;
+       int detect = 0;
+       struct proc_app_info *pai;
+       char *appid = DEFAULT_APPID;
+       char *type = NULL;
+       pid_t pid = -1;
+
+       do_expr_unless_g_variant_get_typechecked(goto null_reply, params, "(i&s)", &pid, &type);
+       if (pid < 0 || type == NULL) {
+               _D("there is no message");
+               goto null_reply;
+       }
+
+       pai = find_app_info(pid);
+       if (!pai) {
+               _D("There is no appid %d", pid);
+               goto response;
+       }
+
+       /*
+        * allowed strings: normal, lcddim, lcdoff
+        * normal & lcddim : allow only UI application
+        * lcdoff : allow if it sends the excluding dbus signal
+        */
+       len = strlen(type);
+
+       if (len != 6) {
+               _D("wrong lock type : %s", type);
+               goto response;
+       }
+
+       appid = pai->appid;
+       if (pai->watchdog_exclude || pai->runtime_exclude) {
+               _E("application (%d, %s) used %s lock longly but it is excluded", pid, appid, type);
+               goto response;
+       }
+
+       if (!strncmp(type, "norm", 4) || !strncmp(type, "lcdd", 4)) {
+               if (pai->type == PROC_TYPE_SERVICE || pai->type == PROC_TYPE_READY ||
+                   pai->type == PROC_TYPE_NONE)
+                       detect = 1;
+       } else if (!strncmp(type, "lcdo", 4)) {
+               detect = 1;
+       }
+
+       if (detect)
+               _E("detect application locking %s lock longly : %d, %s", type, pid, appid);
+       else
+               _D("application locking %s lock longly but it seems normal : %d, %s", type, pid, appid);
+
+response:
+       g_dbus_method_invocation_return_value(invocation, g_variant_new("(iis)",
+                               pid, detect, appid));
+       return;
+
+null_reply:
+       D_BUS_REPLY_NULL(invocation);
+}
+
 static void proc_dbus_active_signal_handler(GVariant *params)
 {
        int type;
@@ -1022,6 +1084,13 @@ static const char dbus_methods_xml[] =
 "                      <arg type='ai' name='ProcList' direction='in'/>"
 "                      <arg type='a(ii)' name='CpuUsage' direction='out'/>"
 "              </method>"
+"              <method name='CheckAppStatus'>"
+"                      <arg type='i' name='Pid' direction='in'/>"
+"                      <arg type='s' name='Type' direction='in'/>"
+"                      <arg type='i' name='Pid' direction='out'/>"
+"                      <arg type='i' name='Detect' direction='out'/>"
+"                      <arg type='s' name='Appid' direction='out'/>"
+"              </method>"
 "      </interface>"
 "</node>";
 
@@ -1039,6 +1108,7 @@ static struct d_bus_method dbus_methods[] = {
 /* Following functions are defined in proc-usage-stats.c */
        { "ProcMemoryUsage", dbus_proc_memory_usage },
        { "ProcCpuUsage", dbus_proc_cpu_usage },
+       { "CheckAppStatus", dbus_get_checkappstatus },
        /* Add methods here */
 };