Avoid calling storage API
authorWoongsuk Cho <ws77.cho@samsung.com>
Wed, 4 May 2022 01:41:04 +0000 (10:41 +0900)
committer조웅석/Common Platform Lab(SR)/삼성전자 <ws77.cho@samsung.com>
Thu, 26 May 2022 05:35:46 +0000 (14:35 +0900)
The storage API is used to get direcoty of SpecialFolder
In special case (like target booting up time), some delay can occur inside the API.

So, to avoid that kind of delay, set SpecialFolder with environment variable if that is set.

NativeLauncher/launcher/lib/core_runtime.cc

index c2fca03..2f1d7d6 100644 (file)
@@ -154,36 +154,38 @@ static bool storage_cb(int id, storage_type_e type, storage_state_e state, const
        return true;
 }
 
-static void initEnvForSpecialFolder()
+static void setSpecialFolder(storage_directory_e type, const char* key)
 {
-       int storageId;
        int error;
-       char *path = NULL;
+       char* path = NULL;
+       static int __storageId = -1;
 
-       error = storage_foreach_device_supported(storage_cb, &storageId);
-       if (error != STORAGE_ERROR_NONE) {
-               return;
+       if (__storageId < 0) {
+               error = storage_foreach_device_supported(storage_cb, &__storageId);
+               if (error != STORAGE_ERROR_NONE) {
+                       return;
+               }
        }
 
-       error = storage_get_directory(storageId, STORAGE_DIRECTORY_IMAGES, &path);
+       error = storage_get_directory(__storageId, type, &path);
        if (error == STORAGE_ERROR_NONE && path != NULL) {
-               setenv("XDG_PICTURES_DIR", const_cast<char *>(path), 1);
+               setenv(key, const_cast<char *>(path), 1);
                free(path);
-               path = NULL;
        }
+}
 
-       error = storage_get_directory(storageId, STORAGE_DIRECTORY_MUSIC, &path);
-       if (error == STORAGE_ERROR_NONE && path != NULL) {
-               setenv("XDG_MUSIC_DIR", const_cast<char *>(path), 1);
-               free(path);
-               path = NULL;
+static void initEnvForSpecialFolder()
+{
+       if (getenv("XDG_PICTURES_DIR") == NULL) {
+               setSpecialFolder(STORAGE_DIRECTORY_IMAGES, "XDG_PICTURES_DIR");
        }
 
-       error = storage_get_directory(storageId, STORAGE_DIRECTORY_VIDEOS, &path);
-       if (error == STORAGE_ERROR_NONE && path != NULL) {
-               setenv("XDG_VIDEOS_DIR", const_cast<char *>(path), 1);
-               free(path);
-               path = NULL;
+       if (getenv("XDG_MUSIC_DIR") == NULL) {
+               setSpecialFolder(STORAGE_DIRECTORY_MUSIC, "XDG_MUSIC_DIR");
+       }
+
+       if (getenv("XDG_VIDEOS_DIR") == NULL) {
+               setSpecialFolder(STORAGE_DIRECTORY_VIDEOS, "XDG_VIDEOS_DIR");
        }
 }