implement app screen reader
authorjunsuk77.oh <junsuk77.oh@samsung.com>
Wed, 3 Jul 2013 01:55:26 +0000 (10:55 +0900)
committerjunsuk77.oh <junsuk77.oh@samsung.com>
Wed, 3 Jul 2013 01:55:26 +0000 (10:55 +0900)
Change-Id: I736f6135f37dbaf103e51e3c5cf61462ec529f32
Signed-off-by: junsuk77.oh <junsuk77.oh@samsung.com>
packaging/pkgmgr.spec
pkgmgr.manifest
pkgmgr.patch.sh.in
tool/CMakeLists.txt
tool/pkg_fota.c [new file with mode: 0644]
tool/pkg_info.c
tool/pkg_initdb.c
tool/pkg_smack.c [new file with mode: 0644]

index 8747314..16a030a 100755 (executable)
@@ -1,7 +1,7 @@
 #sbs-git:slp/pkgs/s/slp-pkgmgr pkgmgr 0.1.103 29b53909a5d6e8728429f0a188177eac691cb6ce
 Name:       pkgmgr
 Summary:    Packager Manager client library package
-Version:    0.2.100
+Version:    0.2.103
 Release:    1
 Group:      System/Libraries
 License:    Apache License, Version 2.0
@@ -111,8 +111,13 @@ vconftool set -t int memory/pkgmgr/status "0" -f -i -s system::vconf -g 5000
 # Update mime database to support package mime types
 update-mime-database /usr/share/mime
 
+%posttrans
+#init DB
 mkdir -p /usr/share/applications
 mkdir -p /opt/dbspace/
+
+pkg_smack
+
 chsmack -a 'pkgmgr::db' /opt/dbspace/.pkgmgr_parser.db*
 chsmack -a 'pkgmgr::db' /opt/dbspace/.pkgmgr_cert.db*
 chsmack -a 'ail::db' /opt/dbspace/.app_info.db*
@@ -136,6 +141,8 @@ mkdir -p /usr/etc/package-manager/server
 %defattr(-,root,root,-)
 %{_bindir}/pkgcmd
 %{_bindir}/pkg_initdb
+%{_bindir}/pkg_smack
+%{_bindir}/pkg_fota
 %{_bindir}/pkg_getsize
 %{_bindir}/pkginfo
 %{_bindir}/pkgmgr-install
index 1a215c2..c33781f 100755 (executable)
@@ -20,6 +20,8 @@
                <domain name="pkgmgr"/>
        </request>
        <assign>
+               <filesystem path="/usr/bin/pkg_smack" exec_label="pkgmgr"/>
+               <filesystem path="/usr/bin/pkg_fota" exec_label="pkgmgr"/>
                <filesystem path="/usr/bin/pkg_initdb" exec_label="pkgmgr"/>
                <filesystem path="/usr/bin/pkgcmd" exec_label="pkgmgr"/>
                <filesystem path="/usr/bin/pkginfo" exec_label="pkgmgr"/>
index 93558e5..8f2fc9f 100644 (file)
@@ -8,5 +8,5 @@ echo "Update package database..............."
 echo "--------------------------------------"
 /bin/rm /opt/dbspace/.pkgmgr_parser.db
 /bin/rm /opt/dbspace/.pkgmgr_parser.db-journal
-/usr/bin/pkg_initdb
+/usr/bin/pkg_fota
 /usr/bin/ail_initdb
index d06ed5a..f13acac 100755 (executable)
@@ -22,6 +22,12 @@ SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
 SET(CMAKE_C_FLAGS_DEBUG "-O0 -g")
 SET(CMAKE_C_FLAGS_RELEASE "-O2")
 
+add_executable(pkg_smack
+                pkg_smack.c)
+target_link_libraries(pkg_smack ${pkgs_test_LDFLAGS})
+target_link_libraries(pkg_smack "-ldl")
+INSTALL(TARGETS pkg_smack DESTINATION bin)
+
 add_executable(pkgcmd
                pkg_cmd.c)
 target_link_libraries(pkgcmd pkgmgr-client ${pkgs_test_LDFLAGS})
