Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorvng <viktor.govako@gmail.com>2013-07-08 18:38:51 +0400
committerAlex Zolotarev <alex@maps.me>2015-09-23 01:58:29 +0300
commit75d58d02582b8058fce2d9b411a33467a9a3967f (patch)
treeadb5a0ea042792ac3f69e99ad4090eaf2c6c113a
parentd2d7828685ff9e9b8c2988c9efc69ed7b6af9923 (diff)
[android] Use alternative zip files for *.ttf and World, WorldCoasts.
-rw-r--r--android/jni/com/mapswithme/maps/DownloadResourcesActivity.cpp39
-rw-r--r--android/jni/com/mapswithme/maps/MWMApplication.cpp20
-rw-r--r--android/jni/com/mapswithme/maps/settings/StoragePathActivity.cpp4
-rw-r--r--android/jni/com/mapswithme/platform/Platform.cpp26
-rw-r--r--android/jni/com/mapswithme/platform/Platform.hpp5
-rw-r--r--android/src/com/mapswithme/maps/MWMApplication.java17
-rw-r--r--coding/zip_reader.cpp5
-rw-r--r--coding/zip_reader.hpp4
-rw-r--r--defines.hpp1
-rw-r--r--map/framework.cpp10
-rw-r--r--platform/platform.cpp29
-rw-r--r--platform/platform.hpp8
-rw-r--r--platform/platform_android.cpp115
13 files changed, 195 insertions, 88 deletions
diff --git a/android/jni/com/mapswithme/maps/DownloadResourcesActivity.cpp b/android/jni/com/mapswithme/maps/DownloadResourcesActivity.cpp
index aa91a6c905..623738a941 100644
--- a/android/jni/com/mapswithme/maps/DownloadResourcesActivity.cpp
+++ b/android/jni/com/mapswithme/maps/DownloadResourcesActivity.cpp
@@ -63,43 +63,26 @@ extern "C"
// Check if we need to download mandatory resource file.
bool NeedToDownload(Platform & pl, string const & name, int size)
{
- uint64_t originSize = 0;
- if (!pl.GetFileSizeByName(name, originSize))
+ try
{
- // no such file
- return true;
- }
-
- if (size == originSize)
- {
- // file is up-to-date
- return false;
- }
+ ModelReaderPtr reader(pl.GetReader(name));
- if (name == WORLD_FILE_NAME DATA_FILE_EXTENSION)
- {
- try
+ if (name == WORLD_FILE_NAME DATA_FILE_EXTENSION)
{
- FilesContainerR cont(pl.GetReader(name));
- if (cont.IsReaderExist(SEARCH_INDEX_FILE_TAG))
+ FilesContainerR cont(reader);
+ if (!cont.IsReaderExist(SEARCH_INDEX_FILE_TAG))
{
- // World.mwm file has search index - can skip new version.
- return false;
+ // World.mwm file doesn't have search index - need to download new one.
+ return true;
}
}
- catch (RootException const &)
- {
- // Some error occurred when loading file.
- return true;
- }
+
+ // file exists - no need to download
+ return false;
}
- else if (name == WORLD_COASTS_FILE_NAME DATA_FILE_EXTENSION)
+ catch (RootException const &)
{
- // Skip WorldCoasts.mwm
- return false;
}
-
- // Do download otherwise.
return true;
}
diff --git a/android/jni/com/mapswithme/maps/MWMApplication.cpp b/android/jni/com/mapswithme/maps/MWMApplication.cpp
index 7ff0c77fbb..0afee794c6 100644
--- a/android/jni/com/mapswithme/maps/MWMApplication.cpp
+++ b/android/jni/com/mapswithme/maps/MWMApplication.cpp
@@ -21,18 +21,13 @@
extern "C"
{
JNIEXPORT void JNICALL
- Java_com_mapswithme_maps_MWMApplication_nativeInit(JNIEnv * env,
- jobject thiz,
- jstring apkPath,
- jstring storagePath,
- jstring tmpPath,
- jboolean isPro)
+ Java_com_mapswithme_maps_MWMApplication_nativeInit(
+ JNIEnv * env, jobject thiz,
+ jstring apkPath, jstring storagePath, jstring tmpPath, jstring obbGooglePath,
+ jboolean isPro)
{
- android::Platform::Instance().Initialize(env,
- apkPath,
- storagePath,
- tmpPath,
- isPro);
+ android::Platform::Instance().Initialize(
+ env, apkPath, storagePath, tmpPath, obbGooglePath, isPro);
LOG(LDEBUG, ("Creating android::Framework instance ..."));
@@ -43,8 +38,7 @@ extern "C"
}
JNIEXPORT jboolean JNICALL
- Java_com_mapswithme_maps_MWMApplication_nativeIsBenchmarking(JNIEnv * env,
- jobject thiz)
+ Java_com_mapswithme_maps_MWMApplication_nativeIsBenchmarking(JNIEnv * env, jobject thiz)
{
return static_cast<jboolean>(g_framework->NativeFramework()->IsBenchmarking());
}
diff --git a/android/jni/com/mapswithme/maps/settings/StoragePathActivity.cpp b/android/jni/com/mapswithme/maps/settings/StoragePathActivity.cpp
index ab904a6389..51dcaeac94 100644
--- a/android/jni/com/mapswithme/maps/settings/StoragePathActivity.cpp
+++ b/android/jni/com/mapswithme/maps/settings/StoragePathActivity.cpp
@@ -29,7 +29,9 @@ extern "C"
Platform & pl = GetPlatform();
// Get regexp like this: (\.mwm$|\.ttf$)
- string const regexp = "(" "\\"DATA_FILE_EXTENSION"$" "|" "\\"BOOKMARKS_FILE_EXTENSION"$" "|" "\\.ttf$" ")";
+ string const regexp = "(" "\\"DATA_FILE_EXTENSION"$" "|"
+ "\\"BOOKMARKS_FILE_EXTENSION"$" "|"
+ "\\"FONT_FILE_EXTENSION"$" ")";
Platform::FilesList files;
pl.GetFilesByRegExp(from, regexp, files);
diff --git a/android/jni/com/mapswithme/platform/Platform.cpp b/android/jni/com/mapswithme/platform/Platform.cpp
index 2bd970a28b..af122e59f9 100644
--- a/android/jni/com/mapswithme/platform/Platform.cpp
+++ b/android/jni/com/mapswithme/platform/Platform.cpp
@@ -3,7 +3,11 @@
#include "../core/jni_helper.hpp"
#include "../../../../../platform/settings.hpp"
+
#include "../../../../../base/logging.hpp"
+#include "../../../../../base/stl_add.hpp"
+
+#include "../../../../../std/algorithm.hpp"
string Platform::UniqueClientId() const
@@ -52,9 +56,8 @@ string Platform::UniqueClientId() const
namespace android
{
void Platform::Initialize(JNIEnv * env,
- jstring apkPath,
- jstring storagePath,
- jstring tmpPath,
+ jstring apkPath, jstring storagePath,
+ jstring tmpPath, jstring obbGooglePath,
bool isPro)
{
m_resourcesDir = jni::ToNativeString(env, apkPath);
@@ -75,10 +78,19 @@ namespace android
m_isPro = isPro;
- LOG(LDEBUG, ("Apk path = ", m_resourcesDir));
- LOG(LDEBUG, ("Writable path = ", m_writableDir));
- LOG(LDEBUG, ("Temporary path = ", m_tmpDir));
- LOG(LDEBUG, ("Settings path = ", m_settingsDir));
+ string const obbPath = jni::ToNativeString(env, obbGooglePath);
+ Platform::FilesList files;
+ GetFilesByExt(obbPath, ".obb", files);
+ m_extResFiles.clear();
+ for (size_t i = 0; i < files.size(); ++i)
+ m_extResFiles.push_back(obbPath + files[i]);
+
+ LOG(LINFO, ("Apk path = ", m_resourcesDir));
+ LOG(LINFO, ("Writable path = ", m_writableDir));
+ LOG(LINFO, ("Temporary path = ", m_tmpDir));
+ LOG(LINFO, ("Settings path = ", m_settingsDir));
+ LOG(LINFO, ("OBB Google path = ", obbPath));
+ LOG(LINFO, ("OBB Google files = ", files));
}
void Platform::OnExternalStorageStatusChanged(bool isAvailable)
diff --git a/android/jni/com/mapswithme/platform/Platform.hpp b/android/jni/com/mapswithme/platform/Platform.hpp
index 355ad0a0b7..6d65b92212 100644
--- a/android/jni/com/mapswithme/platform/Platform.hpp
+++ b/android/jni/com/mapswithme/platform/Platform.hpp
@@ -11,9 +11,8 @@ namespace android
public:
void Initialize(JNIEnv * env,
- jstring apkPath,
- jstring storagePath,
- jstring tmpPath,
+ jstring apkPath, jstring storagePath,
+ jstring tmpPath, jstring obbGooglePath,
bool isPro);
void OnExternalStorageStatusChanged(bool isAvailable);
diff --git a/android/src/com/mapswithme/maps/MWMApplication.java b/android/src/com/mapswithme/maps/MWMApplication.java
index 89a2a1e95a..a2dd3f86af 100644
--- a/android/src/com/mapswithme/maps/MWMApplication.java
+++ b/android/src/com/mapswithme/maps/MWMApplication.java
@@ -126,10 +126,8 @@ public class MWMApplication extends android.app.Application implements MapStorag
new File(extTmpPath).mkdirs();
// init native framework
- nativeInit(getApkPath(),
- extStoragePath,
- extTmpPath,
- m_isProVersion);
+ nativeInit(getApkPath(), extStoragePath, extTmpPath,
+ getOBBGooglePath(), m_isProVersion);
m_slotID = getMapStorage().subscribe(this);
@@ -203,6 +201,12 @@ public class MWMApplication extends android.app.Application implements MapStorag
return storagePath.concat(String.format("/Android/data/%s/%s/", getPackageName(), folder));
}
+ private String getOBBGooglePath()
+ {
+ final String storagePath = Environment.getExternalStorageDirectory().getAbsolutePath();
+ return storagePath.concat(String.format("/Android/obb/%s/", getPackageName()));
+ }
+
/// Check if we have free space on storage (writable path).
public native boolean hasFreeSpace(long size);
@@ -241,9 +245,8 @@ public class MWMApplication extends android.app.Application implements MapStorag
System.loadLibrary("mapswithme");
}
- private native void nativeInit(String apkPath,
- String storagePath,
- String tmpPath,
+ private native void nativeInit(String apkPath, String storagePath,
+ String tmpPath, String obbGooglePath,
boolean isPro);
public native boolean nativeIsBenchmarking();
diff --git a/coding/zip_reader.cpp b/coding/zip_reader.cpp
index ba4aa05db7..ffcca33951 100644
--- a/coding/zip_reader.cpp
+++ b/coding/zip_reader.cpp
@@ -10,8 +10,9 @@
#include "../3party/zlib/contrib/minizip/unzip.h"
-ZipFileReader::ZipFileReader(string const & container, string const & file)
- : FileReader(container), m_uncompressedFileSize(0)
+ZipFileReader::ZipFileReader(string const & container, string const & file,
+ uint32_t logPageSize, uint32_t logPageCount)
+ : FileReader(container, logPageSize, logPageCount), m_uncompressedFileSize(0)
{
unzFile zip = unzOpen64(container.c_str());
if (!zip)
diff --git a/coding/zip_reader.hpp b/coding/zip_reader.hpp
index e85e03ee3f..d4915a9891 100644
--- a/coding/zip_reader.hpp
+++ b/coding/zip_reader.hpp
@@ -21,7 +21,9 @@ public:
DECLARE_EXCEPTION(LocateZipException, OpenException);
DECLARE_EXCEPTION(InvalidZipException, OpenException);
- ZipFileReader(string const & container, string const & file);
+ /// @param[in] logPageSize, logPageCount default values are equal with FileReader constructor.
+ ZipFileReader(string const & container, string const & file,
+ uint32_t logPageSize = 10, uint32_t logPageCount = 4);
/// @note Size() returns compressed file size inside zip
uint64_t UncompressedSize() const { return m_uncompressedFileSize; }
diff --git a/defines.hpp b/defines.hpp
index bfa28febe8..8efc3fa219 100644
--- a/defines.hpp
+++ b/defines.hpp
@@ -2,6 +2,7 @@
#define DATA_FILE_EXTENSION ".mwm"
#define DATA_FILE_EXTENSION_TMP ".mwm.tmp"
+#define FONT_FILE_EXTENSION ".ttf"
#define DATA_FILE_TAG "dat"
#define GEOMETRY_FILE_TAG "geom"
#define TRIANGLE_FILE_TAG "trg"
diff --git a/map/framework.cpp b/map/framework.cpp
index 7b28d7039a..1966e3bad2 100644
--- a/map/framework.cpp
+++ b/map/framework.cpp
@@ -630,6 +630,16 @@ void Framework::GetLocalMaps(vector<string> & outMaps) const
{
Platform & pl = GetPlatform();
pl.GetFilesByExt(pl.WritableDir(), DATA_FILE_EXTENSION, outMaps);
+
+#ifdef OMIM_OS_ANDROID
+ // On Android World and WorldCoasts can be stored in alternative /Android/obb/ path.
+ char const * arrCheck[] = { WORLD_FILE_NAME DATA_FILE_EXTENSION,
+ WORLD_COASTS_FILE_NAME DATA_FILE_EXTENSION };
+
+ for (size_t i = 0; i < ARRAY_SIZE(arrCheck); ++i)
+ if (find(outMaps.begin(), outMaps.end(), arrCheck[i]) == outMaps.end())
+ outMaps.push_back(arrCheck[i]);
+#endif
}
void Framework::PrepareToShutdown()
diff --git a/platform/platform.cpp b/platform/platform.cpp
index a2fcf1bb03..70d5e3bdde 100644
--- a/platform/platform.cpp
+++ b/platform/platform.cpp
@@ -14,9 +14,11 @@ string Platform::ReadPathForFile(string const & file) const
fullPath = m_resourcesDir + file;
if (!IsFileExistsByFullPath(fullPath))
{
- fullPath = file;
- if (!IsFileExistsByFullPath(fullPath))
- MYTHROW(FileAbsentException, ("File doesn't exist", fullPath));
+ // default behaviour - assume that we have full path here
+ if (!IsFileExistsByFullPath(file))
+ MYTHROW(FileAbsentException, ("File doesn't exist", file));
+ else
+ return file;
}
}
return fullPath;
@@ -60,19 +62,22 @@ void Platform::GetFontNames(FilesList & res) const
{
GetSystemFontNames(res);
- // Do not search inside apk for the fonts in Android.
- string const paths[] = {
- WritableDir()
-#ifndef OMIM_OS_ANDROID
- , ResourcesDir()
+ size_t n = 0;
+ string const * arrPaths[4];
+
+ arrPaths[n++] = &m_writableDir;
+#ifdef OMIM_OS_ANDROID
+ for (size_t i = 0; i < m_extResFiles.size(); ++i)
+ arrPaths[n++] = &m_extResFiles[i];
+#else
+ arrPaths[n++] = &m_resourcesDir;
#endif
- };
FilesList fonts;
- for (size_t i = 0; i < ARRAY_SIZE(paths); ++i)
+ for (size_t i = 0; i < n; ++i)
{
- LOG(LDEBUG, ("Searching for fonts in", paths[i]));
- GetFilesByExt(paths[i], ".ttf", fonts);
+ LOG(LDEBUG, ("Searching for fonts in", *(arrPaths[i])));
+ GetFilesByExt(*(arrPaths[i]), FONT_FILE_EXTENSION, fonts);
}
sort(fonts.begin(), fonts.end());
diff --git a/platform/platform.hpp b/platform/platform.hpp
index 89c87ac1d9..5bc1899fa6 100644
--- a/platform/platform.hpp
+++ b/platform/platform.hpp
@@ -29,8 +29,12 @@ protected:
/// Flag that it's a paid PRO version of app.
bool m_isPro;
- /// Internal function to use files from writable dir
- /// if they override the same file in the resources dir
+ /// Extended resource files.
+ /// Used in Android only (downloaded zip files as a container).
+ vector<string> m_extResFiles;
+
+ /// Internal function to get full path for input file.
+ /// Uses m_writeableDir and m_resourcesDir.
string ReadPathForFile(string const & file) const;
/// Hash some unique string into uniform format.
diff --git a/platform/platform_android.cpp b/platform/platform_android.cpp
index f24b22a0ca..c59623f067 100644
--- a/platform/platform_android.cpp
+++ b/platform/platform_android.cpp
@@ -3,12 +3,14 @@
#include "constants.hpp"
#include "../coding/zip_reader.hpp"
+#include "../coding/file_name_utils.hpp"
#include "../base/logging.hpp"
#include "../base/thread.hpp"
#include "../base/regexp.hpp"
+#include "../base/string_utils.hpp"
-#include <unistd.h>
+#include <unistd.h> // for sysconf
Platform::Platform()
@@ -16,26 +18,115 @@ Platform::Platform()
/// @see initialization routine in android/jni/com/.../Platform.hpp
}
-ModelReader * Platform::GetReader(string const & file) const
+namespace
+{
+
+enum SourceT { EXTERNAL_RESOURCE, RESOURCE, WRITABLE_PATH, FULL_PATH };
+
+size_t GetSearchSources(string const & file, SourceT (&arr)[4])
{
- if (IsFileExistsByFullPath(m_writableDir + file))
+ size_t ret = 0;
+ string const ext = my::GetFileExtension(file);
+ ASSERT ( !ext.empty(), () );
+
+ if (ext == DATA_FILE_EXTENSION)
{
- return new FileReader(ReadPathForFile(file),
- READER_CHUNK_LOG_SIZE, READER_CHUNK_LOG_COUNT);
+ if (strings::StartsWith(file, WORLD_COASTS_FILE_NAME) ||
+ strings::StartsWith(file, WORLD_FILE_NAME))
+ {
+ arr[ret++] = EXTERNAL_RESOURCE;
+ }
+ arr[ret++] = WRITABLE_PATH;
}
- if (IsFileExistsByFullPath(file))
+ else if (ext == FONT_FILE_EXTENSION)
{
- return new FileReader(ReadPathForFile(file),
- READER_CHUNK_LOG_SIZE, READER_CHUNK_LOG_COUNT);
+ // system fonts have absolute unix path
+ if (strings::StartsWith(file, "/"))
+ arr[ret++] = FULL_PATH;
+ else
+ {
+ arr[ret++] = EXTERNAL_RESOURCE;
+ arr[ret++] = WRITABLE_PATH;
+ }
}
else
+ arr[ret++] = RESOURCE;
+
+ return ret;
+}
+
+#ifdef DEBUG
+class DbgLogger
+{
+ string const & m_file;
+ SourceT m_src;
+public:
+ DbgLogger(string const & file) : m_file(file) {}
+ void SetSource(SourceT src) { m_src = src; }
+ ~DbgLogger()
{
- ASSERT_EQUAL ( file.find("assets/"), string::npos, () );
+ LOG(LDEBUG, ("Source for file", m_file, "is", m_src));
+ }
+};
+#endif
+
+}
- /// @note If you push some maps to the bundle, it's better to set
- /// better values for chunk size and chunks count. @see constants.hpp
- return new ZipFileReader(m_resourcesDir, "assets/" + file);
+ModelReader * Platform::GetReader(string const & file) const
+{
+ SourceT sources[4];
+ size_t const n = GetSearchSources(file, sources);
+
+#ifdef DEBUG
+ DbgLogger logger(file);
+#endif
+
+ for (size_t i = 0; i < n; ++i)
+ {
+#ifdef DEBUG
+ logger.SetSource(sources[i]);
+#endif
+
+ switch (sources[i])
+ {
+ case EXTERNAL_RESOURCE:
+ {
+ for (size_t j = 0; j < m_extResFiles.size(); ++j)
+ {
+ try
+ {
+ return new ZipFileReader(m_extResFiles[j], file,
+ READER_CHUNK_LOG_SIZE, READER_CHUNK_LOG_COUNT);
+ }
+ catch (Reader::OpenException const &)
+ {
+ }
+ }
+ break;
+ }
+
+ case WRITABLE_PATH:
+ {
+ string const path = m_writableDir + file;
+ if (IsFileExistsByFullPath(path))
+ return new FileReader(path, READER_CHUNK_LOG_SIZE, READER_CHUNK_LOG_COUNT);
+ break;
+ }
+
+ case FULL_PATH:
+ if (IsFileExistsByFullPath(file))
+ return new FileReader(file);
+ break;
+
+ default:
+ ASSERT_EQUAL ( sources[i], RESOURCE, () );
+ ASSERT_EQUAL ( file.find("assets/"), string::npos, () );
+ return new ZipFileReader(m_resourcesDir, "assets/" + file);
+ }
}
+
+ MYTHROW(FileAbsentException, ("File not found", file));
+ return 0;
}
void Platform::GetFilesByRegExp(string const & directory, string const & regexp, FilesList & res)