[android] Improve reliability of map files detection

Signed-off-by: Konstantin Pastbin <konstantin.pastbin@gmail.com>
This commit is contained in:
Konstantin Pastbin 2022-05-29 14:27:35 +03:00 committed by Viktor Govako
parent 3d139bd724
commit 778f7f1c25
3 changed files with 11 additions and 25 deletions

View file

@ -1036,6 +1036,12 @@ Java_com_mapswithme_maps_Framework_nativeGetSettingsDir(JNIEnv * env, jclass)
return jni::ToJavaString(env, GetPlatform().SettingsDir().c_str());
}
JNIEXPORT jstring JNICALL
Java_com_mapswithme_maps_Framework_nativeGetDataFileExt(JNIEnv * env, jclass)
{
return jni::ToJavaString(env, DATA_FILE_EXTENSION);
}
JNIEXPORT jobjectArray JNICALL
Java_com_mapswithme_maps_Framework_nativeGetMovableFilesExts(JNIEnv * env, jclass)
{

View file

@ -212,6 +212,8 @@ public class Framework
public static native void nativeDeactivatePopup();
public static native String nativeGetDataFileExt();
public static native String[] nativeGetMovableFilesExts();
public static native String[] nativeGetBookmarksFilesExts();

View file

@ -32,6 +32,7 @@ public class StoragePathManager
{
static final String TAG = StoragePathManager.class.getName();
private static final Logger LOGGER = LoggerFactory.INSTANCE.getLogger(LoggerFactory.Type.STORAGE);
private static final String DATA_FILE_EXT = Framework.nativeGetDataFileExt();
private static final String[] MOVABLE_EXTS = Framework.nativeGetMovableFilesExts();
static final FilenameFilter MOVABLE_FILES_FILTER = (dir, filename) -> {
for (String ext : MOVABLE_EXTS)
@ -291,34 +292,11 @@ public class StoragePathManager
}
/**
* Determine whether the storage contains map files
* by checking for non-empty directories with version-like names (e.g. "220415").
* Determine whether the storage contains map files.
*/
private static boolean containsMapData(String storagePath)
{
File path = new File(storagePath);
File[] candidates = path.listFiles((pathname) -> {
if (!pathname.isDirectory())
return false;
try
{
String name = pathname.getName();
if (name.length() != 6)
return false;
int version = Integer.valueOf(name);
return (version > 120000 && version <= 999999);
}
catch (NumberFormatException ignored)
{
}
return false;
});
return (candidates != null && candidates.length > 0 &&
candidates[0].list().length > 0);
return StorageUtils.getDirSizeRecursively(new File(storagePath), (dir, filename) -> filename.endsWith(DATA_FILE_EXT)) > 0;
}
/**