@@ -42,6 +48,10 @@ add_executable(pkg_initdb
 target_link_libraries(pkg_initdb ${pkgs_test_LDFLAGS})
 INSTALL(TARGETS pkg_initdb DESTINATION bin)
 
+add_executable(pkg_fota
+                pkg_fota.c)
+target_link_libraries(pkg_fota ${pkgs_test_LDFLAGS})
+INSTALL(TARGETS pkg_fota DESTINATION bin)
 
 add_executable(pkgmgr-install pkgmgr-install.c)
 target_link_libraries(pkgmgr-install pkgmgr-client pkgmgr-info ${toolpkgs_LDFLAGS})
diff --git a/tool/pkg_fota.c b/tool/pkg_fota.c
new file mode 100644 (file)
index 0000000..91c2639
--- /dev/null
@@ -0,0 +1,281 @@
+/*
+ * slp-pkgmgr
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>,
+ * Jaeho Lee <jaeho81.lee@samsung.com>, Shobhit Srivastava <shobhit.s@samsung.com>
+ *
+ * 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.
+ *
+ */
+
+#define _GNU_SOURCE
+
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <dirent.h>
+#include <unistd.h>
+#include <sys/stat.h>
+#include <errno.h>
+
+#include "pkgmgr_parser.h"
+
+#define OWNER_ROOT 0
+#define GROUP_MENU 6010
+#define BUFSZE 1024
+#define OPT_MANIFEST_DIRECTORY "/opt/share/packages"
+#define USR_MANIFEST_DIRECTORY "/usr/share/packages"
+#define PACKAGE_INFO_DB_FILE "/opt/dbspace/.pkgmgr_parser.db"
+
+#define PKG_PARSER_DB_FILE "/opt/dbspace/.pkgmgr_parser.db"
+#define PKG_PARSER_DB_FILE_JOURNAL "/opt/dbspace/.pkgmgr_parser.db-journal"
+#define PKG_CERT_DB_FILE "/opt/dbspace/.pkgmgr_cert.db"
+#define PKG_CERT_DB_FILE_JOURNAL "/opt/dbspace/.pkgmgr_cert.db-journal"
+#define PKG_INFO_DB_LABEL "pkgmgr::db"
+
+#ifdef _E
+#undef _E
+#endif
+#define _E(fmt, arg...) fprintf(stderr, "[PKG_INITDB][E][%s,%d] "fmt"\n", __FUNCTION__, __LINE__, ##arg);
+
+#ifdef _D
+#undef _D
+#endif
+#define _D(fmt, arg...) fprintf(stderr, "[PKG_INITDB][D][%s,%d] "fmt"\n", __FUNCTION__, __LINE__, ##arg);
+
+static int pkg_fota_count_package(void)
+{
+       int total = 0;
+
+       return total;
+}
+
+static int pkg_fota_xsystem(const char *argv[])
+{
+       int status = 0;
+       pid_t pid;
+       pid = fork();
+       switch (pid) {
+       case -1:
+               perror("fork failed");
+               return -1;
+       case 0:
+               /* child */
+               execvp(argv[0], (char *const *)argv);
+               _exit(-1);
+       default:
+               /* parent */
+               break;
+       }
+       if (waitpid(pid, &status, 0) == -1) {
+               perror("waitpid failed");
+               return -1;
+       }
+       if (WIFSIGNALED(status)) {
+               perror("signal");
+               return -1;
+       }
+       if (!WIFEXITED(status)) {
+               /* shouldn't happen */
+               perror("should not happen");
+               return -1;
+       }
+       return WEXITSTATUS(status);
+}
+
+
+char* _manifest_to_package(const char* manifest)
+{
+       char *package;
+
+       if(manifest == NULL)
+               return NULL;
+
+       package = strdup(manifest);
+       if(package == NULL)
+               return NULL;
+
+
+       if (!strstr(package, ".xml")) {
+               _E("%s is not a manifest file", manifest);
+               free(package);
+               return NULL;
+       }
+
+       return package;
+}
+
+
+
+int pkg_fota_load_directory(const char *directory)
+{
+       DIR *dir;
+       struct dirent entry, *result;
+       int ret;
+       char buf[BUFSZE];
+
+       // desktop file
+       dir = opendir(directory);
+       if (!dir) {
+               if (strerror_r(errno, buf, sizeof(buf)) == 0)
+                       _E("Failed to access the [%s] because %s\n", directory, buf);
+               return -1;
+       }
+
+       _D("Loading manifest files from %s\n", directory);
+
+       for (ret = readdir_r(dir, &entry, &result);
+                       ret == 0 && result != NULL;
+                       ret = readdir_r(dir, &entry, &result)) {
+               char *manifest;
+
+               if (entry.d_name[0] == '.') continue;
+
+               manifest = _manifest_to_package(entry.d_name);
+               if (!manifest) {
+                       _E("Failed to convert file to package[%s]\n", entry.d_name);
+                       continue;
+               }
+
+               snprintf(buf, sizeof(buf), "%s/%s", directory, manifest);
+
+               fprintf(stderr, "pkg_initdb : manifest file %s\n", buf);
+
+               ret = pkgmgr_parser_check_manifest_validation(buf);
+               if (ret < 0) {
+                       _E("check manifest validation failed code[%d] %s\n", ret, buf);
+                       fprintf(stderr, "check manifest validation failed code[%d] %s\n", ret, buf);
+                       free(manifest);
+                       continue;
+               }
+
+
+               /*temporarily fixed due to glib abort */
+               // pkgmgr_parser_parse_manifest_for_installation(buf, NULL);
+
+               char buf2[BUFSZE];
+               snprintf(buf2, sizeof(buf2), "/usr/bin/pkginfo --imd %s", buf);
+               system(buf2);
+
+               free(manifest);
+       }
+
+       closedir(dir);
+
+       return 0;
+}
+
+
+
+static int pkg_fota_change_perm(const char *db_file)
+{
+       char buf[BUFSZE];
+       char journal_file[BUFSZE];
+       char *files[3];
+       int ret, i;
+
+       files[0] = (char *)db_file;
+       files[1] = journal_file;
+       files[2] = NULL;
+
+       if(db_file == NULL)
+               return -1;
+
+       snprintf(journal_file, sizeof(journal_file), "%s%s", db_file, "-journal");
+
+       for (i = 0; files[i]; i++) {
+               ret = chown(files[i], OWNER_ROOT, GROUP_MENU);
+               if (ret == -1) {
+                       strerror_r(errno, buf, sizeof(buf));
+                       _E("FAIL : chown %s %d.%d, because %s", db_file, OWNER_ROOT, GROUP_MENU, buf);
+                       return -1;
+               }
+
+               ret = chmod(files[i], S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH);
+               if (ret == -1) {
+                       strerror_r(errno, buf, sizeof(buf));
+                       _E("FAIL : chmod %s 0664, because %s", db_file, buf);
+                       return -1;
+               }
+       }
+
+       return 0;
+}
+
+static int pkg_fota_give_smack()
+{
+       const char *argv_parser[] = { "/usr/bin/chsmack", "-a", PKG_INFO_DB_LABEL, PKG_PARSER_DB_FILE, NULL };
+       pkg_fota_xsystem(argv_parser);
+       const char *argv_parserjn[] = { "/usr/bin/chsmack", "-a", PKG_INFO_DB_LABEL, PKG_PARSER_DB_FILE_JOURNAL, NULL };
+       pkg_fota_xsystem(argv_parserjn);
+       const char *argv_cert[] = { "/usr/bin/chsmack", "-a", PKG_INFO_DB_LABEL, PKG_CERT_DB_FILE, NULL };
+       pkg_fota_xsystem(argv_cert);
+       const char *argv_certjn[] = { "/usr/bin/chsmack", "-a", PKG_INFO_DB_LABEL, PKG_CERT_DB_FILE_JOURNAL, NULL };
+       pkg_fota_xsystem(argv_certjn);
+
+}
+static int __is_authorized()
+{
+       /* pkg_init db should be called by as root privilege. */
+
+       uid_t uid = getuid();
+       if ((uid_t) 0 == uid)
+               return 1;
+       else
+               return 0;
+}
+
+
+int main(int argc, char *argv[])
+{
+       int ret;
+
+       if (!__is_authorized()) {
+               _E("You are not an authorized user!\n");
+               return -1;
+       }
+
+       /* This is for AIL initializing */
+       ret = setenv("INITDB", "1", 1);
+       _D("INITDB : %d", ret);
+
+       ret = pkg_fota_count_package();
+       if (ret > 0) {
+               _D("Some Packages in the Package Info DB.");
+               return 0;
+       }
+
+       ret = pkg_fota_load_directory(OPT_MANIFEST_DIRECTORY);
+       if (ret == -1) {
+               _E("cannot load opt manifest directory.");
+       }
+
+       ret = pkg_fota_load_directory(USR_MANIFEST_DIRECTORY);
+       if (ret == -1) {
+               _E("cannot load usr manifest directory.");
+       }
+
+       ret = pkg_fota_change_perm(PACKAGE_INFO_DB_FILE);
+       if (ret == -1) {
+               _E("cannot chown.");
+               return -1;
+       }
+
+       pkg_fota_give_smack();
+
+       return 0;
+}
+
+
index a19ede8..5749b01 100755 (executable)
@@ -182,6 +182,7 @@ static void __print_arg_filter_usage()
        printf("14 --> filter by app autorestart [0|1]\n");
        printf("15 --> filter by app taskmanage [0|1]\n");
        printf("16 --> filter by app hwacceleration\n");
+       printf("17 --> filter by app screenreader\n");
        printf("=========================================\n");
 }
 
