Minor update/fixes to previous contributions.

pull/27/head
Fox2Code 3 years ago
parent 45d647953f
commit a847ebd72e

@ -142,18 +142,26 @@ public class AppUpdateManager {
.getBytes(StandardCharsets.UTF_8);
this.parseCompatibilityFlags(new ByteArrayInputStream(rawData));
Files.write(compatFile, rawData);
if (!BuildConfig.ENABLE_AUTO_UPDATER)
this.lastCheckSuccess = true;
} catch (Exception e) {
if (!BuildConfig.ENABLE_AUTO_UPDATER)
this.lastCheckSuccess = false;
Log.e("AppUpdateManager", "Failed to update compat list", e);
}
}
public boolean peekShouldUpdate() {
if (!BuildConfig.ENABLE_AUTO_UPDATER)
return false;
return !(BuildConfig.VERSION_NAME.equals(this.latestRelease) ||
(this.preReleaseNewer &&
BuildConfig.VERSION_NAME.equals(this.latestPreRelease)));
}
public boolean peekHasUpdate() {
if (!BuildConfig.ENABLE_AUTO_UPDATER)
return false;
return !BuildConfig.VERSION_NAME.equals(this.preReleaseNewer ?
this.latestPreRelease : this.latestRelease);
}

@ -178,9 +178,11 @@ public class MainActivity extends CompatActivity implements SwipeRefreshLayout.O
if (!NotificationType.NO_INTERNET.shouldRemove()) {
moduleViewListBuilder.addNotification(NotificationType.NO_INTERNET);
} else {
if (AppUpdateManager.getAppUpdateManager().checkUpdate(true))
// Compatibility data still needs to be updated
AppUpdateManager appUpdateManager = AppUpdateManager.getAppUpdateManager();
if (BuildConfig.ENABLE_AUTO_UPDATER && appUpdateManager.checkUpdate(true))
moduleViewListBuilder.addNotification(NotificationType.UPDATE_AVAILABLE);
if (AppUpdateManager.getAppUpdateManager().isLastCheckSuccess())
if (!BuildConfig.ENABLE_AUTO_UPDATER || appUpdateManager.isLastCheckSuccess())
AppUpdateManager.getAppUpdateManager().checkUpdateCompat();
if (max != 0) {
int current = 0;

@ -219,7 +219,7 @@ public class AndroidacyWebAPI {
this.forceQuitRaw("Non Androidacy module link used on Androidacy");
return;
}
if (checksum != null) checksum = checksum.trim();
checksum = Hashes.checkSumFormat(checksum);
if (checksum == null || checksum.isEmpty()) {
Log.w(TAG, "Androidacy WebView didn't provided a checksum!");
} else if (!Hashes.checkSumValid(checksum)) {
@ -261,7 +261,7 @@ public class AndroidacyWebAPI {
this.forceQuitRaw("Non Androidacy module link used on Androidacy");
return;
}
if (checksum != null) checksum = checksum.trim();
checksum = Hashes.checkSumFormat(checksum);
if (checksum == null || checksum.isEmpty()) {
Log.w(TAG, "Androidacy WebView didn't provided a checksum!");
} else if (!Hashes.checkSumValid(checksum)) {

@ -5,10 +5,12 @@ import android.util.Log;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Locale;
import java.util.regex.Pattern;
public class Hashes {
private static final String TAG = "Hashes";
private static final char[] HEX_ARRAY = "0123456789abcdef".toCharArray();
private static final Pattern nonAlphaNum = Pattern.compile("[^a-zA-Z0-9]");
public static String bytesToHex(byte[] bytes) {
char[] hexChars = new char[bytes.length * 2];
for (int j = 0; j < bytes.length; j++) {
@ -65,8 +67,7 @@ public class Hashes {
*/
public static boolean checkSumMatch(byte[] data, String checksum) {
String hash;
// Remove all non-alphanumeric characters
checksum = checksum.replaceAll("[^a-zA-Z0-9]", "");
if (checksum == null) return false;
switch (checksum.length()) {
case 0:
return true; // No checksum
@ -124,4 +125,10 @@ public class Hashes {
return "SHA-512";
}
}
public static String checkSumFormat(String checksum) {
if (checksum == null) return null;
// Remove all non-alphanumeric characters
return nonAlphaNum.matcher(checksum.trim()).replaceAll("");
}
}

Loading…
Cancel
Save