From 61ce13ca334a0b74c32f70f3a2fec65cdaafb8a1 Mon Sep 17 00:00:00 2001 From: Arndt Date: Sat, 7 Jan 2017 17:24:09 +0100 Subject: [PATCH] workaround for startup crash when reading free space fails --- brouter-routing-app/AndroidManifest.xml | 2 +- .../main/java/btools/routingapp/BInstallerView.java | 13 +++++++++---- .../java/btools/routingapp/BRouterActivity.java | 13 +++++++------ 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/brouter-routing-app/AndroidManifest.xml b/brouter-routing-app/AndroidManifest.xml index b1e8812..242705c 100644 --- a/brouter-routing-app/AndroidManifest.xml +++ b/brouter-routing-app/AndroidManifest.xml @@ -1,7 +1,7 @@ = 0 ? ((availableSize + mb-1)/mb) + " MB" : "?"; canvas.drawText( "Selected segments=" + rd5Tiles, 10, 25, paint ); canvas.drawText( "Size=" + totmb + " Free=" + freemb , 10, 45, paint ); @@ -591,7 +596,7 @@ float tx, ty; // might be -1: server did not report the length int fileLength = connection.getContentLength(); currentDownloadSize = fileLength; - if ( fileLength > availableSize ) return "not enough space on sd-card"; + if ( availableSize >= 0 && fileLength > availableSize ) return "not enough space on sd-card"; // download the file input = connection.getInputStream(); diff --git a/brouter-routing-app/src/main/java/btools/routingapp/BRouterActivity.java b/brouter-routing-app/src/main/java/btools/routingapp/BRouterActivity.java index 417ccde..fe5b036 100644 --- a/brouter-routing-app/src/main/java/btools/routingapp/BRouterActivity.java +++ b/brouter-routing-app/src/main/java/btools/routingapp/BRouterActivity.java @@ -467,17 +467,18 @@ public class BRouterActivity extends Activity implements OnInitListener ArrayList dirFreeSizes = new ArrayList(); for ( String d : items ) { + long size = 0L; try { StatFs stat = new StatFs( d ); - long size = (long) stat.getAvailableBlocks() * stat.getBlockSize(); - int idx = 0; - while (idx < availableBasedirs.size() && dirFreeSizes.get( idx ).longValue() > size) - idx++; - availableBasedirs.add( idx, d ); - dirFreeSizes.add( idx, Long.valueOf( size ) ); + size = (long) stat.getAvailableBlocks() * stat.getBlockSize(); } catch (Exception e) { /* ignore */ } + int idx = 0; + while (idx < availableBasedirs.size() && dirFreeSizes.get( idx ).longValue() > size) + idx++; + availableBasedirs.add( idx, d ); + dirFreeSizes.add( idx, Long.valueOf( size ) ); } basedirOptions = new String[items.size() + 1];