@@ -271,6 +272,7 @@ static int __add_app_filter()
                printf("14 --> filter by app autorestart [0|1]\n");
                printf("15 --> filter by app taskmanage [0|1]\n");
                printf("16 --> filter by app hwacceleration\n");
+               printf("17 --> filter by app screenreader\n");
                choice = __get_integer_input_data();
                switch (choice) {
                case 0:
@@ -460,6 +462,18 @@ static int __add_app_filter()
                        free(value);
                        value = NULL;
                        break;
+               case 17:
+                       value = __get_string_input_data();
+                       ret = pkgmgrinfo_appinfo_filter_add_string(handle,
+                               PMINFO_APPINFO_PROP_APP_SCREENREADER, value);
+                       if (ret < 0) {
+                               printf("pkgmgrinfo_appinfo_filter_add_bool() failed\n");
+                               ret = -1;
+                               goto err;
+                       }
+                       free(value);
+                       value = NULL;
+                       break;
                default:
                        printf("Invalid filter property\n");
                                pkgmgrinfo_appinfo_filter_destroy(handle);
@@ -843,6 +857,15 @@ static int __add_arg_filter(char *key, char *value)
                        goto err;
                }
                break;
+       case 17:
+               ret = pkgmgrinfo_appinfo_filter_add_string(handle, PMINFO_APPINFO_PROP_APP_SCREENREADER, value);
+               if (ret < 0) {
+                       printf("pkgmgrinfo_appinfo_filter_add_bool() failed\n");
+                       ret = -1;
+                       goto err;
+               }
+               break;
+
        default:
                __print_arg_filter_usage();
                goto err;
