Improve detection of sdcard write access

This allows reading waypoints from apps on till devices running API 28
if they store their files in a accessible path (not Android/data). It
even works for devices running API 30 if they installed it as an update.
This commit is contained in:
Manuel Fuhr 2021-11-02 17:24:50 +01:00
parent 12148f6a5d
commit dc95984199
2 changed files with 28 additions and 19 deletions

View file

@ -222,20 +222,21 @@ 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();
}
if (ContextCompat.checkSelfPermission(getContext(), Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
canAccessSdCard = false;
}
if (canAccessSdCard) {
cor = CoordinateReader.obtainValidReader(basedir, segmentDir);
}
else {
cor = new CoordinateReaderInternal(basedir);
cor.readFromTo();
}