Merge pull request #526 from afischerdev/app-version-check

App version check

@polyscias 
Please keep on testing. We could change on problems later.
This commit is contained in:
afischerdev 2023-04-14 09:41:02 +02:00 committed by GitHub
commit 575c24c93d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 47 additions and 24 deletions

View file

@ -18,9 +18,11 @@ public final class BExpressionMetaData {
private static final String VERSION_TAG = "---lookupversion:"; private static final String VERSION_TAG = "---lookupversion:";
private static final String MINOR_VERSION_TAG = "---minorversion:"; private static final String MINOR_VERSION_TAG = "---minorversion:";
private static final String VARLENGTH_TAG = "---readvarlength"; private static final String VARLENGTH_TAG = "---readvarlength";
private static final String MIN_APP_VERSION_TAG = "---minappversion:";
public short lookupVersion = -1; public short lookupVersion = -1;
public short lookupMinorVersion = -1; public short lookupMinorVersion = -1;
public short minAppVersion = -1;
private Map<String, BExpressionContext> listeners = new HashMap<String, BExpressionContext>(); private Map<String, BExpressionContext> listeners = new HashMap<String, BExpressionContext>();
@ -51,6 +53,10 @@ public final class BExpressionMetaData {
lookupMinorVersion = Short.parseShort(line.substring(MINOR_VERSION_TAG.length())); lookupMinorVersion = Short.parseShort(line.substring(MINOR_VERSION_TAG.length()));
continue; continue;
} }
if (line.startsWith(MIN_APP_VERSION_TAG)) {
minAppVersion = Short.parseShort(line.substring(MIN_APP_VERSION_TAG.length()));
continue;
}
if (line.startsWith(VARLENGTH_TAG)) // tag removed... if (line.startsWith(VARLENGTH_TAG)) // tag removed...
{ {
continue; continue;

View file

@ -51,6 +51,7 @@ public class BInstallerActivity extends AppCompatActivity {
private static final int DIALOG_CONFIRM_DELETE_ID = 1; private static final int DIALOG_CONFIRM_DELETE_ID = 1;
private static final int DIALOG_CONFIRM_NEXTSTEPS_ID = 2; private static final int DIALOG_CONFIRM_NEXTSTEPS_ID = 2;
private static final int DIALOG_CONFIRM_GETDIFFS_ID = 3; private static final int DIALOG_CONFIRM_GETDIFFS_ID = 3;
private static final int DIALOG_NEW_APP_NEEDED_ID = 4;
public static final int MY_PERMISSIONS_REQUEST_NITIFICATION = 100; public static final int MY_PERMISSIONS_REQUEST_NITIFICATION = 100;
@ -309,7 +310,9 @@ public class BInstallerActivity extends AppCompatActivity {
} }
} }
if (error != null && error.startsWith("Version error")) { if (error != null && error.startsWith("error new app")) {
showAppUpdate();
} else if (error != null && error.startsWith("Version error")) {
showConfirmNextSteps(); showConfirmNextSteps();
} else if (error != null && error.startsWith("Version diffs")) { } else if (error != null && error.startsWith("Version diffs")) {
showConfirmGetDiffs(); showConfirmGetDiffs();
@ -393,7 +396,16 @@ public class BInstallerActivity extends AppCompatActivity {
} }
}); });
return builder.create(); return builder.create();
case DIALOG_NEW_APP_NEEDED_ID:
builder
.setTitle("App Version")
.setMessage("The new data version needs a new app. Please update BRouter first")
.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
finish();
}
});
return builder.create();
default: default:
return null; return null;
} }
@ -416,6 +428,10 @@ public class BInstallerActivity extends AppCompatActivity {
showADialog(DIALOG_CONFIRM_GETDIFFS_ID); showADialog(DIALOG_CONFIRM_GETDIFFS_ID);
} }
private void showAppUpdate() {
showADialog(DIALOG_NEW_APP_NEEDED_ID);
}
private void scanExistingFiles() { private void scanExistingFiles() {
mBInstallerView.clearAllTilesStatus(MASK_CURRENT_RD5 | MASK_INSTALLED_RD5 | MASK_DELETED_RD5 | MASK_SELECTED_RD5); mBInstallerView.clearAllTilesStatus(MASK_CURRENT_RD5 | MASK_INSTALLED_RD5 | MASK_DELETED_RD5 | MASK_SELECTED_RD5);

View file

@ -58,7 +58,7 @@ public class BRouterService extends Service {
worker.baseDir = baseDir; worker.baseDir = baseDir;
worker.segmentDir = new File(baseDir, "brouter/segments4"); worker.segmentDir = new File(baseDir, "brouter/segments4");
String remoteProfile = params.getString("remoteProfile"); String remoteProfile = params.getString("remoteProfile", null);
if (remoteProfile == null) { if (remoteProfile == null) {
remoteProfile = checkForTestDummy(baseDir); remoteProfile = checkForTestDummy(baseDir);
@ -77,7 +77,6 @@ public class BRouterService extends Service {
} else { } else {
try { try {
readNogos(worker, baseDir); readNogos(worker, baseDir);
errMsg = getConfigFromModeForProfile(worker, baseDir, profile);
} catch (Exception e) { } catch (Exception e) {
errMsg = e.getLocalizedMessage(); errMsg = e.getLocalizedMessage();
} }
@ -115,20 +114,9 @@ public class BRouterService extends Service {
} }
} }
private String getConfigFromModeForProfile(BRouterWorker worker, String baseDir, String profile) {
return getConfigFromMode(worker, baseDir, profile, null);
}
private String getConfigFromMode(BRouterWorker worker, String baseDir, String mode, String fast) { private String getConfigFromMode(BRouterWorker worker, String baseDir, String mode, String fast) {
boolean isFast = false; boolean isFast = "1".equals(fast) || "true".equals(fast) || "yes".equals(fast);
String profile = null; String mode_key = mode + "_" + (isFast ? "fast" : "short");
String mode_key = null;
if (fast != null) {
isFast = "1".equals(fast) || "true".equals(fast) || "yes".equals(fast);
mode_key = mode + "_" + (isFast ? "fast" : "short");
} else {
profile = mode;
}
BufferedReader br = null; BufferedReader br = null;
try { try {
@ -139,9 +127,7 @@ public class BRouterService extends Service {
if (line == null) if (line == null)
break; break;
ServiceModeConfig smc = new ServiceModeConfig(line); ServiceModeConfig smc = new ServiceModeConfig(line);
if (profile!=null && !smc.profile.equals(profile)) if (!smc.mode.equals(mode_key))
continue;
else if (profile==null && !smc.mode.equals(mode_key))
continue; continue;
worker.profileName = smc.profile; worker.profileName = smc.profile;
worker.profilePath = baseDir + "/brouter/profiles2/" + smc.profile + ".brf"; worker.profilePath = baseDir + "/brouter/profiles2/" + smc.profile + ".brf";
@ -176,7 +162,7 @@ public class BRouterService extends Service {
} catch (Exception ee) { } catch (Exception ee) {
} }
} }
return "no brouter service config found for mode " + (mode_key!=null?mode_key:profile); return "no brouter service config found for mode " + mode_key;
} }
private String getConfigForRemoteProfile(BRouterWorker worker, String baseDir, String remoteProfile) { private String getConfigForRemoteProfile(BRouterWorker worker, String baseDir, String remoteProfile) {

View file

@ -70,6 +70,8 @@ public class DownloadWorker extends Worker {
private List<URL> done = new ArrayList<>(); private List<URL> done = new ArrayList<>();
int version = -1; int version = -1;
int appversion = -1;
String errorCode = null;
public DownloadWorker( public DownloadWorker(
@NonNull Context context, @NonNull Context context,
@ -171,7 +173,7 @@ public class DownloadWorker extends Worker {
try { try {
if (DEBUG) Log.d(LOG_TAG, "Download lookup & profiles"); if (DEBUG) Log.d(LOG_TAG, "Download lookup & profiles");
if (!downloadLookup()) { if (!downloadLookup()) {
output.putString(KEY_OUTPUT_ERROR, "Version error"); output.putString(KEY_OUTPUT_ERROR, (errorCode != null ? errorCode : "Version error"));
return Result.failure(output.build()); return Result.failure(output.build());
} }
@ -229,11 +231,13 @@ public class DownloadWorker extends Worker {
private boolean downloadLookup() throws IOException, InterruptedException { private boolean downloadLookup() throws IOException, InterruptedException {
String[] lookups = mServerConfig.getLookups(); String[] lookups = mServerConfig.getLookups();
for (String fileName : lookups) { for (String fileName : lookups) {
appversion = BuildConfig.VERSION_CODE;
if (fileName.length() > 0) { if (fileName.length() > 0) {
File lookupFile = new File(baseDir, PROFILES_DIR + fileName); File lookupFile = new File(baseDir, PROFILES_DIR + fileName);
BExpressionMetaData meta = new BExpressionMetaData(); BExpressionMetaData meta = new BExpressionMetaData();
meta.readMetaData(lookupFile); meta.readMetaData(lookupFile);
version = meta.lookupVersion; version = meta.lookupVersion;
int newappversion = meta.minAppVersion;
int size = (int) (lookupFile.exists() ? lookupFile.length() : 0); int size = (int) (lookupFile.exists() ? lookupFile.length() : 0);
File tmplookupFile = new File(baseDir, PROFILES_DIR + fileName + ".tmp"); File tmplookupFile = new File(baseDir, PROFILES_DIR + fileName + ".tmp");
@ -244,6 +248,7 @@ public class DownloadWorker extends Worker {
versionChanged = true; versionChanged = true;
meta.readMetaData(lookupFile); meta.readMetaData(lookupFile);
version = meta.lookupVersion; version = meta.lookupVersion;
newappversion = meta.minAppVersion;
} else { } else {
String lookupLocation = mServerConfig.getLookupUrl() + fileName; String lookupLocation = mServerConfig.getLookupUrl() + fileName;
URL lookupUrl = new URL(lookupLocation); URL lookupUrl = new URL(lookupLocation);
@ -252,12 +257,22 @@ public class DownloadWorker extends Worker {
downloadProgressListener.onDownloadFinished(); downloadProgressListener.onDownloadFinished();
done.add(lookupUrl); done.add(lookupUrl);
} }
if (changed && downloadAll == VALUE_SEGMENT_PARTS) { int newversion = version;
if (changed) {
meta = new BExpressionMetaData(); meta = new BExpressionMetaData();
meta.readMetaData(tmplookupFile); meta.readMetaData(tmplookupFile);
int newversion = meta.lookupVersion; newversion = meta.lookupVersion;
newappversion = meta.minAppVersion;
}
if (newappversion != -1 && newappversion > appversion) {
if (DEBUG) Log.d(LOG_TAG, "app version old " + appversion + " new " + newappversion);
errorCode = "error new app";
return false;
}
if (changed && downloadAll == VALUE_SEGMENT_PARTS) {
if (DEBUG) Log.d(LOG_TAG, "version old " + version + " new " + newversion); if (DEBUG) Log.d(LOG_TAG, "version old " + version + " new " + newversion);
if (version != newversion) { if (version != newversion) {
errorCode = "Version error";
return false; return false;
} }
} else if (changed) { } else if (changed) {