Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit 8949fc1

Browse files
author
Langston Smith
authored
Mapbox gl native pin update and offline fix - release-sangria patch 8.5.2 release (#99)
1 parent aec765b commit 8949fc1

File tree

5 files changed

+98
-5
lines changed

5 files changed

+98
-5
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ Mapbox welcomes participation and contributions from everyone. If you'd like to
66
### Bugs
77
- Synchronise LibaryLoader#loadLibrary to avoid race conditions resulting in UnsatisfiedLinkError [#58](https://github.com/mapbox/mapbox-gl-native-android/pull/58)
88

9+
## 8.5.2 - December 10, 2019
10+
[Changes](https://github.com/mapbox/mapbox-gl-native-android/compare/android-v8.5.1...android-v8.5.2) since [Mapbox Maps SDK for Android v8.5.1](https://github.com/mapbox/mapbox-gl-native-android/releases/tag/android-v8.5.1):
11+
12+
### Features
13+
- Enabling decoupling vacuum operation from other operations run on the offline database file (delete offline region, clear ambient cache) [#99](https://github.com/mapbox/mapbox-gl-native-android/pull/99)
14+
15+
916
## 8.5.1 - November 20, 2019
1017
[Changes](https://github.com/mapbox/mapbox-gl-native-android/compare/android-v8.5.0...android-v8.5.1) since [Mapbox Maps SDK for Android v8.5.0](https://github.com/mapbox/mapbox-gl-native-android/releases/tag/android-v8.5.0):
1118
### Bugs

MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/offline/OfflineManager.java

Lines changed: 70 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,50 @@ public void run() {
306306
});
307307
}
308308

309+
/**
310+
* Packs the existing database file into a minimal amount of disk space.
311+
* <p>
312+
* This operation has a performance impact as it will vacuum the database,
313+
* forcing it to move pages on the filesystem.
314+
* <p>
315+
* When the operation is complete or encounters an error, the given callback will be
316+
* executed on the database thread; it is the responsibility of the SDK bindings
317+
* to re-execute a user-provided callback on the main thread.
318+
* </p>
319+
*
320+
* @param callback the callback to be invoked when the database was reset or when the operation erred.
321+
*/
322+
public void packDatabase(@Nullable final FileSourceCallback callback) {
323+
fileSource.activate();
324+
nativePackDatabase(new FileSourceCallback() {
325+
@Override
326+
public void onSuccess() {
327+
handler.post(new Runnable() {
328+
@Override
329+
public void run() {
330+
fileSource.deactivate();
331+
if (callback != null) {
332+
callback.onSuccess();
333+
}
334+
}
335+
});
336+
}
337+
338+
@Override
339+
public void onError(@NonNull final String message) {
340+
handler.post(new Runnable() {
341+
@Override
342+
public void run() {
343+
fileSource.deactivate();
344+
if (callback != null) {
345+
callback.onError(message);
346+
}
347+
}
348+
});
349+
}
350+
});
351+
}
352+
309353
/**
310354
* Forces re-validation of the ambient cache.
311355
* <p>
@@ -355,9 +399,10 @@ public void run() {
355399
/**
356400
* Erase resources from the ambient cache, freeing storage space.
357401
* <p>
358-
* Erases the ambient cache, freeing resources. This operation can be
359-
* potentially slow because it will trigger a VACUUM on SQLite,
360-
* forcing the database to move pages on the filesystem.
402+
* Erases the ambient cache, freeing resources.
403+
* <p>
404+
* Note that this operation can be potentially slow if packing the database
405+
* occurs automatically ({@link OfflineManager#runPackDatabaseAutomatically(boolean)}).
361406
* </p>
362407
* <p>
363408
* Resources overlapping with offline regions will not be affected
@@ -620,14 +665,32 @@ private boolean isValidOfflineRegionDefinition(OfflineRegionDefinition definitio
620665
* <p>
621666
* Once this limit is reached, {@link OfflineRegion.OfflineRegionObserver#mapboxTileCountLimitExceeded(long)}
622667
* fires every additional attempt to download additional tiles until already downloaded tiles are removed
623-
* by calling {@link OfflineRegion#deleteOfflineRegion(OfflineRegion.OfflineRegionDeleteCallback)}.
668+
* by calling {@link OfflineRegion#delete(OfflineRegion.OfflineRegionDeleteCallback)}.
624669
* </p>
625670
*
626671
* @param limit the maximum number of tiles allowed to be downloaded
627672
*/
628673
@Keep
629674
public native void setOfflineMapboxTileCountLimit(long limit);
630675

676+
/**
677+
* Sets whether database file packing occurs automatically.
678+
* By default, the automatic database file packing is enabled.
679+
* <p>
680+
* If packing is enabled, database file packing occurs automatically
681+
* after an offline region is deleted by calling
682+
* {@link OfflineRegion#delete(OfflineRegion.OfflineRegionDeleteCallback)}
683+
* or the ambient cache is cleared by calling {@link OfflineManager#clearAmbientCache()}.
684+
*
685+
* If packing is disabled, disk space will not be freed after
686+
* resources are removed unless {@link OfflineManager#packDatabase()} is explicitly called.
687+
* </p>
688+
*
689+
* @param autopack flag setting the automatic database file packing.
690+
*/
691+
@Keep
692+
public native void runPackDatabaseAutomatically(boolean autopack);
693+
631694
@Keep
632695
private native void initialize(FileSource fileSource);
633696

@@ -648,6 +711,9 @@ private native void createOfflineRegion(FileSource fileSource, OfflineRegionDefi
648711
@Keep
649712
private native void nativeResetDatabase(@Nullable FileSourceCallback callback);
650713

714+
@Keep
715+
private native void nativePackDatabase(@Nullable FileSourceCallback callback);
716+
651717
@Keep
652718
private native void nativeInvalidateAmbientCache(@Nullable FileSourceCallback callback);
653719

MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/offline/OfflineRegion.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,10 @@ public void run() {
388388
* by other regions, until the database shrinks below a certain size.
389389
* </p>
390390
* <p>
391+
* Note that this operation can be potentially slow if packing the database
392+
* occurs automatically ({@link OfflineManager#runPackDatabaseAutomatically(boolean)}).
393+
* </p>
394+
* <p>
391395
* When the operation is complete or encounters an error, the given callback will be
392396
* executed on the main thread.
393397
* </p>

MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/offline/CacheTest.kt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,4 +85,20 @@ class CacheTest {
8585
}
8686
countDownLatch.await()
8787
}
88+
89+
@Test
90+
fun testSetPackDatabase() {
91+
rule.activity.runOnUiThread {
92+
OfflineManager.getInstance(context).packDatabase(object : OfflineManager.FileSourceCallback {
93+
override fun onSuccess() {
94+
countDownLatch.countDown()
95+
}
96+
97+
override fun onError(message: String) {
98+
Assert.assertNull("onError should not be called", message)
99+
}
100+
})
101+
}
102+
countDownLatch.await()
103+
}
88104
}

0 commit comments

Comments
 (0)