@@ -1425,6 +1448,7 @@ int app_func(const pkgmgr_appinfo_h handle, void *user_data)
        bool multiple = 0;
        bool taskmanage = 0;
        pkgmgr_hwacceleration_type hwacceleration;
+       pkgmgrinfo_app_screenreader screenreader;
        bool onboot = 0;
        bool autorestart = 0;
        char *package = NULL;
@@ -1506,6 +1530,13 @@ int app_func(const pkgmgr_appinfo_h handle, void *user_data)
                        printf("hw-acceleration: %d\n", hwacceleration);
                }
 
+               ret = pkgmgrinfo_appinfo_get_screenreader(handle, &screenreader);
+               if (ret < 0) {
+                       printf("Failed to get screenreader\n");
+               } else {
+                       printf("screenreader: %d\n", screenreader);
+               }
+
        }
        if (component == PM_SVC_APP) {
                printf("component: svcapp\n");
@@ -1950,6 +1981,7 @@ static int __get_app_info(char *appid)
        bool multiple = 0;
        bool taskmanage = 0;
        pkgmgr_hwacceleration_type hwacceleration;
+       pkgmgrinfo_app_screenreader screenreader;
        bool onboot = 0;
        bool autorestart = 0;
        bool enabled = 0;
@@ -2010,6 +2042,10 @@ static int __get_app_info(char *appid)
        if (ret < 0) {
                printf("Failed to get hwacceleration\n");
        }
+       ret = pkgmgrinfo_appinfo_get_screenreader(handle, &screenreader);
+       if (ret < 0) {
+               printf("Failed to get screenreader\n");
+       }
        ret = pkgmgr_appinfo_is_onboot(handle, &onboot);
        if (ret < 0) {
                printf("Failed to get onboot\n");
@@ -2050,6 +2086,7 @@ static int __get_app_info(char *appid)
                printf("Multiple: %d\n", multiple);
                printf("Taskmanage: %d\n", taskmanage);
                printf("Hw-Acceleration: %d\n", hwacceleration);
+               printf("Screenreader: %d\n", screenreader);
        } else if (component == PM_SVC_APP) {
                printf("component: svcapp\n");
 
index f738806..88a0036 100755 (executable)
@@ -117,8 +117,6 @@ char* _manifest_to_package(const char* manifest)
        return package;
 }
 
-
-
 int initdb_load_directory(const char *directory)
 {
        DIR *dir;
diff --git a/tool/pkg_smack.c b/tool/pkg_smack.c
new file mode 100644 (file)
index 0000000..7fe3073
--- /dev/null
@@ -0,0 +1,445 @@
+/*
+ * slp-pkgmgr
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>,
+ * Jaeho Lee <jaeho81.lee@samsung.com>, Shobhit Srivastava <shobhit.s@samsung.com>
+ *
+ * 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.
+ *
+ */
+
+#define _GNU_SOURCE
+
+#include <unistd.h>
+#include <stdio.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdbool.h>
+#include <dlfcn.h>
+#include <sys/stat.h>
+
+#include <pkgmgr-info.h>
+
+static int __pkg_list_cb (const pkgmgrinfo_pkginfo_h handle, void *user_data);
+
+
+#ifdef _E
+#undef _E
+#endif
+#define _E(fmt, arg...) fprintf(stderr, "[PKG_SMACK][E][%s,%d] "fmt"\n", __FUNCTION__, __LINE__, ##arg);
+
+#ifdef _D
+#undef _D
+#endif
+#define _D(fmt, arg...) fprintf(stderr, "[PKG_SMACK][D][%s,%d] "fmt"\n", __FUNCTION__, __LINE__, ##arg);
+
+#define LIB_PRIVILEGE_CONTROL          "libprivilege-control.so.0"
+#define LIB_SMACK                                      "libsmack.so.1"
+
+#define BUFF_SIZE                      256
+#define APP_OWNER_ID           5000
+#define APP_GROUP_ID           5000
+
+enum rpm_path_type {
+       RPM_PATH_PRIVATE,
+       RPM_PATH_GROUP_RW,
+       RPM_PATH_PUBLIC_RO,
+       RPM_PATH_SETTINGS_RW,
+       RPM_PATH_ANY_LABEL
+};
+
+static int __is_dir(char *dirname)
+{
+       struct stat stFileInfo;
+       stat(dirname, &stFileInfo);
+       if (S_ISDIR(stFileInfo.st_mode)) {
+               return 1;
+       }
+       return 0;
+}
+
+int __pkg_smack_register_package(const char *pkgid)
+{
+       int ret = 0;
+       void *handle = NULL;
+       char *errmsg = NULL;
+       int (*app_install)(const char*) = NULL;
+
+       if (pkgid == NULL)
+               return -1;
+
+       handle = dlopen(LIB_PRIVILEGE_CONTROL, RTLD_LAZY | RTLD_GLOBAL);
+       if (!handle) {
+               _E( "register package: dlopen() failed. [%s]", dlerror());
+               return -1;
+       }
+
+       app_install = dlsym(handle, "app_install");
+       errmsg = dlerror();
+       if ((errmsg != NULL) || (app_install == NULL)) {
+               _E( "register package: dlsym() failed. [%s]", errmsg);
+               dlclose(handle);
+               return -1;
+       }
+
+       _E( "[smack] app_install(%s)", pkgid);
+       ret = app_install(pkgid);
+       _E( "[smack] app_install(%s), result = [%d]", pkgid, ret);
+
+       dlclose(handle);
+       return ret;
+}
+
+int __pkg_smack_unregister_package(const char *pkgid)
+{
+       int ret = 0;
+       void *handle = NULL;
+       char *errmsg = NULL;
+       int (*app_uninstall)(const char*) = NULL;
+
+       if (pkgid == NULL)
+               return -1;
+
+       handle = dlopen(LIB_PRIVILEGE_CONTROL, RTLD_LAZY | RTLD_GLOBAL);
+       if (!handle) {
+               _E( "unregister package: dlopen() failed. [%s]", dlerror());
+               return -1;
+       }
+
+       app_uninstall = dlsym(handle, "app_uninstall");
+       errmsg = dlerror();
+       if ((errmsg != NULL) || (app_uninstall == NULL)) {
+               _E( "unregister package: dlsym() failed. [%s]", errmsg);
+               dlclose(handle);
+               return -1;
+       }
+
+       _E( "[smack] app_uninstall(%s)", pkgid);
+       ret = app_uninstall(pkgid);
+       _E( "[smack] app_uninstall(%s), result = [%d]", pkgid, ret);
+
+       dlclose(handle);
+       return ret;
+}
+
+int __pkg_smack_revoke_permissions(const char *pkgid)
+{
+       int ret = 0;
+       void *handle = NULL;
+       char *errmsg = NULL;
+       int (*app_revoke_permissions)(const char*) = NULL;
+
+       if (pkgid == NULL)
+               return -1;
+
+       handle = dlopen(LIB_PRIVILEGE_CONTROL, RTLD_LAZY | RTLD_GLOBAL);
+       if (!handle) {
+               _E( "revoke permissions: dlopen() failed. [%s][%s]", pkgid, dlerror());
+               return -1;
+       }
+
+       app_revoke_permissions = dlsym(handle, "app_revoke_permissions");
+       errmsg = dlerror();
+       if ((errmsg != NULL) || (app_revoke_permissions == NULL)) {
+               _E( "revoke permissions(): dlsym() failed. [%s][%s]", pkgid, errmsg);
+               dlclose(handle);
+               return -1;
+       }
+
+       _E( "[smack] app_revoke_permissions(%s)", pkgid);
+       ret = app_revoke_permissions(pkgid);
+       _E( "[smack] app_revoke_permissions(%s), result = [%d]", pkgid, ret);
+
+       dlclose(handle);
+       return ret;
+}
+
+int __pkg_smack_enable_permissions(const char *pkgid, int apptype,
+                                               const char **perms, int persistent)
+{
+       int ret = 0;
+       void *handle = NULL;
+       char *errmsg = NULL;
+       int (*app_enable_permissions)(const char*, int, const char**, bool) = NULL;
+
+       if (pkgid == NULL)
+               return -1;
+
+       handle = dlopen(LIB_PRIVILEGE_CONTROL, RTLD_LAZY | RTLD_GLOBAL);
+       if (!handle) {
+               _E( "enable permissions(): dlopen() failed. [%s]", dlerror());
+               return -1;
+       }
+
+       app_enable_permissions = dlsym(handle, "app_enable_permissions");
+       errmsg = dlerror();
+       if ((errmsg != NULL) || (app_enable_permissions == NULL)) {
+               _E( "enable permissions(): dlsym() failed. [%s]", errmsg);
+               dlclose(handle);
+               return -1;
+       }
+
+       _E( "[smack] app_enable_permissions(%s, %d)", pkgid, apptype);
+       ret = app_enable_permissions(pkgid, apptype, perms, persistent);
+       _E( "[smack] app_enable_permissions(%s, %d), result = [%d]", pkgid, apptype, ret);
+
+       dlclose(handle);
+       return ret;
+}
+
+int __pkg_smack_setup_path(const char *pkgid, const char *dirpath,
+                                               int apppathtype, const char *groupid)
+{
+       int ret = 0;
+       void *handle = NULL;
+       char *errmsg = NULL;
+       int (*app_setup_path)(const char*, const char*, int, ...) = NULL;
+
+       if (pkgid == NULL || dirpath == NULL)
+               return -1;
+
+       handle = dlopen(LIB_PRIVILEGE_CONTROL, RTLD_LAZY | RTLD_GLOBAL);
+       if (!handle) {
+               _E( "setup path: dlopen() failed. [%s]", dlerror());
+               return -1;
+       }
+
+       app_setup_path = dlsym(handle, "app_setup_path");
+       errmsg = dlerror();
+       if ((errmsg != NULL) || (app_setup_path == NULL)) {
+               _E( "setup path: dlsym() failed. [%s]", errmsg);
+               dlclose(handle);
+               return -1;
+       }
+
+       if (groupid == NULL) {
+               _E( "[smack] app_setup_path(%s, %s, %d)", pkgid, dirpath, apppathtype);
+               ret = app_setup_path(pkgid, dirpath, apppathtype);
+               _E( "[smack] app_setup_path(), result = [%d]", ret);
+       } else {
+               _E( "[smack] app_setup_path(%s, %s, %d, %s)", pkgid, dirpath, apppathtype, groupid);
+               ret = app_setup_path(pkgid, dirpath, apppathtype, groupid);
+               _E( "[smack] app_setup_path(), result = [%d]", ret);
+       }
+
+       dlclose(handle);
+       return ret;
+}
+
+int __pkg_smack_add_friend(const char *pkgid1, const char *pkgid2)
+{
+       int ret = 0;
+       void *handle = NULL;
+       char *errmsg = NULL;
+       int (*app_add_friend)(const char*, const char*) = NULL;
+
+       if (pkgid1 == NULL || pkgid2 == NULL)
+               return -1;
+
+       handle = dlopen(LIB_PRIVILEGE_CONTROL, RTLD_LAZY | RTLD_GLOBAL);
+       if (!handle) {
+               _E( "add friend: dlopen() failed. [%s]", dlerror());
+               return -1;
+       }
+
+       app_add_friend = dlsym(handle, "app_add_friend");
+       errmsg = dlerror();
+       if ((errmsg != NULL) || (app_add_friend == NULL)) {
+               _E( "add friend: dlsym() failed. [%s]", errmsg);
+               dlclose(handle);
+               return -1;
+       }
+
+       _E( "[smack] app_add_friend(%s, %s)", pkgid1, pkgid2);
+       ret = app_add_friend(pkgid1, pkgid2);
+       _E( "[smack] app_add_friend(%s, %s), result = [%d]", pkgid1, pkgid2, ret);
+
+       dlclose(handle);
+       return ret;
+}
+
+int __pkg_smack_change_smack_label(const char *path, const char *label,
+                                               int label_type)
+{
+       if (path == NULL || label == NULL)
+               return -1;
+       int ret = 0;
+       void *handle = NULL;
+       char *errmsg = NULL;
+       int (*smack_lsetlabel)(const char*, const char*, int) = NULL;
+
+       handle = dlopen(LIB_SMACK, RTLD_LAZY | RTLD_GLOBAL);
+       if (!handle) {
+               _E( "change smack label: dlopen() failed. [%s]", dlerror());
+               return -1;
+       }
+
+       smack_lsetlabel = dlsym(handle, "smack_lsetlabel");
+       errmsg = dlerror();
+       if ((errmsg != NULL) || (smack_lsetlabel == NULL)) {
+               _E( "change smack label: dlsym() failed. [%s]", errmsg);
+               dlclose(handle);
+               return -1;
+       }
+
+       _E( "[smack] smack_lsetlabel(%s, %s, %d)", path, label, label_type);
+       ret = smack_lsetlabel(path, label, label_type);
+       _E( "[smack] smack_lsetlabel(%s, %s, %d), result = [%d]", path, label, label_type, ret);
+
+       dlclose(handle);
+       return ret;
+}
+
+static void __apply_shared_privileges(char *pkgname, int flag)
+{
+       char dirpath[BUFF_SIZE] = {'\0'};
+       /*execute privilege APIs. The APIs should not fail*/
+       __pkg_smack_register_package(pkgname);
+
+#if 0
+       /*home dir. Dont setup path but change smack access to "_" */
+       snprintf(dirpath, BUFF_SIZE, "/usr/apps/%s", pkgname);
+       if (__is_dir(dirpath))
+               __pkg_smack_change_smack_label(dirpath, "_", 0);/*0 is SMACK_LABEL_ACCESS*/
+       memset(dirpath, '\0', BUFF_SIZE);
+       snprintf(dirpath, BUFF_SIZE, "/opt/usr/apps/%s", pkgname);
+       if (__is_dir(dirpath))
+               __pkg_smack_change_smack_label(dirpath, "_", 0);/*0 is SMACK_LABEL_ACCESS*/
+       memset(dirpath, '\0', BUFF_SIZE);
+
+       /*/shared dir. Dont setup path but change smack access to "_" */
+       snprintf(dirpath, BUFF_SIZE, "/usr/apps/%s/shared", pkgname);
+       if (__is_dir(dirpath))
+               __pkg_smack_change_smack_label(dirpath, "_", 0);/*0 is SMACK_LABEL_ACCESS*/
+       memset(dirpath, '\0', BUFF_SIZE);
+       snprintf(dirpath, BUFF_SIZE, "/opt/usr/apps/%s/shared", pkgname);
+       if (__is_dir(dirpath))
+               __pkg_smack_change_smack_label(dirpath, "_", 0);/*0 is SMACK_LABEL_ACCESS*/
+       memset(dirpath, '\0', BUFF_SIZE);
+
+       /*/shared/res dir. setup path */
+       if (flag == 0)
+               snprintf(dirpath, BUFF_SIZE, "/usr/apps/%s/shared/res", pkgname);
+       else
+               snprintf(dirpath, BUFF_SIZE, "/opt/usr/apps/%s/shared/res", pkgname);
+       if (__is_dir(dirpath))
+               __pkg_smack_setup_path(pkgname, dirpath, RPM_PATH_PUBLIC_RO, NULL);
+       memset(dirpath, '\0', BUFF_SIZE);
+
+       /*/shared/data dir. setup path and change group to 'app'*/
+       if (flag == 0)
+               snprintf(dirpath, BUFF_SIZE, "/usr/apps/%s/shared/data", pkgname);
+       else
+               snprintf(dirpath, BUFF_SIZE, "/opt/usr/apps/%s/shared/data", pkgname);
+       if (__is_dir(dirpath)) {
+               chown(dirpath, APP_OWNER_ID, APP_GROUP_ID);
+               __pkg_smack_setup_path(pkgname, dirpath, RPM_PATH_PUBLIC_RO, NULL);
+       } else {
+               memset(dirpath, '\0', BUFF_SIZE);
+               if (flag == 0)
+                       snprintf(dirpath, BUFF_SIZE, "/opt/usr/apps/%s/shared/data", pkgname);
+               else
+                       snprintf(dirpath, BUFF_SIZE, "/usr/apps/%s/shared/data", pkgname);
+               if (__is_dir(dirpath))
+                       chown(dirpath, APP_OWNER_ID, APP_GROUP_ID);
+                       __pkg_smack_setup_path(pkgname, dirpath, RPM_PATH_PUBLIC_RO, NULL);
+       }
+#endif
+}
+
+static int __is_authorized()
+{
+       /* pkg_init db should be called by as root privilege. */
+
+       uid_t uid = getuid();
+       if ((uid_t) 0 == uid)
+               return 1;
+       else
+               return 0;
+}
+
+static int __pkg_list_cb (const pkgmgrinfo_pkginfo_h handle, void *user_data)
+{
+       int ret = -1;
+       char *pkgid = NULL;
+
+       ret = pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid);
+       if(ret < 0) {
+               printf("pkgmgrinfo_pkginfo_get_pkgid() failed\n");
+       }
+
+       __apply_shared_privileges(pkgid, 0);
+
+       return 0;
+}
+
+static int __additional_rpm_for_smack()
+{
+       char *pkgid = "ui-gadget::client";
+
+       __apply_shared_privileges(pkgid, 0);
+       return 0;
+}
+
+static int __find_rpm_for_smack()
+{
+       int ret = 0;
+       pkgmgrinfo_pkginfo_filter_h handle = NULL;
+
+       ret = pkgmgrinfo_pkginfo_filter_create(&handle);
+       if (ret > 0) {
+               printf("pkginfo filter handle create failed\n");
+               return -1;
+       }
+
+       ret = pkgmgrinfo_pkginfo_filter_add_string(handle,
+               PMINFO_PKGINFO_PROP_PACKAGE_TYPE, "rpm");
+       if (ret < 0) {
+               printf("pkgmgrinfo_pkginfo_filter_add_string() failed\n");
+               ret = -1;
+       }
+
+       ret = pkgmgrinfo_pkginfo_filter_foreach_pkginfo(handle, __pkg_list_cb, NULL);
+       if (ret < 0) {
+               printf("pkgmgrinfo_pkginfo_filter_foreach_pkginfo() failed\n");
+               ret = -1;
+       }
+
+       pkgmgrinfo_pkginfo_filter_destroy(handle);
+       return ret;
+}
+
+int main(int argc, char *argv[])
+{
+       int ret = 0;
+
+       if (!__is_authorized()) {
+               _E("You are not an authorized user!\n");
+               return -1;
+       }
+
+       ret = __find_rpm_for_smack();
+       if (ret < 0)
+               printf("__find_rpm_for_smack() failed\n");
+
+       ret = __additional_rpm_for_smack();
+       if (ret < 0)
+               printf("__additional_rpm_for_smack() failed\n");
+
+       return 0;
+}
+
+