Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

App version check #526

Merged
merged 2 commits into from
Apr 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ public final class BExpressionMetaData {
private static final String VERSION_TAG = "---lookupversion:";
private static final String MINOR_VERSION_TAG = "---minorversion:";
private static final String VARLENGTH_TAG = "---readvarlength";
private static final String MIN_APP_VERSION_TAG = "---minappversion:";

public short lookupVersion = -1;
public short lookupMinorVersion = -1;
public short minAppVersion = -1;

private Map<String, BExpressionContext> listeners = new HashMap<String, BExpressionContext>();

Expand Down Expand Up @@ -51,6 +53,10 @@ public void readMetaData(File lookupsFile) {
lookupMinorVersion = Short.parseShort(line.substring(MINOR_VERSION_TAG.length()));
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...
{
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public class BInstallerActivity extends AppCompatActivity {
private static final int DIALOG_CONFIRM_DELETE_ID = 1;
private static final int DIALOG_CONFIRM_NEXTSTEPS_ID = 2;
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;

Expand Down Expand Up @@ -309,7 +310,9 @@ private void startObserver(WorkInfo workInfo) {
}
}

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();
} else if (error != null && error.startsWith("Version diffs")) {
showConfirmGetDiffs();
Expand Down Expand Up @@ -393,7 +396,16 @@ public void onClick(DialogInterface dialog, int id) {
}
});
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:
return null;
}
Expand All @@ -416,6 +428,10 @@ private void showConfirmGetDiffs() {
showADialog(DIALOG_CONFIRM_GETDIFFS_ID);
}

private void showAppUpdate() {
showADialog(DIALOG_NEW_APP_NEEDED_ID);
}


private void scanExistingFiles() {
mBInstallerView.clearAllTilesStatus(MASK_CURRENT_RD5 | MASK_INSTALLED_RD5 | MASK_DELETED_RD5 | MASK_SELECTED_RD5);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public String getTrackFromParams(Bundle params) throws RemoteException {
worker.baseDir = baseDir;
worker.segmentDir = new File(baseDir, "brouter/segments4");

String remoteProfile = params.getString("remoteProfile");
String remoteProfile = params.getString("remoteProfile", null);

if (remoteProfile == null) {
remoteProfile = checkForTestDummy(baseDir);
Expand All @@ -77,7 +77,6 @@ public String getTrackFromParams(Bundle params) throws RemoteException {
} else {
try {
readNogos(worker, baseDir);
errMsg = getConfigFromModeForProfile(worker, baseDir, profile);
} catch (Exception e) {
errMsg = e.getLocalizedMessage();
}
Expand Down Expand Up @@ -115,20 +114,9 @@ public String getTrackFromParams(Bundle params) throws RemoteException {
}
}

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) {
boolean isFast = false;
String profile = null;
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;
}
boolean isFast = "1".equals(fast) || "true".equals(fast) || "yes".equals(fast);
String mode_key = mode + "_" + (isFast ? "fast" : "short");

BufferedReader br = null;
try {
Expand All @@ -139,9 +127,7 @@ private String getConfigFromMode(BRouterWorker worker, String baseDir, String mo
if (line == null)
break;
ServiceModeConfig smc = new ServiceModeConfig(line);
if (profile!=null && !smc.profile.equals(profile))
continue;
else if (profile==null && !smc.mode.equals(mode_key))
if (!smc.mode.equals(mode_key))
continue;
worker.profileName = smc.profile;
worker.profilePath = baseDir + "/brouter/profiles2/" + smc.profile + ".brf";
Expand Down Expand Up @@ -176,7 +162,7 @@ else if (profile==null && !smc.mode.equals(mode_key))
} 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ public class DownloadWorker extends Worker {
private List<URL> done = new ArrayList<>();

int version = -1;
int appversion = -1;
String errorCode = null;

public DownloadWorker(
@NonNull Context context,
Expand Down Expand Up @@ -171,7 +173,7 @@ public Result doWork() {
try {
if (DEBUG) Log.d(LOG_TAG, "Download lookup & profiles");
if (!downloadLookup()) {
output.putString(KEY_OUTPUT_ERROR, "Version error");
output.putString(KEY_OUTPUT_ERROR, (errorCode != null ? errorCode : "Version error"));
return Result.failure(output.build());
}

Expand Down Expand Up @@ -229,11 +231,13 @@ public boolean accept(File file) {
private boolean downloadLookup() throws IOException, InterruptedException {
String[] lookups = mServerConfig.getLookups();
for (String fileName : lookups) {
appversion = BuildConfig.VERSION_CODE;
if (fileName.length() > 0) {
File lookupFile = new File(baseDir, PROFILES_DIR + fileName);
BExpressionMetaData meta = new BExpressionMetaData();
meta.readMetaData(lookupFile);
version = meta.lookupVersion;
int newappversion = meta.minAppVersion;

int size = (int) (lookupFile.exists() ? lookupFile.length() : 0);
File tmplookupFile = new File(baseDir, PROFILES_DIR + fileName + ".tmp");
Expand All @@ -244,6 +248,7 @@ private boolean downloadLookup() throws IOException, InterruptedException {
versionChanged = true;
meta.readMetaData(lookupFile);
version = meta.lookupVersion;
newappversion = meta.minAppVersion;
} else {
String lookupLocation = mServerConfig.getLookupUrl() + fileName;
URL lookupUrl = new URL(lookupLocation);
Expand All @@ -252,12 +257,22 @@ private boolean downloadLookup() throws IOException, InterruptedException {
downloadProgressListener.onDownloadFinished();
done.add(lookupUrl);
}
if (changed && downloadAll == VALUE_SEGMENT_PARTS) {
int newversion = version;
if (changed) {
meta = new BExpressionMetaData();
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 (version != newversion) {
errorCode = "Version error";
return false;
}
} else if (changed) {
Expand Down