Remove WpDatabaseScanner

This commit is contained in:
Manuel Fuhr 2022-05-04 17:01:37 +02:00
parent b5895e1fd8
commit fc524fb4db
3 changed files with 2 additions and 213 deletions

View file

@ -45,11 +45,9 @@ public class BRouterActivity extends AppCompatActivity implements ActivityCompat
private static final int DIALOG_SELECTBASEDIR_ID = 11; private static final int DIALOG_SELECTBASEDIR_ID = 11;
private static final int DIALOG_MAINACTION_ID = 12; private static final int DIALOG_MAINACTION_ID = 12;
private static final int DIALOG_OLDDATAHINT_ID = 13; private static final int DIALOG_OLDDATAHINT_ID = 13;
private static final int DIALOG_SHOW_WP_HELP_ID = 14;
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_REPEAT_TIMEOUT_HELP_ID = 16;
private static final int DIALOG_SHOW_API23_HELP_ID = 17; private static final int DIALOG_SHOW_API23_HELP_ID = 17;
private final Set<Integer> dialogIds = new HashSet<>();
private BRouterView mBRouterView; private BRouterView mBRouterView;
private PowerManager mPowerManager; private PowerManager mPowerManager;
private WakeLock mWakeLock; private WakeLock mWakeLock;
@ -66,8 +64,6 @@ public class BRouterActivity extends AppCompatActivity implements ActivityCompat
private String[] availableVias; private String[] availableVias;
private Set<String> selectedVias; private Set<String> selectedVias;
private List<OsmNodeNamed> nogoList; private List<OsmNodeNamed> nogoList;
private String maptoolDirCandidate;
private final Set<Integer> dialogIds = new HashSet<>();
private String errorMessage; private String errorMessage;
private String title; private String title;
private int wpCount; private int wpCount;
@ -148,27 +144,6 @@ public class BRouterActivity extends AppCompatActivity implements ActivityCompat
} }
}); });
return builder.create(); return builder.create();
case DIALOG_SHOW_WP_HELP_ID:
builder
.setTitle("No Waypoint Database found")
.setMessage(
"The simple scan did not find any map-tool directory including a waypoint database. "
+ "Reason could be there is no map-tool installed (osmand, locus or oruxmaps), or at an "
+ "unusual path, or it contains no waypoints yet. That's o.k. if you want to use BRouter "
+ "in server-mode only - in that case you can still use the 'Server-Mode' button to "
+ "configure the profile mapping. But you will not be able to use nogo-points or do "
+ "long distance calculations. If you know the path to your map-tool, you can manually "
+ "configure it in 'storageconfig.txt'. Or I can do an extended scan searching "
+ "your sd-card for a valid waypoint database").setPositiveButton("Scan", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
mBRouterView.startWpDatabaseScan();
}
}).setNegativeButton("Exit", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
finish();
}
});
return builder.create();
case DIALOG_SHOW_API23_HELP_ID: case DIALOG_SHOW_API23_HELP_ID:
builder builder
.setTitle("Android >=6 limitations") .setTitle("Android >=6 limitations")
@ -202,20 +177,6 @@ public class BRouterActivity extends AppCompatActivity implements ActivityCompat
} }
}); });
return builder.create(); return builder.create();
case DIALOG_SHOW_WP_SCANRESULT_ID:
builder
.setTitle("Waypoint Database ")
.setMessage("Found Waypoint-Database(s) for maptool-dir: " + maptoolDirCandidate
+ " Configure that?").setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
mBRouterView.saveMaptoolDir(maptoolDirCandidate);
}
}).setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
finish();
}
});
return builder.create();
case DIALOG_OLDDATAHINT_ID: case DIALOG_OLDDATAHINT_ID:
builder builder
.setTitle("Local setup needs reset") .setTitle("Local setup needs reset")
@ -448,22 +409,13 @@ public class BRouterActivity extends AppCompatActivity implements ActivityCompat
} }
public void showWaypointDatabaseHelp() { public void showWaypointDatabaseHelp() {
if (mBRouterView.canAccessSdCard) {
showNewDialog(DIALOG_SHOW_WP_HELP_ID);
} else {
showNewDialog(DIALOG_SHOW_API23_HELP_ID); showNewDialog(DIALOG_SHOW_API23_HELP_ID);
} }
}
public void showRepeatTimeoutHelp() { public void showRepeatTimeoutHelp() {
showNewDialog(DIALOG_SHOW_REPEAT_TIMEOUT_HELP_ID); showNewDialog(DIALOG_SHOW_REPEAT_TIMEOUT_HELP_ID);
} }
public void showWpDatabaseScanSuccess(String bestGuess) {
maptoolDirCandidate = bestGuess;
showNewDialog(DIALOG_SHOW_WP_SCANRESULT_ID);
}
public void selectNogos(List<OsmNodeNamed> nogoList) { public void selectNogos(List<OsmNodeNamed> nogoList) {
this.nogoList = nogoList; this.nogoList = nogoList;
showDialog(DIALOG_NOGOSELECT_ID); showDialog(DIALOG_NOGOSELECT_ID);

View file

@ -75,7 +75,6 @@ public class BRouterView extends View {
private boolean needsViaSelection; private boolean needsViaSelection;
private boolean needsNogoSelection; private boolean needsNogoSelection;
private boolean needsWaypointSelection; private boolean needsWaypointSelection;
private WpDatabaseScanner dataBaseScanner;
private long lastDataTime = System.currentTimeMillis(); private long lastDataTime = System.currentTimeMillis();
private CoordinateReader cor; private CoordinateReader cor;
private int[] imgPixels; private int[] imgPixels;
@ -428,17 +427,6 @@ public class BRouterView extends View {
} }
} }
public void startWpDatabaseScan() {
dataBaseScanner = new WpDatabaseScanner();
dataBaseScanner.start();
invalidate();
}
public void saveMaptoolDir(String dir) {
ConfigMigration.saveAdditionalMaptoolDir(segmentDir, dir);
((BRouterActivity) getContext()).showResultMessage("Success", "please restart to use new config", -1);
}
public void finishWaypointSelection() { public void finishWaypointSelection() {
needsWaypointSelection = false; needsWaypointSelection = false;
} }
@ -715,51 +703,7 @@ public class BRouterView extends View {
} }
} }
private void showDatabaseScanning(Canvas canvas) {
try {
Thread.sleep(100);
} catch (InterruptedException ignored) {
}
Paint paint1 = new Paint();
paint1.setColor(Color.WHITE);
paint1.setTextSize(20);
Paint paint2 = new Paint();
paint2.setColor(Color.WHITE);
paint2.setTextSize(10);
String currentDir = dataBaseScanner.getCurrentDir();
String bestGuess = dataBaseScanner.getBestGuess();
if (currentDir == null) // scan finished
{
if (bestGuess.length() == 0) {
((BRouterActivity) getContext()).showErrorMessage("scan did not find any possible waypoint database");
} else {
((BRouterActivity) getContext()).showWpDatabaseScanSuccess(bestGuess);
}
cr = null;
dataBaseScanner = null;
waitingForSelection = true;
return;
}
canvas.drawText("Scanning:", 10, 30, paint1);
canvas.drawText(currentDir, 0, 60, paint2);
canvas.drawText("Best Guess:", 10, 90, paint1);
canvas.drawText(bestGuess, 0, 120, paint2);
canvas.drawText("Last Error:", 10, 150, paint1);
canvas.drawText(dataBaseScanner.getLastError(), 0, 180, paint2);
invalidate();
}
private void _onDraw(Canvas canvas) { private void _onDraw(Canvas canvas) {
if (dataBaseScanner != null) {
showDatabaseScanning(canvas);
return;
}
if (waitingForSelection) if (waitingForSelection)
return; return;

View file

@ -1,107 +0,0 @@
package btools.routingapp;
import java.io.File;
public class WpDatabaseScanner extends Thread {
private String currentDir = "";
private String bestGuess = "";
private String lastError = "";
private Object currentDirSync = new Object();
private long maxtimestamp = 0;
public String getCurrentDir() {
synchronized (currentDirSync) {
return currentDir;
}
}
private void setCurrentDir(String dir) {
synchronized (currentDirSync) {
currentDir = dir;
}
}
public String getBestGuess() {
synchronized (currentDirSync) {
return bestGuess;
}
}
public String getLastError() {
synchronized (currentDirSync) {
return lastError;
}
}
private void setLastError(String msg) {
synchronized (currentDirSync) {
lastError = msg;
}
}
private static String[] vetos = new String[]{"dev", "sys", "system", "proc", "etc", "init", "d", "cache", "acct", "data"};
private void scan(File dir, int level) {
if (level > 8) {
return;
}
try {
if (dir.isDirectory()) {
if (level == 1) {
String name = dir.getName();
for (String veto : vetos) {
if (veto.equals(name)) {
return;
}
}
}
testPath(dir.getPath());
File[] childs = dir.listFiles();
if (childs == null) {
return;
}
for (File child : childs) {
scan(child, level + 1);
}
}
} catch (Exception e) {
setLastError(e.toString());
}
}
private void testPath(String path) throws Exception {
setCurrentDir(path);
testReader(new CoordinateReaderOsmAnd(path));
testReader(new CoordinateReaderOsmAnd(path, true));
testReader(new CoordinateReaderLocus(path));
testReader(new CoordinateReaderOrux(path));
}
private void testReader(CoordinateReader cor) throws Exception {
long ts = cor.getTimeStamp();
if (ts > maxtimestamp) {
maxtimestamp = ts;
synchronized (currentDirSync) {
bestGuess = cor.basedir;
}
} else if (ts > 0 && ts == maxtimestamp) {
synchronized (currentDirSync) {
if (cor.basedir.length() < bestGuess.length()) {
bestGuess = cor.basedir;
}
}
}
}
@Override
public void run() {
scan(new File("/"), 0);
setCurrentDir(null);
}
}