forked from organicmaps/organicmaps
[new downloader][android] add: JNI bridge for migration.
This commit is contained in:
parent
44f9e24cd6
commit
a0d693f3c3
4 changed files with 125 additions and 9 deletions
|
@ -409,14 +409,25 @@ UserMark const * Framework::GetActiveUserMark()
|
|||
return m_activeUserMark;
|
||||
}
|
||||
|
||||
bool Framework::HasSpaceForMigration()
|
||||
{
|
||||
return m_work.IsEnoughSpaceForMigrate();
|
||||
}
|
||||
|
||||
bool Framework::NeedMigrate()
|
||||
{
|
||||
return platform::migrate::NeedMigrate();
|
||||
}
|
||||
|
||||
void Framework::Migrate()
|
||||
void Framework::Migrate(bool keepOldMaps)
|
||||
{
|
||||
m_work.Migrate();
|
||||
m_work.Migrate(keepOldMaps);
|
||||
}
|
||||
|
||||
bool Framework::PreMigrate(ms::LatLon const & position, Storage::TChangeCountryFunction const & statusChangeListener,
|
||||
Storage::TProgressFunction const & progressListener)
|
||||
{
|
||||
return m_work.PreMigrate(position, statusChangeListener, progressListener);
|
||||
}
|
||||
|
||||
} // namespace android
|
||||
|
|
|
@ -149,8 +149,11 @@ namespace android
|
|||
void SetActiveUserMark(UserMark const * mark);
|
||||
UserMark const * GetActiveUserMark();
|
||||
|
||||
bool HasSpaceForMigration();
|
||||
bool NeedMigrate();
|
||||
void Migrate();
|
||||
bool PreMigrate(ms::LatLon const & position, storage::Storage::TChangeCountryFunction const & statusChangeListener,
|
||||
storage::Storage::TProgressFunction const & progressListener);
|
||||
void Migrate(bool keepOldMaps);
|
||||
|
||||
private:
|
||||
vector<TDrapeTask> m_drapeTasksQueue;
|
||||
|
|
|
@ -51,6 +51,13 @@ Java_com_mapswithme_maps_MapStorage_nativeMoveFile(JNIEnv * env, jclass clazz, j
|
|||
return my::RenameFileX(jni::ToNativeString(env, oldFile), jni::ToNativeString(env, newFile));
|
||||
}
|
||||
|
||||
// static boolean nativeHasSpaceForMigration();
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_com_mapswithme_maps_downloader_MapManager_nativeHasSpaceForMigration(JNIEnv * env, jclass clazz)
|
||||
{
|
||||
return g_framework->HasSpaceForMigration();
|
||||
}
|
||||
|
||||
// static native boolean nativeIsLegacyMode();
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_com_mapswithme_maps_downloader_MapManager_nativeIsLegacyMode(JNIEnv * env, jclass clazz)
|
||||
|
@ -58,11 +65,86 @@ Java_com_mapswithme_maps_downloader_MapManager_nativeIsLegacyMode(JNIEnv * env,
|
|||
return g_framework->NeedMigrate();
|
||||
}
|
||||
|
||||
// static void nativeMigrate();
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_mapswithme_maps_downloader_MapManager_nativeMigrate(JNIEnv * env, jclass clazz)
|
||||
static void FinishMigration(JNIEnv * env, jobject const listener)
|
||||
{
|
||||
g_framework->Migrate();
|
||||
env->DeleteGlobalRef(listener);
|
||||
}
|
||||
|
||||
static void OnPrefetchComplete(jobject const listener, bool keepOldMaps)
|
||||
{
|
||||
g_framework->Migrate(keepOldMaps);
|
||||
|
||||
JNIEnv * env = jni::GetEnv();
|
||||
jmethodID const callback = jni::GetMethodID(env, listener, "onComplete", "()V");
|
||||
ASSERT(callback, ());
|
||||
env->CallVoidMethod(listener, callback);
|
||||
|
||||
FinishMigration(env, listener);
|
||||
}
|
||||
|
||||
static void OnMigrationError(jobject const listener, NodeErrorCode error)
|
||||
{
|
||||
JNIEnv * env = jni::GetEnv();
|
||||
jmethodID const callback = jni::GetMethodID(env, listener, "onError", "(I)V");
|
||||
ASSERT(callback, ());
|
||||
env->CallVoidMethod(listener, callback, static_cast<jint>(error));
|
||||
|
||||
FinishMigration(env, listener);
|
||||
}
|
||||
|
||||
static void MigrationStatusChangedCallback(jobject const listener, TCountryId const & countryId, bool keepOldMaps)
|
||||
{
|
||||
NodeAttrs attrs;
|
||||
GetStorage().GetPrefetchStorage()->GetNodeAttrs(countryId, attrs);
|
||||
|
||||
switch (attrs.m_status)
|
||||
{
|
||||
case NodeStatus::OnDisk:
|
||||
OnPrefetchComplete(listener, keepOldMaps);
|
||||
break;
|
||||
|
||||
case NodeStatus::Undefined:
|
||||
case NodeStatus::Error:
|
||||
OnMigrationError(listener, attrs.m_error);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void MigrationProgressCallback(jobject const listener, TCountryId const & countryId, TLocalAndRemoteSize const & sizes)
|
||||
{
|
||||
JNIEnv * env = jni::GetEnv();
|
||||
|
||||
jmethodID const callback = jni::GetMethodID(env, listener, "onProgress", "(I)V");
|
||||
env->CallVoidMethod(listener, callback, static_cast<jint>(sizes.first * 100 / sizes.second));
|
||||
}
|
||||
|
||||
// static boolean nativeMigrate(MigrationListener listener, double lat, double lon, boolean hasLocation, boolean keepOldMaps);
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_com_mapswithme_maps_downloader_MapManager_nativeMigrate(JNIEnv * env, jclass clazz, jobject listener, jdouble lat, jdouble lon, jboolean hasLocation, jboolean keepOldMaps)
|
||||
{
|
||||
ms::LatLon position{};
|
||||
if (hasLocation)
|
||||
position = MercatorBounds::ToLatLon(g_framework->GetViewportCenter());
|
||||
|
||||
listener = env->NewGlobalRef(listener);
|
||||
|
||||
if (g_framework->PreMigrate(position, bind(&MigrationStatusChangedCallback, listener, _1, keepOldMaps),
|
||||
bind(&MigrationProgressCallback, listener, _1, _2)))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
OnPrefetchComplete(listener, keepOldMaps);
|
||||
return false;
|
||||
}
|
||||
|
||||
// static void nativeCancelMigration();
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_mapswithme_maps_downloader_MapManager_nativeCancelMigration(JNIEnv * env, jclass clazz)
|
||||
{
|
||||
Storage * storage = GetStorage().GetPrefetchStorage();
|
||||
TCountryId const & currentCountry = storage->GetCurrentDownloadingCountryId();
|
||||
storage->CancelDownloadNode(currentCountry);
|
||||
}
|
||||
|
||||
// static int nativeGetDownloadedCount();
|
||||
|
|
|
@ -14,11 +14,19 @@ public final class MapManager
|
|||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public interface CurrentCountryChangedListener
|
||||
interface CurrentCountryChangedListener
|
||||
{
|
||||
void onCurrentCountryChanged(String countryId);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
interface MigrationListener
|
||||
{
|
||||
void onComplete();
|
||||
void onProgress(int percent);
|
||||
void onError(int code);
|
||||
}
|
||||
|
||||
private MapManager() {}
|
||||
|
||||
/**
|
||||
|
@ -26,6 +34,11 @@ public final class MapManager
|
|||
*/
|
||||
public static native boolean nativeMoveFile(String oldFile, String newFile);
|
||||
|
||||
/**
|
||||
* Returns {@code true} if there is enough storage space to perform migration. Or {@code false} otherwise.
|
||||
*/
|
||||
public static native boolean nativeHasSpaceForMigration();
|
||||
|
||||
/**
|
||||
* Determines whether the legacy (large MWMs) mode is used.
|
||||
*/
|
||||
|
@ -33,8 +46,15 @@ public final class MapManager
|
|||
|
||||
/**
|
||||
* Performs migration from old (large MWMs) mode.
|
||||
* @return {@code true} if prefetch was started. {@code false} if maps were queued to downloader and migration process is complete.
|
||||
* In this case {@link MigrationListener#onComplete()} will be called before return from {@code nativeMigrate()}.
|
||||
*/
|
||||
public static native void nativeMigrate();
|
||||
public static native boolean nativeMigrate(MigrationListener listener, double lat, double lon, boolean hasLocation, boolean keepOldMaps);
|
||||
|
||||
/**
|
||||
* Aborts migration. Affects only prefetch process.
|
||||
*/
|
||||
public static native void nativeCancelMigration();
|
||||
|
||||
/**
|
||||
* Returns country ID of the root node.
|
||||
|
|
Loading…
Add table
Reference in a new issue