Add ui-gadget install tool 85/45985/3 accepted/tizen/mobile/20150814.112852 accepted/tizen/tv/20150814.113012 accepted/tizen/wearable/20150814.112930 submit/tizen/20150814.080020
authorSangyoon Jang <s89.jang@samsung.com>
Thu, 13 Aug 2015 02:42:40 +0000 (11:42 +0900)
committerSangyoon Jang <s89.jang@samsung.com>
Thu, 13 Aug 2015 04:57:58 +0000 (13:57 +0900)
add ui-gadget install tool
add filter prop for ui-gadget on pkg_info

Change-Id: I18a85e35b046b5fb4d0c1c466ddc2ea9fd8c4864
Signed-off-by: Sangyoon Jang <s89.jang@samsung.com>
packaging/pkgmgr.spec
tool/CMakeLists.txt
tool/pkg_info.c
tool/pkg_initdb.c
tool/pkg_install_ug.c [new file with mode: 0644]

index 35022a9..1518148 100644 (file)
@@ -172,6 +172,7 @@ chsmack -a '*' %{TZ_SYS_RW_PACKAGES}
 %{_bindir}/pkg_getsize
 %{_bindir}/pkg_clearcache
 %{_bindir}/pkg_privilege
+%{_bindir}/pkg_install_ug
 %{_bindir}/pkginfo
 %{_datadir}/mime/packages/mime.wac.xml
 %{_datadir}/mime/packages/mime.tpk.xml
