Fix getting widget db path 65/253665/1
authorHwankyu Jhun <h.jhun@samsung.com>
Tue, 16 Feb 2021 07:32:08 +0000 (16:32 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Tue, 16 Feb 2021 07:38:13 +0000 (16:38 +0900)
When the user is not a globalapp user, the db path should be created
using TZ_USER_DB.

Change-Id: I256b722cbeb9133cc75e2ce99428ed4018365acf
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
src/widget.c

index 00363cf..441acda 100644 (file)
@@ -26,6 +26,7 @@
 #include <glib.h>
 #include <bundle.h>
 #include <bundle_internal.h>
+#include <tzplatform_config.h>
 
 #include "aul.h"
 #include "aul_api.h"
@@ -667,21 +668,34 @@ API int aul_widget_service_set_disable(const char *widget_id, bool is_disable)
        return ret;
 }
 
+static const char *__get_widget_db_path(uid_t uid)
+{
+#define ROOT_USER 0
+#define GLOBALAPP_USER tzplatform_getuid(TZ_SYS_GLOBALAPP_USER)
+       const char *path;
+
+       if (uid == ROOT_USER || uid == GLOBALAPP_USER) {
+               path = tzplatform_mkpath(TZ_SYS_DB, WIDGET_SERVICE_DB);
+       } else {
+               tzplatform_set_user(uid);
+               path = tzplatform_mkpath(TZ_USER_DB, WIDGET_SERVICE_DB);
+               tzplatform_reset_user();
+       }
+
+       return path;
+}
+
 static sqlite3 *__open_widget_service_db(uid_t uid, bool readonly)
 {
-       sqlite3 *db;
-       char *path;
+       const char *path;
 
-       path = aul_db_get_path(WIDGET_SERVICE_DB, uid);
+       path = __get_widget_db_path(uid);
        if (!path) {
                _E("Failed to get db path");
                return NULL;
        }
 
-       db = aul_db_open(path, readonly);
-       free(path);
-
-       return db;
+       return aul_db_open(path, readonly);
 }
 
 API int aul_widget_service_set_disable_db(const char *widget_id, bool is_disable)