Add inhouse api to get storage type and the kind of external device
[platform/core/system/libstorage.git] / src / storage-inhouse.c
index a8031bb..72eddac 100755 (executable)
@@ -168,3 +168,53 @@ API int storage_get_primary_sdcard(int *storage_id, char **path)
 
        return STORAGE_ERROR_NONE;
 }
+
+API int storage_get_type_dev(int storage_id, storage_type_e *type, storage_dev_e *dev)
+{
+       storage_ext_device *ext_dev;
+       int ret;
+
+       if (storage_id < 0) {
+               _E("Invalid parameger");
+               return STORAGE_ERROR_NOT_SUPPORTED;
+       }
+
+       if (!type) {
+               _E("Invalid parameger");
+               return STORAGE_ERROR_INVALID_PARAMETER;
+       }
+
+       if (!dev) {
+               _E("Invalid parameger");
+               return STORAGE_ERROR_INVALID_PARAMETER;
+       }
+
+       ret = storage_get_type(storage_id, type);
+       if (ret != STORAGE_ERROR_NONE) {
+               _E("Failed to get storage type: %d", ret);
+               return ret;
+       }
+
+       ext_dev = calloc(1, sizeof(storage_ext_device));
+       if (!ext_dev) {
+//LCOV_EXCL_START System Error
+               _E("calloc failed");
+               return STORAGE_ERROR_OUT_OF_MEMORY;
+//LCOV_EXCL_STOP
+       }
+
+       ret = storage_ext_get_device_info(storage_id, ext_dev);
+       if (ret < 0) {
+               _E("Cannot get the storage with id (%d, ret:%d)", storage_id, ret); //LCOV_EXCL_LINE
+               ret = STORAGE_ERROR_NOT_SUPPORTED;
+               goto out;
+       }
+
+       *dev = ext_dev->type;
+       ret = STORAGE_ERROR_NONE;
+       _I("type: %d(internal:0, external:1) dev: %d(sdcard: 1001, usb: 1002)", *type, *dev);
+
+out:
+       storage_ext_release_device(&ext_dev);
+       return ret;
+}