index 0a4c0ee..a438096 100644 (file)
@@ -39,6 +39,11 @@ add_executable(pkg_privilege
 target_link_libraries(pkg_privilege ${pkgs_test_LDFLAGS})
 INSTALL(TARGETS pkg_privilege DESTINATION bin)
 
+add_executable(pkg_install_ug
+                pkg_install_ug.c)
+target_link_libraries(pkg_install_ug ${pkgs_test_LDFLAGS})
+INSTALL(TARGETS pkg_install_ug DESTINATION bin)
+
 add_executable(pkg_getsize
                 pkg_getsize.c)
 target_link_libraries(pkg_getsize pkgmgr-client pkgmgr_installer ${pkgs_test_LDFLAGS})
index f4d6c2e..d4120f8 100644 (file)
@@ -415,6 +415,7 @@ static int __add_app_filter(uid_t uid)
                printf("15 --> filter by app taskmanage [0|1]\n");
                printf("16 --> filter by app hwacceleration\n");
                printf("17 --> filter by app screenreader\n");
+               printf("18 --> filter by app ui_gadget [0|1]\n");
                choice = __get_integer_input_data();
                switch (choice) {
                case 0:
@@ -619,6 +620,16 @@ static int __add_app_filter(uid_t uid)
                        free(value);
                        value = NULL;
                        break;
+               case 18:
+                       val = __get_integer_input_data();
+                       ret = pkgmgrinfo_appinfo_filter_add_bool(handle,
+                                       PMINFO_APPINFO_PROP_APP_UI_GADGET, val);
+                       if (ret < 0) {
+                               printf("pkgmgrinfo_appinfo_filter_add_bool() failed\n");
+                               ret = -1;
+                               goto err;
+                       }
+                       break;
                default:
                        printf("Invalid filter property\n");
                                pkgmgrinfo_appinfo_filter_destroy(handle);
index 137e72a..70253c9 100644 (file)
 #endif
 #define _D(fmt, arg...) fprintf(stderr, "[PKG_INITDB][D][%s,%d] "fmt"\n", __FUNCTION__, __LINE__, ##arg);
 
+#define PKGINFO_CMD "/usr/bin/pkginfo --imd"
+#define PKGINSTALLUG_CMD "/usr/bin/pkg_install_ug"
+#define PKGPRIVILEGE_CMD "/usr/bin/pkg_privilege -i"
+
 static int _is_global(uid_t uid)
 {
        return (uid == OWNER_ROOT || uid == GLOBAL_USER) ? 1 : 0;
 }
 
-static int _initdb_load_directory(uid_t uid, const char *directory, const char *cmd)
+static int _initdb_load_directory(uid_t uid, const char *directory)
 {
        DIR *dir;
        struct dirent entry, *result;
@@ -64,7 +68,6 @@ static int _initdb_load_directory(uid_t uid, const char *directory, const char *
        char buf[BUFSZE];
        char buf2[BUFSZE];
 
-       // desktop file
        dir = opendir(directory);
        if (!dir) {
                _E("Failed to access the [%s] because %s", directory,
@@ -90,8 +93,12 @@ static int _initdb_load_directory(uid_t uid, const char *directory, const char *
                        continue;
                }
 
-               snprintf(buf2, sizeof(buf2), "%s %s", cmd, buf);
                setresuid(uid, uid, OWNER_ROOT);
+               snprintf(buf2, sizeof(buf2), "%s %s", PKGINFO_CMD, buf);
+               system(buf2);
+               snprintf(buf2, sizeof(buf2), "%s %s", PKGINSTALLUG_CMD, buf);
+               system(buf2);
+               snprintf(buf2, sizeof(buf2), "%s %s", PKGPRIVILEGE_CMD, buf);
                system(buf2);
                setresuid(OWNER_ROOT, OWNER_ROOT, OWNER_ROOT);
        }
@@ -101,41 +108,6 @@ static int _initdb_load_directory(uid_t uid, const char *directory, const char *
        return 0;
 }
 
-static int _install_manifest(uid_t uid)
-{
-       int ret;
-       const char *dir;
-
-       if (!_is_global(uid)) {
-               tzplatform_set_user(uid);
-       }
-
-       dir = tzplatform_getenv(
-                       _is_global(uid) ? TZ_SYS_RW_PACKAGES : TZ_USER_PACKAGES);
-       ret = _initdb_load_directory(uid, dir, "/usr/bin/pkginfo --imd");
-
-       tzplatform_reset_user();
-
-       return ret;
-}
-
-static int _install_privilege(uid_t uid)
-{
-       int ret;
-       const char *dir;
-
-       if (!_is_global(uid))
-               tzplatform_set_user(uid);
-
-       dir = tzplatform_getenv(
-                       _is_global(uid) ? TZ_SYS_RW_PACKAGES : TZ_USER_PACKAGES);
-       ret = _initdb_load_directory(uid, dir, "/usr/bin/pkg_privilege -i");
-
-       tzplatform_reset_user();
-
-       return ret;
-}
-
 static int _is_authorized()
 {
        /* pkg_init db should be called by as root privilege. */
@@ -185,6 +157,7 @@ static void _remove_old_dbs(uid)
 int main(int argc, char *argv[])
 {
        int ret;
+       const char *dir;
        uid_t uid = 0;
 
        if (!_is_authorized()) {
@@ -203,17 +176,11 @@ int main(int argc, char *argv[])
                return -1;
        }
 
-       ret = _install_manifest(uid);
-       if (ret < 0) {
-               _E("cannot install manifest");
-               return -1;
-       }
-
-       ret = _install_privilege(uid);
-       if (ret < 0) {
-               _E("cannot install priveilge");
-               return -1;
-       }
+       if (!_is_global(uid))
+               tzplatform_set_user(uid);
+       dir = tzplatform_getenv(
+                       _is_global(uid) ? TZ_SYS_RW_PACKAGES : TZ_USER_PACKAGES);
+       tzplatform_reset_user();
 
-       return 0;
+       return _initdb_load_directory(uid, dir);
 }
diff --git a/tool/pkg_install_ug.c b/tool/pkg_install_ug.c
new file mode 100644 (file)
index 0000000..63c0b4e
--- /dev/null
@@ -0,0 +1,65 @@
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include <unistd.h>
+#include <sys/types.h>
+
+#include <pkgmgr_parser.h>
+#include <tzplatform_config.h>
+
+#define OWNER_ROOT 0
+#define GLOBAL_USER tzplatform_getuid(TZ_SYS_GLOBALAPP_USER)
+#define UG_CLIENT tzplatform_mkpath(TZ_SYS_BIN, "ug-client")
+
+static int _install_ug(const char *manifest)
+{
+       manifest_x *mfx;
+       uiapplication_x *tmp;
+       const char *exec;
+       int ret;
+
+       mfx = pkgmgr_parser_process_manifest_xml(manifest);
+       if (mfx == NULL) {
+               printf("Parse manifest failed\n");
+               return -1;
+       }
+
+       for (tmp = mfx->uiapplication; tmp; tmp = tmp->next) {
+               if (tmp->exec == NULL || tmp->ui_gadget == NULL ||
+                               strcasecmp(tmp->ui_gadget, "true") != 0)
+                       continue;
+
+               ret = symlink(UG_CLIENT, tmp->exec);
+               if (ret != 0)
+                       printf("failed to install ug %s: %s\n", tmp->exec,
+                                       strerror(errno));
+       }
+
+       pkgmgr_parser_free_manifest_xml(mfx);
+
+       return 0;
+}
+
+static void _print_usage(const char *cmd)
+{
+       printf("usage: %s <manifest>\n", cmd);
+}
+
+int main(int argc, char *argv[])
+{
+       int ret;
+
+       if (getuid() != OWNER_ROOT && getuid() != GLOBAL_USER) {
+               printf("Only root or tizenglobalapp user is allowed\n");
+               return -1;
+       }
+
+       if (argc < 2) {
+               _print_usage(argv[0]);
+               return -1;
+       }
+
+       ret = _install_ug(argv[1]);
+
+       return ret;
+}