forked from organicmaps/organicmaps
[android] Fix bug with correct storage path for downloading.
This commit is contained in:
parent
106b0b5816
commit
7fca6a746e
8 changed files with 28 additions and 15 deletions
|
@ -82,4 +82,10 @@ extern "C"
|
|||
bool flag = val;
|
||||
(void)Settings::Set(jni::ToNativeString(env, name), flag);
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_com_mapswithme_maps_MWMApplication_hasFreeSpace(JNIEnv * env, jobject thiz, jlong size)
|
||||
{
|
||||
return android::Platform::Instance().HasAvailableSpaceForWriting(size);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -92,8 +92,7 @@ namespace android
|
|||
// It stores path to current maps storage.
|
||||
m_settingsDir = jni::ToNativeString(env, storagePath);
|
||||
|
||||
if (!Settings::Get("StoragePath", m_writableDir) ||
|
||||
(GetWritableStorageStatus(1024) != ::Platform::STORAGE_OK))
|
||||
if (!Settings::Get("StoragePath", m_writableDir) || !HasAvailableSpaceForWriting(1024))
|
||||
{
|
||||
// If no saved storage path or the storage is unavailable
|
||||
// (disconnected from the last session), assign writable
|
||||
|
@ -123,7 +122,7 @@ namespace android
|
|||
m_tmpDir = m_localTmpPath;
|
||||
}
|
||||
|
||||
string Platform::GetStoragePathPrefix()
|
||||
string Platform::GetStoragePathPrefix() const
|
||||
{
|
||||
size_t const count = m_writableDir.size();
|
||||
ASSERT_GREATER ( count, 2, () );
|
||||
|
@ -140,6 +139,11 @@ namespace android
|
|||
Settings::Set("StoragePath", m_writableDir);
|
||||
}
|
||||
|
||||
bool Platform::HasAvailableSpaceForWriting(uint64_t size) const
|
||||
{
|
||||
return (GetWritableStorageStatus(size) == ::Platform::STORAGE_OK);
|
||||
}
|
||||
|
||||
Platform & Platform::Instance()
|
||||
{
|
||||
static Platform platform;
|
||||
|
|
|
@ -27,10 +27,12 @@ namespace android
|
|||
void OnExternalStorageStatusChanged(bool isAvailable);
|
||||
|
||||
/// get storage path without ending "/MapsWithMe/"
|
||||
string GetStoragePathPrefix();
|
||||
string GetStoragePathPrefix() const;
|
||||
/// assign storage path (should contain ending "/MapsWithMe/")
|
||||
void SetStoragePath(string const & path);
|
||||
|
||||
bool HasAvailableSpaceForWriting(uint64_t size) const;
|
||||
|
||||
static Platform & Instance();
|
||||
};
|
||||
}
|
||||
|
|
|
@ -8,8 +8,6 @@ import android.content.DialogInterface;
|
|||
import android.content.Intent;
|
||||
import android.content.res.Resources;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.os.StatFs;
|
||||
import android.provider.Settings;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
|
@ -128,7 +126,7 @@ public class DownloadUI extends ListActivity implements MapStorage.Listener
|
|||
|
||||
private AlertDialog.Builder m_alert;
|
||||
private DialogInterface.OnClickListener m_alertCancelHandler =
|
||||
new DialogInterface.OnClickListener()
|
||||
new DialogInterface.OnClickListener()
|
||||
{
|
||||
@Override
|
||||
public void onClick(DialogInterface dlg, int which)
|
||||
|
@ -211,10 +209,10 @@ public class DownloadUI extends ListActivity implements MapStorage.Listener
|
|||
.show();
|
||||
}
|
||||
|
||||
static private long getFreeSpace()
|
||||
private boolean hasFreeSpace(long size)
|
||||
{
|
||||
StatFs stat = new StatFs(Environment.getExternalStorageDirectory().getPath());
|
||||
return (long)stat.getAvailableBlocks() * (long)stat.getBlockSize();
|
||||
MWMApplication app = (MWMApplication) m_context.getApplication();
|
||||
return app.hasFreeSpace(size);
|
||||
}
|
||||
|
||||
private void processCountry(int position)
|
||||
|
@ -256,7 +254,7 @@ public class DownloadUI extends ListActivity implements MapStorage.Listener
|
|||
@Override
|
||||
public void onClick(DialogInterface dlg, int which)
|
||||
{
|
||||
if (remoteSize + MB > getFreeSpace())
|
||||
if (!hasFreeSpace(remoteSize + MB))
|
||||
showNotEnoughFreeSpaceDialog(getSizeString(remoteSize), name);
|
||||
else
|
||||
m_storage.downloadCountry(idx);
|
||||
|
@ -281,7 +279,7 @@ public class DownloadUI extends ListActivity implements MapStorage.Listener
|
|||
case MapStorage.NOT_DOWNLOADED:
|
||||
// Check for available free space
|
||||
final long size = m_storage.countryRemoteSizeInBytes(idx);
|
||||
if (size + MB > getFreeSpace())
|
||||
if (!hasFreeSpace(size + MB))
|
||||
{
|
||||
showNotEnoughFreeSpaceDialog(getSizeString(size), name);
|
||||
}
|
||||
|
|
|
@ -153,6 +153,9 @@ public class MWMApplication extends android.app.Application implements MapStorag
|
|||
return storagePath.concat(String.format("/Android/data/%s/%s/", getPackageName(), folder));
|
||||
}
|
||||
|
||||
/// Check if we have free space on storage (writable path).
|
||||
public native boolean hasFreeSpace(long size);
|
||||
|
||||
public boolean isProVersion()
|
||||
{
|
||||
return m_isProVersion;
|
||||
|
|
|
@ -96,7 +96,7 @@ public:
|
|||
STORAGE_DISCONNECTED,
|
||||
NOT_ENOUGH_SPACE
|
||||
};
|
||||
TStorageStatus GetWritableStorageStatus(uint64_t neededSize);
|
||||
TStorageStatus GetWritableStorageStatus(uint64_t neededSize) const;
|
||||
|
||||
/// @name Functions for concurrent tasks.
|
||||
//@{
|
||||
|
|
|
@ -31,7 +31,7 @@ bool Platform::GetFileSizeByFullPath(string const & filePath, uint64_t & size)
|
|||
else return false;
|
||||
}
|
||||
|
||||
Platform::TStorageStatus Platform::GetWritableStorageStatus(uint64_t neededSize)
|
||||
Platform::TStorageStatus Platform::GetWritableStorageStatus(uint64_t neededSize) const
|
||||
{
|
||||
struct statfs st;
|
||||
int const ret = statfs(m_writableDir.c_str(), &st);
|
||||
|
|
|
@ -122,7 +122,7 @@ void Platform::RunAsync(TFunctor const & fn, Priority p)
|
|||
fn();
|
||||
}
|
||||
|
||||
Platform::TStorageStatus Platform::GetWritableStorageStatus(uint64_t neededSize)
|
||||
Platform::TStorageStatus Platform::GetWritableStorageStatus(uint64_t neededSize) const
|
||||
{
|
||||
ULARGE_INTEGER freeSpace;
|
||||
if (0 == ::GetDiskFreeSpaceExA(m_writableDir.c_str(), &freeSpace, NULL, NULL))
|
||||
|
|
Loading…
Add table
Reference in a new issue