From 1f3b621450beb2fa6e5dd65928377301dc61bfac Mon Sep 17 00:00:00 2001 From: xynngh Date: Tue, 1 Jun 2021 12:26:00 +0400 Subject: [PATCH] Update LibPhoneNumberInfo --- CHANGELOG.md | 4 +- app/build.gradle | 2 +- .../yetanothercallblocker/data/Config.java | 41 ++++++++----------- .../yetanothercallblocker/work/DbUpdater.java | 37 +++++++++++++++++ .../work/TaskService.java | 22 +--------- .../work/UpdateWorker.java | 29 ++----------- 6 files changed, 62 insertions(+), 73 deletions(-) create mode 100644 app/src/main/java/dummydomain/yetanothercallblocker/work/DbUpdater.java diff --git a/CHANGELOG.md b/CHANGELOG.md index c514ae0..9942588 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,12 +15,14 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ### Changed - The Lookup screen number field is prefilled from clipboard. +- The database update procedure is optimized to require less RAM. - Updated French and Italian translations thanks to J. Lavoie ([@Edanas](https://hosted.weblate.org/user/Edanas/)). - Updated Portuguese translation thanks to ssantos ([@ssantos](https://hosted.weblate.org/user/ssantos/)). ### Fixed -- Fix Hebrew translation not being used by Android. +- Fixed a rare bug where the app could stuck in an update loop. +- Fixed Hebrew translation not being used by Android. ## [0.5.14] - 2021-05-05 diff --git a/app/build.gradle b/app/build.gradle index ad15d9a..574e432 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -46,7 +46,7 @@ dependencies { implementation 'org.conscrypt:conscrypt-android:2.5.2' //noinspection GradleDependency: 3.12.* is the latest version compatible with Android <5 implementation 'com.squareup.okhttp3:okhttp:3.12.13' - implementation 'com.gitlab.xynngh:LibPhoneNumberInfo:5b0b9fcbee' + implementation 'com.gitlab.xynngh:LibPhoneNumberInfo:c77bdd2b69' implementation 'org.apache.commons:commons-csv:1.8' implementation 'androidx.appcompat:appcompat:1.2.0' diff --git a/app/src/main/java/dummydomain/yetanothercallblocker/data/Config.java b/app/src/main/java/dummydomain/yetanothercallblocker/data/Config.java index ec2f360..066ddec 100644 --- a/app/src/main/java/dummydomain/yetanothercallblocker/data/Config.java +++ b/app/src/main/java/dummydomain/yetanothercallblocker/data/Config.java @@ -18,6 +18,7 @@ import dummydomain.yetanothercallblocker.sia.model.database.CommunityDatabase; import dummydomain.yetanothercallblocker.sia.model.database.DbManager; import dummydomain.yetanothercallblocker.sia.model.database.FeaturedDatabase; import dummydomain.yetanothercallblocker.sia.network.DbDownloader; +import dummydomain.yetanothercallblocker.sia.network.DbUpdateRequester; import dummydomain.yetanothercallblocker.sia.network.OkHttpClientFactory; import dummydomain.yetanothercallblocker.sia.network.WebService; import dummydomain.yetanothercallblocker.sia.utils.Utils; @@ -32,22 +33,17 @@ import static dummydomain.yetanothercallblocker.data.SiaConstants.SIA_SECONDARY_ public class Config { private static class WSParameterProvider extends WebService.DefaultWSParameterProvider { - dummydomain.yetanothercallblocker.Settings settings; - SiaMetadata siaMetadata; - CommunityDatabase communityDatabase; + final dummydomain.yetanothercallblocker.Settings settings; + final SiaMetadata siaMetadata; + final CommunityDatabase communityDatabase; volatile String appId; volatile long appIdTimestamp; - void setSettings(dummydomain.yetanothercallblocker.Settings settings) { + WSParameterProvider(dummydomain.yetanothercallblocker.Settings settings, + SiaMetadata siaMetadata, CommunityDatabase communityDatabase) { this.settings = settings; - } - - void setSiaMetadata(SiaMetadata siaMetadata) { this.siaMetadata = siaMetadata; - } - - void setCommunityDatabase(CommunityDatabase communityDatabase) { this.communityDatabase = communityDatabase; } @@ -98,32 +94,29 @@ public class Config { return new OkHttpClient(); }; - WSParameterProvider wsParameterProvider = new WSParameterProvider(); - wsParameterProvider.setSettings(settings); - - WebService webService = new WebService(wsParameterProvider, okHttpClientFactory); - YacbHolder.setWebService(webService); - - YacbHolder.setDbManager(new DbManager(storage, SIA_PATH_PREFIX, - new DbDownloader(okHttpClientFactory))); - CommunityDatabase communityDatabase = new CommunityDatabase( storage, AbstractDatabase.Source.ANY, SIA_PATH_PREFIX, - SIA_SECONDARY_PATH_PREFIX, siaSettings, webService); - - wsParameterProvider.setCommunityDatabase(communityDatabase); + SIA_SECONDARY_PATH_PREFIX, siaSettings); YacbHolder.setCommunityDatabase(communityDatabase); SiaMetadata siaMetadata = new SiaMetadata(storage, SIA_PATH_PREFIX, communityDatabase::isUsingInternal); - - wsParameterProvider.setSiaMetadata(siaMetadata); YacbHolder.setSiaMetadata(siaMetadata); FeaturedDatabase featuredDatabase = new FeaturedDatabase( storage, AbstractDatabase.Source.ANY, SIA_PATH_PREFIX); YacbHolder.setFeaturedDatabase(featuredDatabase); + WSParameterProvider wsParameterProvider = new WSParameterProvider( + settings, siaMetadata, communityDatabase); + + WebService webService = new WebService(wsParameterProvider, okHttpClientFactory); + YacbHolder.setWebService(webService); + + YacbHolder.setDbManager(new DbManager(storage, SIA_PATH_PREFIX, + new DbDownloader(okHttpClientFactory), new DbUpdateRequester(webService), + communityDatabase)); + YacbHolder.setCommunityReviewsLoader(new CommunityReviewsLoader(webService)); YacbDaoSessionFactory daoSessionFactory = new YacbDaoSessionFactory(context, "YACB"); diff --git a/app/src/main/java/dummydomain/yetanothercallblocker/work/DbUpdater.java b/app/src/main/java/dummydomain/yetanothercallblocker/work/DbUpdater.java new file mode 100644 index 0000000..7c2d444 --- /dev/null +++ b/app/src/main/java/dummydomain/yetanothercallblocker/work/DbUpdater.java @@ -0,0 +1,37 @@ +package dummydomain.yetanothercallblocker.work; + +import dummydomain.yetanothercallblocker.App; +import dummydomain.yetanothercallblocker.Settings; +import dummydomain.yetanothercallblocker.data.YacbHolder; +import dummydomain.yetanothercallblocker.event.SecondaryDbUpdateFinished; +import dummydomain.yetanothercallblocker.event.SecondaryDbUpdatingEvent; +import dummydomain.yetanothercallblocker.sia.model.database.DbManager; + +import static dummydomain.yetanothercallblocker.EventUtils.postEvent; +import static dummydomain.yetanothercallblocker.EventUtils.postStickyEvent; +import static dummydomain.yetanothercallblocker.EventUtils.removeStickyEvent; + +public class DbUpdater { + + public void update() { + Settings settings = App.getSettings(); + + boolean updated = false; + + SecondaryDbUpdatingEvent sticky = new SecondaryDbUpdatingEvent(); + + postStickyEvent(sticky); + try { + DbManager.UpdateResult updateResult = YacbHolder.getDbManager().updateSecondaryDb(); + if (updateResult.isUpdated()) { + settings.setLastUpdateTime(System.currentTimeMillis()); + updated = true; + } // TODO: handle other results + settings.setLastUpdateCheckTime(System.currentTimeMillis()); + } finally { + removeStickyEvent(sticky); + postEvent(new SecondaryDbUpdateFinished(updated)); + } + } + +} diff --git a/app/src/main/java/dummydomain/yetanothercallblocker/work/TaskService.java b/app/src/main/java/dummydomain/yetanothercallblocker/work/TaskService.java index cb24bbe..42ac528 100644 --- a/app/src/main/java/dummydomain/yetanothercallblocker/work/TaskService.java +++ b/app/src/main/java/dummydomain/yetanothercallblocker/work/TaskService.java @@ -16,12 +16,9 @@ import org.slf4j.LoggerFactory; import dummydomain.yetanothercallblocker.App; import dummydomain.yetanothercallblocker.NotificationHelper; import dummydomain.yetanothercallblocker.R; -import dummydomain.yetanothercallblocker.Settings; import dummydomain.yetanothercallblocker.data.YacbHolder; import dummydomain.yetanothercallblocker.event.MainDbDownloadFinishedEvent; import dummydomain.yetanothercallblocker.event.MainDbDownloadingEvent; -import dummydomain.yetanothercallblocker.event.SecondaryDbUpdateFinished; -import dummydomain.yetanothercallblocker.event.SecondaryDbUpdatingEvent; import static dummydomain.yetanothercallblocker.EventUtils.postEvent; import static dummydomain.yetanothercallblocker.EventUtils.postStickyEvent; @@ -102,24 +99,7 @@ public class TaskService extends IntentService { } private void updateSecondaryDb() { - Settings settings = App.getSettings(); - - boolean updated = false; - - SecondaryDbUpdatingEvent sticky = new SecondaryDbUpdatingEvent(); - - postStickyEvent(sticky); - try { - if (YacbHolder.getCommunityDatabase().updateSecondaryDb()) { - settings.setLastUpdateTime(System.currentTimeMillis()); - updated = true; - } - settings.setLastUpdateCheckTime(System.currentTimeMillis()); - } finally { - removeStickyEvent(sticky); - } - - postEvent(new SecondaryDbUpdateFinished(updated)); + new DbUpdater().update(); } } diff --git a/app/src/main/java/dummydomain/yetanothercallblocker/work/UpdateWorker.java b/app/src/main/java/dummydomain/yetanothercallblocker/work/UpdateWorker.java index 94e4342..59fcf55 100644 --- a/app/src/main/java/dummydomain/yetanothercallblocker/work/UpdateWorker.java +++ b/app/src/main/java/dummydomain/yetanothercallblocker/work/UpdateWorker.java @@ -9,16 +9,6 @@ import androidx.work.WorkerParameters; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import dummydomain.yetanothercallblocker.App; -import dummydomain.yetanothercallblocker.Settings; -import dummydomain.yetanothercallblocker.data.YacbHolder; -import dummydomain.yetanothercallblocker.event.SecondaryDbUpdateFinished; -import dummydomain.yetanothercallblocker.event.SecondaryDbUpdatingEvent; - -import static dummydomain.yetanothercallblocker.EventUtils.postEvent; -import static dummydomain.yetanothercallblocker.EventUtils.postStickyEvent; -import static dummydomain.yetanothercallblocker.EventUtils.removeStickyEvent; - public class UpdateWorker extends Worker { private static final Logger LOG = LoggerFactory.getLogger(UpdateWorker.class); @@ -32,25 +22,12 @@ public class UpdateWorker extends Worker { public Result doWork() { LOG.info("doWork() started"); - Settings settings = App.getSettings(); - - boolean updated = false; - - SecondaryDbUpdatingEvent sticky = new SecondaryDbUpdatingEvent(); - - postStickyEvent(sticky); try { - if (YacbHolder.getCommunityDatabase().updateSecondaryDb()) { - settings.setLastUpdateTime(System.currentTimeMillis()); - updated = true; - } - settings.setLastUpdateCheckTime(System.currentTimeMillis()); - } finally { - removeStickyEvent(sticky); + new DbUpdater().update(); + } catch (Exception e) { + LOG.error("doWork() error", e); } - postEvent(new SecondaryDbUpdateFinished(updated)); - LOG.info("doWork() finished"); return Result.success(); }