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:
authorAlex Zolotarev <deathbaba@gmail.com>2012-01-07 02:51:43 +0400
committerAlex Zolotarev <alex@maps.me>2015-09-23 01:31:24 +0300
commit7d9b25d33da63f2b3dc9316d969cd91f48c7dc9b (patch)
tree2510ac3db8a3a0a2537e1fd1bdcf2b6d9e076d4a
parent3932615f2a7e4539b06b8426028067ca92974776 (diff)
[android] Added dynamical support for external/internal tmp dir when it's available
-rw-r--r--android/jni/com/mapswithme/maps/MWMActivity.cpp6
-rw-r--r--android/jni/com/mapswithme/platform/Platform.cpp16
-rw-r--r--android/jni/com/mapswithme/platform/Platform.hpp9
-rw-r--r--android/src/com/mapswithme/maps/MWMActivity.java28
4 files changed, 41 insertions, 18 deletions
diff --git a/android/jni/com/mapswithme/maps/MWMActivity.cpp b/android/jni/com/mapswithme/maps/MWMActivity.cpp
index 4c8b3e5b21..4db63b086b 100644
--- a/android/jni/com/mapswithme/maps/MWMActivity.cpp
+++ b/android/jni/com/mapswithme/maps/MWMActivity.cpp
@@ -37,12 +37,12 @@ extern "C"
JNIEXPORT void JNICALL
Java_com_mapswithme_maps_MWMActivity_nativeInit(JNIEnv * env, jobject thiz,
- jstring apkPath, jstring storagePath, jstring tmpPath, jstring settingsPath)
+ jstring apkPath, jstring storagePath, jstring tmpPath, jstring extTmpPath, jstring settingsPath)
{
if (!g_framework)
{
android::Platform::Instance().Initialize(env, apkPath, storagePath,
- tmpPath, settingsPath);
+ tmpPath, extTmpPath, settingsPath);
g_framework = new android::Framework(g_jvm);
}
}
@@ -103,12 +103,14 @@ extern "C"
JNIEXPORT void JNICALL
Java_com_mapswithme_maps_MWMActivity_nativeStorageConnected(JNIEnv * env, jobject thiz)
{
+ android::Platform::Instance().OnExternalStorageStatusChanged(true);
g_framework->AddLocalMaps();
}
JNIEXPORT void JNICALL
Java_com_mapswithme_maps_MWMActivity_nativeStorageDisconnected(JNIEnv * env, jobject thiz)
{
+ android::Platform::Instance().OnExternalStorageStatusChanged(false);
g_framework->RemoveLocalMaps();
}
diff --git a/android/jni/com/mapswithme/platform/Platform.cpp b/android/jni/com/mapswithme/platform/Platform.cpp
index 193eb7f36b..7fb32450f8 100644
--- a/android/jni/com/mapswithme/platform/Platform.cpp
+++ b/android/jni/com/mapswithme/platform/Platform.cpp
@@ -7,17 +7,29 @@
namespace android
{
void Platform::Initialize(JNIEnv * env, jstring apkPath, jstring storagePath,
- jstring tmpPath, jstring settingsPath)
+ jstring tmpPath, jstring extTmpPath, jstring settingsPath)
{
m_resourcesDir = jni::ToString(env, apkPath);
m_writableDir = jni::ToString(env, storagePath);
- m_tmpDir = jni::ToString(env, tmpPath);
m_settingsDir = jni::ToString(env, settingsPath);
+ m_localTmpPath = jni::ToString(env, tmpPath);
+ m_externalTmpPath = jni::ToString(env, extTmpPath);
+ // By default use external temporary folder
+ m_tmpDir = m_externalTmpPath;
+
LOG(LDEBUG, ("Apk path = ", m_resourcesDir));
LOG(LDEBUG, ("Writable path = ", m_writableDir));
}
+ void Platform::OnExternalStorageStatusChanged(bool isAvailable)
+ {
+ if (isAvailable)
+ m_tmpDir = m_externalTmpPath;
+ else
+ m_tmpDir = m_localTmpPath;
+ }
+
Platform & Platform::Instance()
{
static Platform platform;
diff --git a/android/jni/com/mapswithme/platform/Platform.hpp b/android/jni/com/mapswithme/platform/Platform.hpp
index 3070fd0d7c..2480f40b96 100644
--- a/android/jni/com/mapswithme/platform/Platform.hpp
+++ b/android/jni/com/mapswithme/platform/Platform.hpp
@@ -8,9 +8,16 @@ namespace android
{
class Platform : public ::Platform
{
+ /// External storage path for temporary files, used when external storage is available
+ string m_externalTmpPath;
+ /// The same but in device's internal memory (it's usually much smaller)
+ string m_localTmpPath;
+
public:
void Initialize(JNIEnv * env, jstring apkPath, jstring storagePath,
- jstring tmpPath, jstring settingsPath);
+ jstring tmpPath, jstring extTmpPath, jstring settingsPath);
+
+ void OnExternalStorageStatusChanged(bool isAvailable);
static Platform & Instance();
};
diff --git a/android/src/com/mapswithme/maps/MWMActivity.java b/android/src/com/mapswithme/maps/MWMActivity.java
index 86cb9df54a..8b2729c2da 100644
--- a/android/src/com/mapswithme/maps/MWMActivity.java
+++ b/android/src/com/mapswithme/maps/MWMActivity.java
@@ -51,12 +51,12 @@ public class MWMActivity extends NvEventQueueActivity implements
return "";
}
- private String getDataStoragePath()
+ private String getDataStoragePath(String folder)
{
final String storagePath = Environment.getExternalStorageDirectory().getAbsolutePath();
- return storagePath.concat(String.format("/Android/data/%s/files/", PACKAGE_NAME));
+ return storagePath.concat(String.format("/Android/data/%s/%s/", PACKAGE_NAME, folder));
}
-
+ // Note: local storage memory is limited on some devices!
private String getTmpPath()
{
return getCacheDir().getAbsolutePath() + "/";
@@ -161,12 +161,13 @@ public class MWMActivity extends NvEventQueueActivity implements
m_context = this;
- final String storagePath = getDataStoragePath();
- // create folder if it doesn't exist
- final File f = new File(storagePath);
- f.mkdirs();
+ final String extStoragePath = getDataStoragePath("files");
+ final String extTmpPath = getDataStoragePath("caches");
+ // create folders if they don't exist
+ new File(extStoragePath).mkdirs();
+ new File(extTmpPath).mkdirs();
- nativeInit(getAppBundlePath(), storagePath, getTmpPath(), getSettingsPath());
+ nativeInit(getAppBundlePath(), extStoragePath, getTmpPath(), extTmpPath, getSettingsPath());
setupLanguages();
@@ -287,8 +288,6 @@ public class MWMActivity extends NvEventQueueActivity implements
private void handleExternalStorageState(boolean available, boolean writeable)
{
- Log.d("COUNTRY", "USB State changed:" + available + " " + writeable);
-
if (available && writeable)
{ // Add local maps to the model
nativeStorageConnected();
@@ -296,14 +295,16 @@ public class MWMActivity extends NvEventQueueActivity implements
findViewById(R.id.map_button_download).setVisibility(View.VISIBLE);
if (m_storageDisconnectedDialog != null)
m_storageDisconnectedDialog.dismiss();
- } else if (available)
+ }
+ else if (available)
{ // Add local maps to the model
nativeStorageConnected();
// disable downloader button and dismiss blocking popup
findViewById(R.id.map_button_download).setVisibility(View.INVISIBLE);
if (m_storageDisconnectedDialog != null)
m_storageDisconnectedDialog.dismiss();
- } else
+ }
+ else
{ // Remove local maps from the model
nativeStorageDisconnected();
// enable downloader button and show blocking popup
@@ -361,7 +362,8 @@ public class MWMActivity extends NvEventQueueActivity implements
private native void nativeStorageConnected();
private native void nativeStorageDisconnected();
- private native void nativeInit(String apkPath, String storagePath, String tmpPath, String settingsPath);
+ private native void nativeInit(String apkPath, String storagePath,
+ String tmpPath, String extTmpPath, String settingsPath);
private native void nativeLocationStatusChanged(int newStatus);
private native void nativeLocationUpdated(long time, double lat, double lon, float accuracy);
private native void nativeCompassUpdated(long time, double magneticNorth, double trueNorth, float accuracy);