diff --git a/brouter-routing-app/build.gradle b/brouter-routing-app/build.gradle index 5ec912e..083bbeb 100644 --- a/brouter-routing-app/build.gradle +++ b/brouter-routing-app/build.gradle @@ -7,8 +7,6 @@ android { defaultConfig { applicationId "btools.routingapp" - minSdkVersion 19 - targetSdkVersion 30 versionCode 41 versionName project.version @@ -19,27 +17,27 @@ android { } if(project.hasProperty("RELEASE_STORE_FILE")) { - signingConfigs { - // this uses a file ~/.gradle/gradle.properties - // with content: - // RELEASE_STORE_FILE={path to your keystore} - // RELEASE_STORE_PASSWORD=***** - // RELEASE_KEY_ALIAS=***** - // RELEASE_KEY_PASSWORD=***** - // - release { - // enable signingConfig in buildTypes to get a signed apk file - storeFile file(RELEASE_STORE_FILE) - storePassword RELEASE_STORE_PASSWORD - keyAlias RELEASE_KEY_ALIAS - keyPassword RELEASE_KEY_PASSWORD + signingConfigs { + // this uses a file ~/.gradle/gradle.properties + // with content: + // RELEASE_STORE_FILE={path to your keystore} + // RELEASE_STORE_PASSWORD=***** + // RELEASE_KEY_ALIAS=***** + // RELEASE_KEY_PASSWORD=***** + // + release { + // enable signingConfig in buildTypes to get a signed apk file + storeFile file(RELEASE_STORE_FILE) + storePassword RELEASE_STORE_PASSWORD + keyAlias RELEASE_KEY_ALIAS + keyPassword RELEASE_KEY_PASSWORD - // Optional, specify signing versions used - v1SigningEnabled true - v2SigningEnabled true - - } - } + // Optional, specify signing versions used + v1SigningEnabled true + v2SigningEnabled true + + } + } } buildTypes { @@ -60,19 +58,36 @@ android { lintOptions { disable 'InvalidPackage' checkReleaseBuilds false //added this line to the build.gradle under the /android/app/build.gradle - } + } compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } + flavorDimensions "api" + productFlavors { + api10 { + dimension "api" + + minSdkVersion 10 + targetSdkVersion 19 + } + api19 { + dimension "api" + + minSdkVersion 19 + targetSdkVersion 30 + + } + } + } dependencies { - implementation 'androidx.appcompat:appcompat:1.3.1' - + api19Implementation 'androidx.appcompat:appcompat:1.3.1' + implementation project(':brouter-mapaccess') implementation project(':brouter-core') implementation project(':brouter-expressions') diff --git a/brouter-routing-app/src/api10/java/btools/routingapp/BInstallerMainActivity.java b/brouter-routing-app/src/api10/java/btools/routingapp/BInstallerMainActivity.java new file mode 100644 index 0000000..9d354a5 --- /dev/null +++ b/brouter-routing-app/src/api10/java/btools/routingapp/BInstallerMainActivity.java @@ -0,0 +1,27 @@ +package btools.routingapp; + +import android.app.Activity; +import android.app.AlertDialog; +import android.app.Dialog; +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.DialogInterface; +import android.content.Intent; +import android.content.IntentFilter; +import android.content.pm.ActivityInfo; +import android.os.Bundle; +import android.os.PowerManager; +import android.os.PowerManager.WakeLock; +import android.os.StatFs; + +import java.util.HashSet; +import java.util.Set; + +public class BInstallerMainActivity extends Activity { + + + static public long getAvailableSpace (String baseDir) { + StatFs stat = new StatFs(baseDir); + return (long)stat.getAvailableBlocks()*stat.getBlockSize(); + } +} diff --git a/brouter-routing-app/src/api10/java/btools/routingapp/BRouterMainActivity.java b/brouter-routing-app/src/api10/java/btools/routingapp/BRouterMainActivity.java new file mode 100644 index 0000000..92f07ef --- /dev/null +++ b/brouter-routing-app/src/api10/java/btools/routingapp/BRouterMainActivity.java @@ -0,0 +1,106 @@ +package btools.routingapp; + +import android.app.Activity; +import android.app.ActivityManager; +import android.app.AlertDialog; +import android.app.Dialog; +import android.content.Context; +import android.content.DialogInterface; +import android.content.Intent; +import android.content.pm.PackageManager; +import android.net.ConnectivityManager; +import android.net.Network; +import android.net.NetworkCapabilities; +import android.net.NetworkInfo; +import android.os.Build; +import android.os.Bundle; +import android.os.Environment; +import android.os.PowerManager; +import android.os.PowerManager.WakeLock; +import android.os.StatFs; +import android.widget.EditText; + +import java.io.File; +import java.lang.reflect.Method; +import java.text.DecimalFormat; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import btools.router.OsmNodeNamed; + +public class BRouterMainActivity extends Activity +{ + + public boolean checkSelfPermission (Context context, String perm ) { + return true; + } + + public String getStorageState(File f ) { + return Environment.getExternalStorageState(); + } + + public ArrayList getStorageDirectories() { + List list = getFilesDirs(); + ArrayList flist = new ArrayList<>(); + for (String s: list) { + File f = new File(s); + flist.add(f); + } + return flist; + } + + private List getFilesDirs() + { + ArrayList res = new ArrayList(); + + // check write access on internal sd + try + { + File sd = Environment.getExternalStorageDirectory(); + File testDir = new File( sd, "brouter" ); + boolean didExist = testDir.isDirectory(); + if ( !didExist ) + { + testDir.mkdir(); + } + File testFile = new File( testDir, "test" + System.currentTimeMillis() ); + testFile.createNewFile(); + if ( testFile.exists() ) + { + testFile.delete(); + res.add( sd.getPath() ); + } + if ( !didExist ) + { + testDir.delete(); + } + } + catch( Throwable t ) + { + // ignore + } + + /* + // not on api 10 + try + { + Method method = Context.class.getDeclaredMethod("getExternalFilesDirs", new Class[]{ String.class } ); + File[] paths = (File[])method.invoke( this, new Object[1] ); + for( File path : paths ) + { + res.add( path.getPath() ); + } + } + catch( Exception e ) + { + res.add( e.toString() ); + res.add( Environment.getExternalStorageDirectory().getPath() ); + } + */ + + return res; + } + +} diff --git a/brouter-routing-app/src/api10/java/btools/routingapp/NotificationHelper.java b/brouter-routing-app/src/api10/java/btools/routingapp/NotificationHelper.java new file mode 100644 index 0000000..18d0525 --- /dev/null +++ b/brouter-routing-app/src/api10/java/btools/routingapp/NotificationHelper.java @@ -0,0 +1,104 @@ +package btools.routingapp; + +import android.app.Notification; +import android.app.NotificationChannel; +import android.app.NotificationManager; +import android.app.PendingIntent; +import android.app.Service; +import android.content.Context; +import android.content.Intent; +import android.media.AudioAttributes; +import android.os.Build; +import android.util.Log; + + + +import static android.content.Context.NOTIFICATION_SERVICE; + +public class NotificationHelper { + + private static final boolean DEBUG = false; + + public static String BRouterNotificationChannel1 = "brouter_channel_01"; + + private Context mContext; + private int NOTIFICATION_ID = 111; + private Notification mNotification; + private NotificationManager mNotificationManager; + private PendingIntent mContentIntent; + private CharSequence mContentTitle; + + public NotificationHelper(Context context) + { + if (DEBUG) Log.d("NH", "init " ); + mContext = context; + createNotificationChannels(); + } + + public void startNotification(Service service) { + if (DEBUG) Log.d("NH", "startNotification " ); + + mNotification = createNotification("BRouter Download", "Download some files"); + if (mNotification != null) { + NotificationManager mNotificationManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE); + mNotificationManager.notify(NOTIFICATION_ID, mNotification); + } + } + + public void progressUpdate(String text) { + mNotification = createNotification("BRouter Download", text); + + if (mNotification != null) { + mNotification.flags = Notification.FLAG_NO_CLEAR | + Notification.FLAG_ONGOING_EVENT; + NotificationManager mNotificationManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE); + mNotificationManager.notify(NOTIFICATION_ID, mNotification); + } + } + + + public Notification createNotification(String title, String desc) { + + Intent resultIntent = new Intent(mContext, BInstallerActivity.class); + + Intent notificationIntent = new Intent(); + mContentIntent = PendingIntent.getActivity(mContext, 0, resultIntent, PendingIntent.FLAG_IMMUTABLE); + + Notification.Builder builder ; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { + builder = new Notification.Builder(mContext); + builder.setSmallIcon(android.R.drawable.stat_sys_download) + .setContentTitle(title) + .setContentText(desc) + .setOnlyAlertOnce(true) + .setContentIntent(mContentIntent); + + if(Build.VERSION.SDK_INT>=11 && Build.VERSION.SDK_INT<=15) + return builder.getNotification(); + else if (Build.VERSION.SDK_INT > 15) + return builder.build(); + } + + return null; + + } + + + + /** + * create notification channels + */ + public void createNotificationChannels() { + if (DEBUG) Log.d("NH", "createNotificationChannels " ); + + } + + public void stopNotification() { + if (DEBUG) Log.d("NH", "stopNotification " ); + NotificationManager mNotificationManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + mNotificationManager.deleteNotificationChannel(BRouterNotificationChannel1); + } + mNotificationManager.cancel(NOTIFICATION_ID); + } +} \ No newline at end of file diff --git a/brouter-routing-app/src/api19/java/btools/routingapp/BInstallerMainActivity.java b/brouter-routing-app/src/api19/java/btools/routingapp/BInstallerMainActivity.java new file mode 100644 index 0000000..3b37d9e --- /dev/null +++ b/brouter-routing-app/src/api19/java/btools/routingapp/BInstallerMainActivity.java @@ -0,0 +1,37 @@ +package btools.routingapp; + +import java.util.HashSet; +import java.util.Set; + +import android.app.Activity; +import android.app.AlertDialog; +import android.app.Dialog; +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.DialogInterface; +import android.content.Intent; +import android.content.IntentFilter; +import android.content.pm.ActivityInfo; +import android.os.Bundle; +import android.os.PowerManager; +import android.os.PowerManager.WakeLock; +import android.speech.tts.TextToSpeech.OnInitListener; +import android.os.StatFs; +import android.util.Log; + +public class BInstallerMainActivity extends Activity implements OnInitListener { + + + @Override + public void onInit(int i) + { + } + + + static public long getAvailableSpace (String baseDir) { + StatFs stat = new StatFs(baseDir); + + return (long)stat.getAvailableBlocksLong()*stat.getBlockSizeLong(); + } + +} diff --git a/brouter-routing-app/src/api19/java/btools/routingapp/BRouterMainActivity.java b/brouter-routing-app/src/api19/java/btools/routingapp/BRouterMainActivity.java new file mode 100644 index 0000000..8f33453 --- /dev/null +++ b/brouter-routing-app/src/api19/java/btools/routingapp/BRouterMainActivity.java @@ -0,0 +1,88 @@ +package btools.routingapp; + +import java.io.File; +import java.text.DecimalFormat; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import android.app.Activity; +import android.app.ActivityManager; +import android.app.AlertDialog; +import android.app.Dialog; +import android.content.Context; +import android.content.DialogInterface; +import android.content.Intent; +import android.content.pm.PackageManager; +import android.net.ConnectivityManager; +import android.net.Network; +import android.net.NetworkCapabilities; +import android.net.NetworkInfo; +import android.os.Build; +import android.os.Bundle; +import android.os.Environment; +import android.os.PowerManager; +import android.os.PowerManager.WakeLock; +import android.os.StatFs; +import android.speech.tts.TextToSpeech.OnInitListener; +import android.util.Log; +import android.view.KeyEvent; +import android.widget.EditText; + +import androidx.core.app.ActivityCompat; +import androidx.core.content.ContextCompat; +import androidx.core.os.EnvironmentCompat; + +import btools.router.OsmNodeNamed; + +public class BRouterMainActivity extends Activity implements OnInitListener, ActivityCompat.OnRequestPermissionsResultCallback +{ + + @Override + public void onInit( int i ) + { + } + + public boolean checkSelfPermission (Context context, String perm ) { + boolean b = checkSelfPermission(context, perm); + if (b) { + ActivityCompat.requestPermissions (this, new String[]{perm}, 0); + } + + return b; + } + + public String getStorageState(File f) { + return EnvironmentCompat.getStorageState(f); //Environment.MEDIA_MOUNTED + } + + public File[] getExternFilesDirs(String d) { + return getExternalFilesDirs(null); + } + + public ArrayList getStorageDirectories () { + ArrayList list = null; + if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.Q) { + list = new ArrayList(Arrays.asList(getExternalMediaDirs())); + } else { + list = new ArrayList(Arrays.asList(getExternFilesDirs(null))); + } + ArrayList res = new ArrayList(); + + for (File f : list) { + if (f != null) { + if (getStorageState(f).equals(Environment.MEDIA_MOUNTED)) + res.add (f); + } + } + +// res.add(getContext().getFilesDir()); + return res; + } + + +} + + diff --git a/brouter-routing-app/src/main/java/btools/routingapp/NotificationHelper.java b/brouter-routing-app/src/api19/java/btools/routingapp/NotificationHelper.java similarity index 100% rename from brouter-routing-app/src/main/java/btools/routingapp/NotificationHelper.java rename to brouter-routing-app/src/api19/java/btools/routingapp/NotificationHelper.java diff --git a/brouter-routing-app/src/main/AndroidManifest.xml b/brouter-routing-app/src/main/AndroidManifest.xml index 90eee53..58395db 100644 --- a/brouter-routing-app/src/main/AndroidManifest.xml +++ b/brouter-routing-app/src/main/AndroidManifest.xml @@ -18,7 +18,8 @@ + android:screenOrientation="unspecified" + android:theme="@android:style/Theme.NoTitleBar.Fullscreen"> @@ -38,7 +39,7 @@ android:process=":brouter_service" /> 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 8a1c93f..14a4470 100644 --- a/brouter-routing-app/src/main/java/btools/routingapp/BInstallerActivity.java +++ b/brouter-routing-app/src/main/java/btools/routingapp/BInstallerActivity.java @@ -16,9 +16,10 @@ import android.os.Bundle; import android.os.PowerManager; import android.os.PowerManager.WakeLock; import android.speech.tts.TextToSpeech.OnInitListener; +import android.os.StatFs; import android.util.Log; -public class BInstallerActivity extends Activity implements OnInitListener { +public class BInstallerActivity extends BInstallerMainActivity { public static final String DOWNLOAD_ACTION = "btools.routingapp.download"; @@ -101,11 +102,6 @@ public class BInstallerActivity extends Activity implements OnInitListener { System.exit(0); } - @Override - public void onInit(int i) - { - } - @Override @SuppressWarnings("deprecation") protected Dialog onCreateDialog( int id ) @@ -154,4 +150,5 @@ public class BInstallerActivity extends Activity implements OnInitListener { showDialog( id ); } + } diff --git a/brouter-routing-app/src/main/java/btools/routingapp/BInstallerView.java b/brouter-routing-app/src/main/java/btools/routingapp/BInstallerView.java index debd00d..8bc737d 100644 --- a/brouter-routing-app/src/main/java/btools/routingapp/BInstallerView.java +++ b/brouter-routing-app/src/main/java/btools/routingapp/BInstallerView.java @@ -269,8 +269,9 @@ public class BInstallerView extends View availableSize = -1; try { - StatFs stat = new StatFs(baseDir.getAbsolutePath ()); - availableSize = (long)stat.getAvailableBlocksLong()*stat.getBlockSizeLong(); + availableSize = (long)((BInstallerActivity)getContext()).getAvailableSpace(baseDir.getAbsolutePath ()); + //StatFs stat = new StatFs(baseDir.getAbsolutePath ()); + //availableSize = (long)stat.getAvailableBlocksLong()*stat.getBlockSizeLong(); } catch (Exception e) { /* ignore */ } } 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 238e253..900dca4 100644 --- a/brouter-routing-app/src/main/java/btools/routingapp/BRouterActivity.java +++ b/brouter-routing-app/src/main/java/btools/routingapp/BRouterActivity.java @@ -1,8 +1,10 @@ package btools.routingapp; import java.io.File; +import java.lang.reflect.Method; import java.text.DecimalFormat; import java.util.ArrayList; +import java.util.Arrays; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -30,12 +32,11 @@ import android.util.Log; import android.view.KeyEvent; import android.widget.EditText; -import androidx.core.app.ActivityCompat; import btools.router.OsmNodeNamed; -public class BRouterActivity extends Activity implements OnInitListener, ActivityCompat.OnRequestPermissionsResultCallback -{ +public class BRouterActivity extends BRouterMainActivity { + private static final int DIALOG_SELECTPROFILE_ID = 1; private static final int DIALOG_EXCEPTION_ID = 2; private static final int DIALOG_SHOW_DM_INFO_ID = 3; @@ -138,7 +139,7 @@ public class BRouterActivity extends Activity implements OnInitListener, Activit { Intent intent = new Intent( BRouterActivity.this, BInstallerActivity.class ); startActivity( intent ); - finish(); + // finish(); } } ).setNegativeButton( "Cancel", new DialogInterface.OnClickListener() { @@ -666,19 +667,4 @@ public class BRouterActivity extends Activity implements OnInitListener, Activit mWakeLock.release(); } - @Override - public void onInit( int i ) - { - } - - @Override - public void onRequestPermissionsResult (int requestCode, String[] permissions, int[] grantResults) { - if (requestCode == 0) { - if (grantResults[0] == PackageManager.PERMISSION_GRANTED) { - mBRouterView.startSetup(null, true); - } else { - mBRouterView.init(); - } - } - } } diff --git a/brouter-routing-app/src/main/java/btools/routingapp/BRouterService.java b/brouter-routing-app/src/main/java/btools/routingapp/BRouterService.java index fbe5d09..655712e 100644 --- a/brouter-routing-app/src/main/java/btools/routingapp/BRouterService.java +++ b/brouter-routing-app/src/main/java/btools/routingapp/BRouterService.java @@ -11,6 +11,7 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.ByteArrayOutputStream; +import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.util.List; import java.util.zip.GZIPOutputStream; @@ -102,9 +103,9 @@ public class BRouterService extends Service try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); - baos.write( "z64".getBytes(StandardCharsets.UTF_8) ); // marker prefix + baos.write( "z64".getBytes(Charset.forName("UTF-8")) ); // marker prefix OutputStream os = new GZIPOutputStream( baos ); - byte[] ab = gpxMessage.getBytes(StandardCharsets.UTF_8); + byte[] ab = gpxMessage.getBytes(Charset.forName("UTF-8")); //StandardCharsets.UTF_8 gpxMessage = null; os.write( ab ); ab = null; 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 18e71f0..05b2f3e 100644 --- a/brouter-routing-app/src/main/java/btools/routingapp/BRouterView.java +++ b/brouter-routing-app/src/main/java/btools/routingapp/BRouterView.java @@ -37,9 +37,6 @@ import android.util.Log; import android.view.View; import android.widget.Toast; -import androidx.core.app.ActivityCompat; -import androidx.core.content.ContextCompat; -import androidx.core.os.EnvironmentCompat; import btools.expressions.BExpressionContextWay; import btools.expressions.BExpressionMetaData; @@ -131,7 +128,7 @@ public class BRouterView extends View if (brd.getAbsolutePath().contains("/Android/data/")) { String message = "(previous basedir " + baseDir + " has to migrate )" ; - ( (BRouterActivity) getContext() ).selectBasedir( getStorageDirectories(), guessBaseDir(), message ); + ( (BRouterActivity) getContext() ).selectBasedir( ( (BRouterActivity) getContext() ).getStorageDirectories(), guessBaseDir(), message ); waitingForSelection = true; waitingForMigration = true; oldMigrationPath = brd.getAbsolutePath(); @@ -145,7 +142,7 @@ public class BRouterView extends View String message = baseDir == null ? "(no basedir configured previously)" : "(previous basedir " + baseDir + ( bdValid ? " does not contain 'brouter' subfolder)" : " is not valid)" ); - ( (BRouterActivity) getContext() ).selectBasedir( getStorageDirectories(), guessBaseDir(), message ); + ( (BRouterActivity) getContext() ).selectBasedir( ( (BRouterActivity) getContext() ).getStorageDirectories(), guessBaseDir(), message ); waitingForSelection = true; } catch (Exception e) @@ -179,11 +176,11 @@ public class BRouterView extends View } if ( !td.isDirectory() ) { - if (ContextCompat.checkSelfPermission (getContext(), Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_DENIED) { + if ( ( (BRouterActivity) getContext() ).checkSelfPermission (getContext(), Manifest.permission.WRITE_EXTERNAL_STORAGE)) { + // if (ContextCompat.checkSelfPermission (getContext(), Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_DENIED) { retryBaseDir = baseDir; - ActivityCompat.requestPermissions ((BRouterActivity) getContext(), new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 0); } else { - ( (BRouterActivity) getContext() ).selectBasedir( getStorageDirectories (), guessBaseDir(), "Cannot access " + baseDir.getAbsolutePath () + "; select another"); + ( (BRouterActivity) getContext() ).selectBasedir( ( (BRouterActivity) getContext() ).getStorageDirectories (), guessBaseDir(), "Cannot access " + baseDir.getAbsolutePath () + "; select another"); } return; } @@ -1175,23 +1172,4 @@ public class BRouterView extends View } } - private ArrayList getStorageDirectories () { - ArrayList list = null; - if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.Q) { - list = new ArrayList(Arrays.asList(getContext().getExternalMediaDirs())); - } else { - list = new ArrayList(Arrays.asList(getContext().getExternalFilesDirs(null))); - } - ArrayList res = new ArrayList(); - - for (File f : list) { - if (f != null) { - if (EnvironmentCompat.getStorageState(f).equals(Environment.MEDIA_MOUNTED)) - res.add (f); - } - } - -// res.add(getContext().getFilesDir()); - return res; - } } diff --git a/brouter-routing-app/src/main/java/btools/routingapp/BRouterWorker.java b/brouter-routing-app/src/main/java/btools/routingapp/BRouterWorker.java index a1770fd..aee03db 100644 --- a/brouter-routing-app/src/main/java/btools/routingapp/BRouterWorker.java +++ b/brouter-routing-app/src/main/java/btools/routingapp/BRouterWorker.java @@ -409,7 +409,7 @@ public class BRouterWorker private List readPoisList(Bundle params ) { // lon,lat,name|... - String pois = params.getString( "pois", null ); + String pois = params.getString( "pois" ); if ( pois == null ) return null; String[] lonLatNameList = pois.split("\\|"); diff --git a/brouter-routing-app/src/main/java/btools/routingapp/DownloadService.java b/brouter-routing-app/src/main/java/btools/routingapp/DownloadService.java index e00eaf8..121424e 100644 --- a/brouter-routing-app/src/main/java/btools/routingapp/DownloadService.java +++ b/brouter-routing-app/src/main/java/btools/routingapp/DownloadService.java @@ -4,6 +4,7 @@ import android.app.NotificationManager; import android.app.Service; import android.content.Intent; import android.net.TrafficStats; +import android.os.Build; import android.os.Bundle; import android.os.Handler; import android.os.HandlerThread; @@ -88,8 +89,9 @@ public class DownloadService extends Service implements ProgressListener { availableSize = -1; try { - StatFs stat = new StatFs(baseDir); - availableSize = (long)stat.getAvailableBlocksLong()*stat.getBlockSizeLong(); + availableSize = BInstallerActivity.getAvailableSpace(baseDir); + //StatFs stat = new StatFs(baseDir); + //availableSize = (long)stat.getAvailableBlocksLong()*stat.getBlockSizeLong(); } catch (Exception e) { /* ignore */ } @@ -228,7 +230,9 @@ public class DownloadService extends Service implements ProgressListener { { try { - TrafficStats.setThreadStatsTag(1); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { + TrafficStats.setThreadStatsTag(1); + } int slidx = surl.lastIndexOf( "segments4/" ); String name = surl.substring( slidx+10 ); @@ -249,6 +253,7 @@ public class DownloadService extends Service implements ProgressListener { URL urlDelta = new URL(surlDelta); connection = (HttpURLConnection) urlDelta.openConnection(); + connection.setConnectTimeout(5000); connection.connect(); // 404 kind of expected here, means there's no delta file @@ -262,11 +267,12 @@ public class DownloadService extends Service implements ProgressListener { if ( connection == null ) { - updateProgress( "Connecting.." + surl ); + updateProgress( "Connecting.." + name ); delta = false; URL url = new URL(surl); connection = (HttpURLConnection) url.openConnection(); + connection.setConnectTimeout(5000); connection.connect(); } @@ -333,7 +339,7 @@ public class DownloadService extends Service implements ProgressListener { tmp_file = new File( fname + "_tmp" ); Rd5DiffTool.recoverFromDelta( fname, diffFile, tmp_file, this ); diffFile.delete(); - } + } if (isCanceled()) { return "Canceled!"; @@ -348,7 +354,7 @@ public class DownloadService extends Service implements ProgressListener { } return check_result; } - + if (fname.exists()) fname.delete(); if ( !tmp_file.renameTo( fname ) ) { return "Could not rename to " + fname.getAbsolutePath(); @@ -429,12 +435,15 @@ public class DownloadService extends Service implements ProgressListener { { try { - TrafficStats.setThreadStatsTag(1); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { + TrafficStats.setThreadStatsTag(1); + } if ( connection == null ) { URL url = new URL(surl); connection = (HttpURLConnection) url.openConnection(); + connection.setConnectTimeout(5000); connection.connect(); } // expect HTTP 200 OK, so we don't mistakenly save error report diff --git a/brouter-server/build.gradle b/brouter-server/build.gradle index 492b8ec..6cbcbd4 100644 --- a/brouter-server/build.gradle +++ b/brouter-server/build.gradle @@ -52,7 +52,10 @@ distributions { include 'readmes/*' include 'profiles2/*' } - from ('../brouter-routing-app/build/outputs/apk/release') { + from ('../brouter-routing-app/build/outputs/apk/api10/release') { + include '*.apk' + } + from ('../brouter-routing-app/build/outputs/apk/api19/release') { include '*.apk' } from ('../brouter-server/build/libs') { diff --git a/build.gradle b/build.gradle index e8b4939..c1c70c8 100644 --- a/build.gradle +++ b/build.gradle @@ -8,7 +8,7 @@ buildscript { google() } dependencies { - classpath 'com.android.tools.build:gradle:7.0.0' + classpath 'com.android.tools.build:gradle:7.0.1' // NOTE: Do not place your application dependencies here; they belong