From 6cc5ae7717a6b3944d65d04589101e4352f2b0aa Mon Sep 17 00:00:00 2001 From: afischerdev Date: Sun, 9 Jul 2023 14:54:50 +0200 Subject: [PATCH 1/4] change from StatFs to File --- .../btools/routingapp/BInstallerActivity.java | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/brouter-routing-app/src/main/java/btools/routingapp/BInstallerActivity.java b/brouter-routing-app/src/main/java/btools/routingapp/BInstallerActivity.java index 6ef654e..5eda69c 100644 --- a/brouter-routing-app/src/main/java/btools/routingapp/BInstallerActivity.java +++ b/brouter-routing-app/src/main/java/btools/routingapp/BInstallerActivity.java @@ -6,6 +6,7 @@ import static btools.routingapp.BInstallerView.MASK_INSTALLED_RD5; import static btools.routingapp.BInstallerView.MASK_SELECTED_RD5; import android.Manifest; +import android.annotation.SuppressLint; import android.app.AlertDialog; import android.app.Dialog; import android.content.DialogInterface; @@ -14,7 +15,6 @@ import android.content.pm.PackageManager; import android.content.res.Resources; import android.os.Build; import android.os.Bundle; -import android.os.StatFs; import android.text.format.Formatter; import android.util.Log; import android.view.View; @@ -65,16 +65,11 @@ public class BInstallerActivity extends AppCompatActivity { BInstallerView.OnSelectListener onSelectListener; - @SuppressWarnings("deprecation") + @SuppressLint("UsableSpace") public static long getAvailableSpace(String baseDir) { - StatFs stat = new StatFs(baseDir); - - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { - return stat.getAvailableBlocksLong() * stat.getBlockSizeLong(); - } else { - //noinspection deprecation - return (long) stat.getAvailableBlocks() * stat.getBlockSize(); - } + File f = new File(baseDir); + if (!f.exists()) return 0L; + return f.getUsableSpace(); } @Override From 20ee509d39646da8344874fa5e885513b5c86077 Mon Sep 17 00:00:00 2001 From: afischerdev Date: Sun, 9 Jul 2023 14:56:42 +0200 Subject: [PATCH 2/4] basedir sometimes not filled --- .../src/main/java/btools/routingapp/BInstallerActivity.java | 1 + 1 file changed, 1 insertion(+) diff --git a/brouter-routing-app/src/main/java/btools/routingapp/BInstallerActivity.java b/brouter-routing-app/src/main/java/btools/routingapp/BInstallerActivity.java index 5eda69c..e93bb31 100644 --- a/brouter-routing-app/src/main/java/btools/routingapp/BInstallerActivity.java +++ b/brouter-routing-app/src/main/java/btools/routingapp/BInstallerActivity.java @@ -155,6 +155,7 @@ public class BInstallerActivity extends AppCompatActivity { } private void updateDownloadButton() { + if (mBaseDir == null) return; final ArrayList selectedTilesDownload = mBInstallerView.getSelectedTiles(MASK_SELECTED_RD5); final ArrayList selectedTilesLastUpdate = mBInstallerView.getSelectedTiles(MASK_CURRENT_RD5); final ArrayList selectedTilesUpdate = mBInstallerView.getSelectedTiles(MASK_INSTALLED_RD5); From 9a029af8dd5ed778fd51ecd7303d751ea4e39237 Mon Sep 17 00:00:00 2001 From: afischerdev Date: Sun, 9 Jul 2023 18:22:25 +0200 Subject: [PATCH 3/4] protect against limited data size --- .../btools/routingapp/BInstallerActivity.java | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/brouter-routing-app/src/main/java/btools/routingapp/BInstallerActivity.java b/brouter-routing-app/src/main/java/btools/routingapp/BInstallerActivity.java index e93bb31..ba3f704 100644 --- a/brouter-routing-app/src/main/java/btools/routingapp/BInstallerActivity.java +++ b/brouter-routing-app/src/main/java/btools/routingapp/BInstallerActivity.java @@ -197,18 +197,30 @@ public class BInstallerActivity extends AppCompatActivity { public void downloadAll(ArrayList downloadList, int all) { ArrayList urlparts = new ArrayList<>(); + int len = 0; for (Integer i : downloadList) { urlparts.add(baseNameForTile(i)); + len++; + if (len > 500) break; // don't do too much work, data size 10240 Bytes only } downloadCanceled = false; mProgressIndicator.show(); mButtonDownload.setEnabled(false); - Data inputData = new Data.Builder() - .putStringArray(DownloadWorker.KEY_INPUT_SEGMENT_NAMES, urlparts.toArray(new String[0])) - .putInt(DownloadWorker.KEY_INPUT_SEGMENT_ALL, all) - .build(); + Data inputData = null; + try { + inputData = new Data.Builder() + .putStringArray(DownloadWorker.KEY_INPUT_SEGMENT_NAMES, urlparts.toArray(new String[0])) + .putInt(DownloadWorker.KEY_INPUT_SEGMENT_ALL, all) + .build(); + + } catch (IllegalStateException e) { + Toast.makeText(this, "Too much data for download. Please reduce.", Toast.LENGTH_LONG).show(); + + e.printStackTrace(); + return; + } Constraints constraints = new Constraints.Builder() .setRequiresBatteryNotLow(true) From 62595b25530641b2d18c224caa3837b8bc46d910 Mon Sep 17 00:00:00 2001 From: afischerdev Date: Sun, 9 Jul 2023 18:35:10 +0200 Subject: [PATCH 4/4] move migration away from ui thread --- .../main/java/btools/routingapp/BRouterView.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/brouter-routing-app/src/main/java/btools/routingapp/BRouterView.java b/brouter-routing-app/src/main/java/btools/routingapp/BRouterView.java index 6e6c706..9655345 100644 --- a/brouter-routing-app/src/main/java/btools/routingapp/BRouterView.java +++ b/brouter-routing-app/src/main/java/btools/routingapp/BRouterView.java @@ -174,8 +174,18 @@ public class BRouterView extends View { // new init is done move old files if (waitingForMigration) { Log.d("BR", "path " + oldMigrationPath + " " + basedir); - if (!oldMigrationPath.equals(basedir + "/brouter")) - moveFolders(oldMigrationPath, basedir + "/brouter"); + Thread t = new Thread(new Runnable() { + @Override + public void run() { + if (!oldMigrationPath.equals(basedir + "/brouter")) + moveFolders(oldMigrationPath, basedir + "/brouter"); + }}); + t.start(); + try { + t.join(500); + } catch (InterruptedException e) { + e.printStackTrace(); + } waitingForMigration = false; }