Merge pull request #356 from zod/permission-handling
Improve permission handling
This commit is contained in:
commit
c9baec210a
14 changed files with 167 additions and 498 deletions
|
@ -16,6 +16,7 @@ android {
|
|||
resValue('string', 'app_version', defaultConfig.versionName)
|
||||
setProperty("archivesBaseName","BRouterApp." + defaultConfig.versionName)
|
||||
|
||||
minSdkVersion 14
|
||||
}
|
||||
|
||||
sourceSets.main.assets.srcDirs += new File(project.buildDir, 'assets')
|
||||
|
@ -69,20 +70,18 @@ android {
|
|||
targetCompatibility JavaVersion.VERSION_1_8
|
||||
}
|
||||
|
||||
|
||||
flavorDimensions "api"
|
||||
productFlavors {
|
||||
api10 {
|
||||
dimension "api"
|
||||
|
||||
minSdkVersion 10
|
||||
targetSdkVersion 19
|
||||
}
|
||||
api19 {
|
||||
dimension "api"
|
||||
|
||||
minSdkVersion 19
|
||||
targetSdkVersion 30
|
||||
targetSdkVersion 19
|
||||
}
|
||||
api30 {
|
||||
dimension "api"
|
||||
|
||||
targetSdkVersion 30
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -93,7 +92,7 @@ android {
|
|||
|
||||
dependencies {
|
||||
|
||||
api19Implementation 'androidx.appcompat:appcompat:1.3.1'
|
||||
implementation 'androidx.appcompat:appcompat:1.3.1'
|
||||
|
||||
implementation project(':brouter-mapaccess')
|
||||
implementation project(':brouter-core')
|
||||
|
|
|
@ -1,27 +0,0 @@
|
|||
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();
|
||||
}
|
||||
}
|
|
@ -1,106 +0,0 @@
|
|||
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<File> getStorageDirectories() {
|
||||
List<String> list = getFilesDirs();
|
||||
ArrayList<File> flist = new ArrayList<>();
|
||||
for (String s: list) {
|
||||
File f = new File(s);
|
||||
flist.add(f);
|
||||
}
|
||||
return flist;
|
||||
}
|
||||
|
||||
private List<String> getFilesDirs()
|
||||
{
|
||||
ArrayList<String> res = new ArrayList<String>();
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,104 +0,0 @@
|
|||
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);
|
||||
}
|
||||
}
|
|
@ -1,37 +0,0 @@
|
|||
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();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,88 +0,0 @@
|
|||
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<File> getStorageDirectories () {
|
||||
ArrayList<File> list = null;
|
||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.Q) {
|
||||
list = new ArrayList<File>(Arrays.asList(getExternalMediaDirs()));
|
||||
} else {
|
||||
list = new ArrayList<File>(Arrays.asList(getExternFilesDirs(null)));
|
||||
}
|
||||
ArrayList<File> res = new ArrayList<File>();
|
||||
|
||||
for (File f : list) {
|
||||
if (f != null) {
|
||||
if (getStorageState(f).equals(Environment.MEDIA_MOUNTED))
|
||||
res.add (f);
|
||||
}
|
||||
}
|
||||
|
||||
// res.add(getContext().getFilesDir());
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -12,6 +12,7 @@ import android.content.DialogInterface;
|
|||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.pm.ActivityInfo;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.PowerManager;
|
||||
import android.os.PowerManager.WakeLock;
|
||||
|
@ -19,7 +20,7 @@ import android.speech.tts.TextToSpeech.OnInitListener;
|
|||
import android.os.StatFs;
|
||||
import android.util.Log;
|
||||
|
||||
public class BInstallerActivity extends BInstallerMainActivity {
|
||||
public class BInstallerActivity extends Activity {
|
||||
|
||||
public static final String DOWNLOAD_ACTION = "btools.routingapp.download";
|
||||
|
||||
|
@ -151,4 +152,14 @@ public class BInstallerActivity extends BInstallerMainActivity {
|
|||
}
|
||||
|
||||
|
||||
static public 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 {
|
||||
return stat.getAvailableBlocks()*stat.getBlockSize();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,9 +33,12 @@ import android.view.KeyEvent;
|
|||
import android.widget.EditText;
|
||||
|
||||
|
||||
import androidx.core.app.ActivityCompat;
|
||||
import androidx.core.os.EnvironmentCompat;
|
||||
|
||||
import btools.router.OsmNodeNamed;
|
||||
|
||||
public class BRouterActivity extends BRouterMainActivity {
|
||||
public class BRouterActivity extends Activity implements ActivityCompat.OnRequestPermissionsResultCallback {
|
||||
|
||||
private static final int DIALOG_SELECTPROFILE_ID = 1;
|
||||
private static final int DIALOG_EXCEPTION_ID = 2;
|
||||
|
@ -54,7 +57,7 @@ public class BRouterActivity extends BRouterMainActivity {
|
|||
private static final int DIALOG_SHOW_WP_SCANRESULT_ID = 15;
|
||||
private static final int DIALOG_SHOW_REPEAT_TIMEOUT_HELP_ID = 16;
|
||||
private static final int DIALOG_SHOW_API23_HELP_ID = 17;
|
||||
|
||||
|
||||
|
||||
private BRouterView mBRouterView;
|
||||
private PowerManager mPowerManager;
|
||||
|
@ -667,4 +670,64 @@ public class BRouterActivity extends BRouterMainActivity {
|
|||
mWakeLock.release();
|
||||
}
|
||||
|
||||
private String getStorageState(File f) {
|
||||
return EnvironmentCompat.getStorageState(f); //Environment.MEDIA_MOUNTED
|
||||
}
|
||||
|
||||
public ArrayList<File> getStorageDirectories () {
|
||||
ArrayList<File> list = null;
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||
list = new ArrayList<File>(Arrays.asList(getExternalMediaDirs()));
|
||||
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
||||
list = new ArrayList<File>(Arrays.asList(getExternalFilesDirs(null)));
|
||||
}
|
||||
ArrayList<File> res = new ArrayList<File>();
|
||||
|
||||
for (File f : list) {
|
||||
if (f != null) {
|
||||
if (getStorageState(f).equals(Environment.MEDIA_MOUNTED))
|
||||
res.add (f);
|
||||
}
|
||||
}
|
||||
|
||||
if (checkExternalStorageWritable()) {
|
||||
res.add(Environment.getExternalStorageDirectory());
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
private boolean checkExternalStorageWritable() {
|
||||
boolean isWritable = false;
|
||||
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();
|
||||
isWritable = true;
|
||||
}
|
||||
}
|
||||
catch (Throwable t) {
|
||||
// ignore
|
||||
}
|
||||
return isWritable;
|
||||
}
|
||||
|
||||
@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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,13 +17,20 @@ import java.util.List;
|
|||
import java.util.zip.GZIPOutputStream;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import android.Manifest;
|
||||
import android.app.Service;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.os.IBinder;
|
||||
import android.os.RemoteException;
|
||||
import android.util.Log;
|
||||
import android.util.Base64;
|
||||
|
||||
import androidx.core.content.ContextCompat;
|
||||
|
||||
import btools.router.OsmNodeNamed;
|
||||
|
||||
public class BRouterService extends Service
|
||||
|
@ -203,27 +210,18 @@ public class BRouterService extends Service
|
|||
// add nogos from waypoint database
|
||||
int deviceLevel = android.os.Build.VERSION.SDK_INT;
|
||||
int targetSdkVersion = getApplicationInfo().targetSdkVersion;
|
||||
boolean canAccessSdCard = deviceLevel < 23 || targetSdkVersion == 19;
|
||||
boolean canAccessSdCard = true;
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q && !Environment.isExternalStorageLegacy()) {
|
||||
canAccessSdCard = false;
|
||||
}
|
||||
if (ContextCompat.checkSelfPermission(BRouterService.this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
|
||||
canAccessSdCard = false;
|
||||
}
|
||||
AppLogger.log( "dev/target=" + deviceLevel + "/" + targetSdkVersion + " canAccessSdCard=" + canAccessSdCard );
|
||||
if ( canAccessSdCard )
|
||||
{
|
||||
CoordinateReader cor = CoordinateReader.obtainValidReader( baseDir, worker.segmentDir, true );
|
||||
worker.nogoList = new ArrayList<OsmNodeNamed>( cor.nogopoints );
|
||||
worker.nogoPolygonsList = new ArrayList<OsmNodeNamed>();
|
||||
}
|
||||
else if (deviceLevel >= android.os.Build.VERSION_CODES.Q) {
|
||||
CoordinateReader cor = new CoordinateReaderInternal( baseDir );
|
||||
cor.readFromTo();
|
||||
|
||||
worker.nogoList = new ArrayList<OsmNodeNamed>( cor.nogopoints );
|
||||
worker.nogoPolygonsList = new ArrayList<OsmNodeNamed>();
|
||||
}
|
||||
else
|
||||
{
|
||||
worker.nogoList = new ArrayList<OsmNodeNamed>();
|
||||
worker.nogoPolygonsList = new ArrayList<OsmNodeNamed>();
|
||||
}
|
||||
|
||||
CoordinateReader cor = CoordinateReader.obtainValidReader( baseDir, worker.segmentDir, canAccessSdCard, true );
|
||||
worker.nogoList = new ArrayList<OsmNodeNamed>( cor.nogopoints );
|
||||
worker.nogoPolygonsList = new ArrayList<OsmNodeNamed>();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -38,6 +38,9 @@ import android.view.View;
|
|||
import android.widget.Toast;
|
||||
|
||||
|
||||
import androidx.core.app.ActivityCompat;
|
||||
import androidx.core.content.ContextCompat;
|
||||
|
||||
import btools.expressions.BExpressionContextWay;
|
||||
import btools.expressions.BExpressionMetaData;
|
||||
import btools.mapaccess.OsmNode;
|
||||
|
@ -176,9 +179,9 @@ public class BRouterView extends View
|
|||
}
|
||||
|
||||
if ( !td.isDirectory() ) {
|
||||
if ( ( (BRouterActivity) getContext() ).checkSelfPermission (getContext(), Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
|
||||
// if (ContextCompat.checkSelfPermission (getContext(), Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_DENIED) {
|
||||
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( ( (BRouterActivity) getContext() ).getStorageDirectories (), guessBaseDir(), "Cannot access " + baseDir.getAbsolutePath () + "; select another");
|
||||
}
|
||||
|
@ -219,22 +222,17 @@ public class BRouterView extends View
|
|||
waitingForMigration = false;
|
||||
}
|
||||
|
||||
int deviceLevel = android.os.Build.VERSION.SDK_INT;
|
||||
int deviceLevel = Build.VERSION.SDK_INT;
|
||||
int targetSdkVersion = getContext().getApplicationInfo().targetSdkVersion;
|
||||
canAccessSdCard = deviceLevel < 23 || targetSdkVersion == 19;
|
||||
if ( canAccessSdCard )
|
||||
{
|
||||
cor = CoordinateReader.obtainValidReader( basedir, segmentDir );
|
||||
canAccessSdCard = true;
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q && !Environment.isExternalStorageLegacy()) {
|
||||
canAccessSdCard = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (deviceLevel >= android.os.Build.VERSION_CODES.Q) {
|
||||
cor = new CoordinateReaderInternal(basedir);
|
||||
} else {
|
||||
cor = new CoordinateReaderNone();
|
||||
}
|
||||
cor.readFromTo();
|
||||
if (ContextCompat.checkSelfPermission(getContext(), Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
|
||||
canAccessSdCard = false;
|
||||
}
|
||||
|
||||
cor = CoordinateReader.obtainValidReader(basedir, segmentDir, canAccessSdCard);
|
||||
|
||||
wpList = cor.waypoints;
|
||||
nogoList = cor.nogopoints;
|
||||
|
@ -582,7 +580,7 @@ public class BRouterView extends View
|
|||
for ( int i = 0; i < wpList.size(); i++ )
|
||||
msg += ( i > 0 ? "->" : "" ) + wpList.get( i ).name;
|
||||
}
|
||||
( (BRouterActivity) getContext() ).showResultMessage( "Select Action", msg, cor instanceof CoordinateReaderNone ? -2 : wpList.size() );
|
||||
( (BRouterActivity) getContext() ).showResultMessage( "Select Action", msg, wpList.size() );
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -149,76 +149,70 @@ public abstract class CoordinateReader
|
|||
protected abstract void readPointmap() throws Exception;
|
||||
|
||||
|
||||
public static CoordinateReader obtainValidReader( String basedir, File segmentDir ) throws Exception
|
||||
public static CoordinateReader obtainValidReader( String basedir, File segmentDir, boolean canAccessSdCard ) throws Exception
|
||||
{
|
||||
return obtainValidReader( basedir, segmentDir, false );
|
||||
return obtainValidReader( basedir, segmentDir, canAccessSdCard, false );
|
||||
}
|
||||
|
||||
public static CoordinateReader obtainValidReader( String basedir, File segmentDir, boolean nogosOnly ) throws Exception
|
||||
public static CoordinateReader obtainValidReader( String basedir, File segmentDir, boolean canAccessSdCard, boolean nogosOnly ) throws Exception
|
||||
{
|
||||
CoordinateReader cor = null;
|
||||
ArrayList<CoordinateReader> rl = new ArrayList<CoordinateReader>();
|
||||
|
||||
AppLogger.log( "adding standard maptool-base: " + basedir );
|
||||
rl.add( new CoordinateReaderOsmAnd( basedir ) );
|
||||
rl.add( new CoordinateReaderLocus( basedir ) );
|
||||
rl.add( new CoordinateReaderOrux( basedir ) );
|
||||
if (canAccessSdCard) {
|
||||
AppLogger.log("adding standard maptool-base: " + basedir);
|
||||
rl.add(new CoordinateReaderOsmAnd(basedir));
|
||||
rl.add(new CoordinateReaderLocus(basedir));
|
||||
rl.add(new CoordinateReaderOrux(basedir));
|
||||
|
||||
// eventually add standard-sd
|
||||
File standardbase = Environment.getExternalStorageDirectory();
|
||||
if ( standardbase != null )
|
||||
{
|
||||
String base2 = standardbase.getAbsolutePath();
|
||||
if ( !base2.equals( basedir ) )
|
||||
{
|
||||
AppLogger.log( "adding internal sd maptool-base: " + base2 );
|
||||
rl.add( new CoordinateReaderOsmAnd( base2 ) );
|
||||
rl.add( new CoordinateReaderLocus( base2 ) );
|
||||
rl.add( new CoordinateReaderOrux( base2 ) );
|
||||
}
|
||||
}
|
||||
|
||||
// eventually add explicit directory
|
||||
File additional = RoutingHelper.getAdditionalMaptoolDir( segmentDir );
|
||||
if ( additional != null )
|
||||
{
|
||||
String base3 = additional.getAbsolutePath();
|
||||
|
||||
AppLogger.log( "adding maptool-base from storage-config: " + base3 );
|
||||
|
||||
rl.add( new CoordinateReaderOsmAnd( base3 ) );
|
||||
rl.add( new CoordinateReaderOsmAnd( base3, true ) );
|
||||
rl.add( new CoordinateReaderLocus( base3 ) );
|
||||
rl.add( new CoordinateReaderOrux( base3 ) );
|
||||
}
|
||||
|
||||
long tmax = 0;
|
||||
for ( CoordinateReader r : rl )
|
||||
{
|
||||
if ( AppLogger.isLogging() )
|
||||
{
|
||||
AppLogger.log( "reading timestamp at systime " + new Date() );
|
||||
}
|
||||
|
||||
long t = r.getTimeStamp();
|
||||
|
||||
if ( t != 0 )
|
||||
{
|
||||
if ( AppLogger.isLogging() )
|
||||
{
|
||||
AppLogger.log( "found coordinate source at " + r.basedir + r.rootdir + " with timestamp " + new Date( t ) );
|
||||
// eventually add standard-sd
|
||||
File standardbase = Environment.getExternalStorageDirectory();
|
||||
if (standardbase != null) {
|
||||
String base2 = standardbase.getAbsolutePath();
|
||||
if (!base2.equals(basedir)) {
|
||||
AppLogger.log("adding internal sd maptool-base: " + base2);
|
||||
rl.add(new CoordinateReaderOsmAnd(base2));
|
||||
rl.add(new CoordinateReaderLocus(base2));
|
||||
rl.add(new CoordinateReaderOrux(base2));
|
||||
}
|
||||
}
|
||||
|
||||
if ( t > tmax )
|
||||
{
|
||||
tmax = t;
|
||||
cor = r;
|
||||
// eventually add explicit directory
|
||||
File additional = RoutingHelper.getAdditionalMaptoolDir(segmentDir);
|
||||
if (additional != null) {
|
||||
String base3 = additional.getAbsolutePath();
|
||||
|
||||
AppLogger.log("adding maptool-base from storage-config: " + base3);
|
||||
|
||||
rl.add(new CoordinateReaderOsmAnd(base3));
|
||||
rl.add(new CoordinateReaderOsmAnd(base3, true));
|
||||
rl.add(new CoordinateReaderLocus(base3));
|
||||
rl.add(new CoordinateReaderOrux(base3));
|
||||
}
|
||||
|
||||
long tmax = 0;
|
||||
for (CoordinateReader r : rl) {
|
||||
if (AppLogger.isLogging()) {
|
||||
AppLogger.log("reading timestamp at systime " + new Date());
|
||||
}
|
||||
|
||||
long t = r.getTimeStamp();
|
||||
|
||||
if (t != 0) {
|
||||
if (AppLogger.isLogging()) {
|
||||
AppLogger.log("found coordinate source at " + r.basedir + r.rootdir + " with timestamp " + new Date(t));
|
||||
}
|
||||
}
|
||||
|
||||
if (t > tmax) {
|
||||
tmax = t;
|
||||
cor = r;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( cor == null )
|
||||
{
|
||||
cor = new CoordinateReaderNone();
|
||||
cor = new CoordinateReaderInternal(basedir);
|
||||
}
|
||||
cor.nogosOnly = nogosOnly;
|
||||
cor.readFromTo();
|
||||
|
|
|
@ -1,32 +0,0 @@
|
|||
package btools.routingapp;
|
||||
|
||||
|
||||
/**
|
||||
* Dummy coordinate reader if none found
|
||||
*/
|
||||
public class CoordinateReaderNone extends CoordinateReader
|
||||
{
|
||||
public CoordinateReaderNone()
|
||||
{
|
||||
super( "" );
|
||||
rootdir = "none";
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getTimeStamp() throws Exception
|
||||
{
|
||||
return 0L;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTurnInstructionMode()
|
||||
{
|
||||
return 0; // none
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readPointmap() throws Exception
|
||||
{
|
||||
}
|
||||
|
||||
}
|
|
@ -58,10 +58,10 @@ distributions {
|
|||
include 'readmes/*'
|
||||
include 'profiles2/*'
|
||||
}
|
||||
from ('../brouter-routing-app/build/outputs/apk/api10/release') {
|
||||
from ('../brouter-routing-app/build/outputs/apk/api19/release') {
|
||||
include '*.apk'
|
||||
}
|
||||
from ('../brouter-routing-app/build/outputs/apk/api19/release') {
|
||||
from ('../brouter-routing-app/build/outputs/apk/api30/release') {
|
||||
include '*.apk'
|
||||
}
|
||||
from ('../brouter-server/build/libs') {
|
||||
|
|
Loading…
Reference in a new issue