Use private dbus connection for synchronous calls.
[platform/core/system/libstorage.git] / src / storage-inhouse.c
index 1d89af4..ef71f98 100755 (executable)
@@ -24,6 +24,7 @@
 #include <tzplatform_config.h>
 #include <blkid.h>
 #include <libsyscommon/libgdbus.h>
+#include <libsyscommon/common.h>
 
 #include "common.h"
 #include "log.h"
@@ -32,6 +33,7 @@
 
 #define FORMAT_TIMEOUT (120*1000)
 #define USER_PARTITION "user"
+#define CONTAINER_USER_PARTITION "contain-user"
 
 /*
        Get compat path from origin Multi-user path
@@ -174,12 +176,22 @@ API int storage_get_primary_sdcard(int *storage_id, char **path)
        if (!storage_ext_is_supported())
                return STORAGE_ERROR_NOT_SUPPORTED;
 
-       ret_dbus = gdbus_call_sync_with_reply(STORAGE_EXT_BUS_NAME,
+       dbus_handle_h dbus_handle = gdbus_get_connection(G_BUS_TYPE_SYSTEM, true);
+       if (dbus_handle == NULL) {
+               _E("Failed to get dbus connection");
+               return STORAGE_ERROR_OPERATION_FAILED;
+       }
+
+       ret_dbus = gdbus_priv_call_sync_with_reply(dbus_handle,
+                       STORAGE_EXT_BUS_NAME,
                        STORAGE_EXT_PATH_MANAGER,
                        STORAGE_EXT_IFACE_MANAGER,
                        "GetMmcPrimary",
                        NULL,
                        &reply);
+
+       gdbus_free_connection(dbus_handle);
+
        if (ret_dbus < 0) {
                //LCOV_EXCL_START System Error
                _E("Failed to get primary sdcard partition"); //LCOV_EXCL_LINE
@@ -454,10 +466,12 @@ API int storage_is_mounted_opt_usr(storage_part_mount_e *mounted)
        blkid_dev dev;
        int ret_val;
        bool found = false;
+       char *user_label = libsys_is_container()? CONTAINER_USER_PARTITION: USER_PARTITION;
 
        if (!mounted)
                return STORAGE_ERROR_INVALID_PARAMETER;
 
+       _D("Find user partition label: %s", user_label);
        ret_val = blkid_get_cache(&cache, NULL);
        if (ret_val < 0) {
                _E("Failed to get cache"); //LCOV_EXCL_LINE
@@ -479,12 +493,12 @@ API int storage_is_mounted_opt_usr(storage_part_mount_e *mounted)
                return STORAGE_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
        }
 
-       ret_val = blkid_dev_set_search(iter, "LABEL", USER_PARTITION);
+       ret_val = blkid_dev_set_search(iter, "LABEL", user_label);
        if (blkid_dev_next(iter, &dev) == 0) {
                dev = blkid_verify(cache, dev);
                if (dev) {
                        found = true;
-                       _D("Partition for user data is found(LABEL=user)");
+                       _D("Partition for user data is found(LABEL=%s)", user_label);
                }
        }
        blkid_dev_iterate_end(iter);
@@ -497,12 +511,12 @@ API int storage_is_mounted_opt_usr(storage_part_mount_e *mounted)
                        return STORAGE_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
                }
 
-               ret_val = blkid_dev_set_search(iter, "PARTLABEL", USER_PARTITION);
+               ret_val = blkid_dev_set_search(iter, "PARTLABEL", user_label);
                if (blkid_dev_next(iter, &dev) == 0) {
                        dev = blkid_verify(cache, dev);
                        if (dev) {
                                found = true;
-                               _D("Partition for user data is found(PARTLABEL=user)");
+                               _D("Partition for user data is found(PARTLABEL=%s)", user_label);
                        }
                }
                blkid_dev_iterate_end(iter);