From: Anton Obzhirov Date: Wed, 5 Feb 2020 15:21:17 +0000 (+0000) Subject: Add handling double slash in Android assets path. X-Git-Tag: dali_1.5.0~2^2 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-adaptor.git;a=commitdiff_plain;h=d2d21f017aa8fb2ecb3ba9250a17e63978348dea Add handling double slash in Android assets path. Also add extra cleanup code in Android framework. Change-Id: I022ee6c4aac4b8b027b900c2740570ca6d97367d --- diff --git a/dali/internal/adaptor-framework/android/file-loader-impl-android.cpp b/dali/internal/adaptor-framework/android/file-loader-impl-android.cpp index 7e065cd..c35e70f 100644 --- a/dali/internal/adaptor-framework/android/file-loader-impl-android.cpp +++ b/dali/internal/adaptor-framework/android/file-loader-impl-android.cpp @@ -43,6 +43,24 @@ int ReadFile(const std::string& filename, Dali::Vector& memblock, Dali::Fi return Dali::Internal::Adaptor::ReadFile( filename, size, memblock, fileType); } +inline bool hasPrefix(const std::string& prefix, const std::string& path) +{ + return std::mismatch(prefix.begin(), prefix.end(), path.begin()).first == prefix.end(); +} + +inline std::string ConvertToAssetsInternalPath(const std::string& path, int offset) +{ + std::string internalPath = std::string(path.c_str() + offset); + + int i = 0; + while ((i = internalPath.find("//", i)) != std::string::npos) + { + internalPath.replace(i, 2, "/"); + } + + return internalPath; +} + int ReadFile(const std::string& filename, std::streampos& fileSize, Dali::Vector& memblock, Dali::FileLoader::FileType fileType) { int errorCode = 0; @@ -58,12 +76,12 @@ int ReadFile(const std::string& filename, std::streampos& fileSize, Dali::Vector return errorCode; } - const char* path = filename.c_str(); - const int assetsOffset = ( sizeof("assets/") - sizeof( char ) ) / sizeof( char ); - if( !strncmp( path, "assets/", assetsOffset ) ) + const std::string assetsPrefix = "assets/"; + if( hasPrefix( assetsPrefix, filename ) ) { + std::string internalPath = ConvertToAssetsInternalPath( filename, assetsPrefix.length() ); AAssetManager* assetManager = Dali::Integration::AndroidFramework::Get().GetApplicationAssets(); - AAsset* asset = AAssetManager_open( assetManager, path + assetsOffset, AASSET_MODE_BUFFER ); + AAsset* asset = AAssetManager_open( assetManager, internalPath.c_str(), AASSET_MODE_BUFFER ); if( asset ) { length = AAsset_getLength( asset ); @@ -77,12 +95,12 @@ int ReadFile(const std::string& filename, std::streampos& fileSize, Dali::Vector } else { - DALI_LOG_ERROR( "Asset not found %s\n", path ); + DALI_LOG_ERROR( "Asset not found %s\n", internalPath.c_str() ); } } else { - FILE* file = fopen( path, mode ); + FILE* file = fopen( filename.c_str(), mode ); if( file ) { fseek( file, 0, SEEK_END ); @@ -98,7 +116,7 @@ int ReadFile(const std::string& filename, std::streampos& fileSize, Dali::Vector } else { - DALI_LOG_ERROR( "File not found %s\n", path ); + DALI_LOG_ERROR( "File not found %s\n", filename.c_str() ); } } @@ -109,12 +127,12 @@ std::streampos GetFileSize(const std::string& filename) { std::streampos size = 0; - const char* path = filename.c_str(); - const int assetsOffset = ( sizeof("assets/") - sizeof( char ) ) / sizeof( char ); - if( !strncmp( path, "assets/", assetsOffset ) ) + const std::string assetsPrefix = "assets/"; + if( hasPrefix( assetsPrefix, filename ) ) { + std::string internalPath = ConvertToAssetsInternalPath( filename, assetsPrefix.length() ); AAssetManager* assetManager = Dali::Integration::AndroidFramework::Get().GetApplicationAssets(); - AAsset* asset = AAssetManager_open( assetManager, path + assetsOffset, AASSET_MODE_BUFFER ); + AAsset* asset = AAssetManager_open( assetManager, internalPath.c_str(), AASSET_MODE_BUFFER ); if( asset ) { size = AAsset_getLength( asset ); @@ -122,12 +140,12 @@ std::streampos GetFileSize(const std::string& filename) } else { - DALI_LOG_ERROR( "Asset not found %s\n", path ); + DALI_LOG_ERROR( "Asset not found %s\n", internalPath.c_str() ); } } else { - FILE* file = fopen( path, "r" ); + FILE* file = fopen( filename.c_str(), "r" ); if( file ) { fseek( file, 0, SEEK_END ); @@ -136,7 +154,7 @@ std::streampos GetFileSize(const std::string& filename) } else { - DALI_LOG_ERROR( "File not found %s\n", path ); + DALI_LOG_ERROR( "File not found %s\n", filename.c_str() ); } } diff --git a/dali/internal/adaptor/android/framework-android.cpp b/dali/internal/adaptor/android/framework-android.cpp index 8e222fe..741f76c 100644 --- a/dali/internal/adaptor/android/framework-android.cpp +++ b/dali/internal/adaptor/android/framework-android.cpp @@ -551,6 +551,14 @@ void Framework::Run() } } + while (!mImpl->mIdleCallbacks.empty()) + { + mImpl->mIdleCallbacks.pop(); + } + + mImpl->mRemovedIdleCallbacks.clear(); + mImpl->mIdleId = 0; + ALooper_removeFd( app->looper, idlePipe[0] ); if ( mImpl ) {