add app version check to downloader
This commit is contained in:
parent
2eb47300cf
commit
fa64ff9192
3 changed files with 42 additions and 5 deletions
|
@ -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;
|
||||||
|
|
|
@ -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);
|
||||||
|
|
|
@ -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) {
|
||||||
|
|
Loading…
Reference in a new issue