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

@ -178,9 +178,11 @@ public class MainActivity extends CompatActivity implements SwipeRefreshLayout.O
if (!NotificationType.NO_INTERNET.shouldRemove()) { if (!NotificationType.NO_INTERNET.shouldRemove()) {
moduleViewListBuilder.addNotification(NotificationType.NO_INTERNET); moduleViewListBuilder.addNotification(NotificationType.NO_INTERNET);
} else { } 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); moduleViewListBuilder.addNotification(NotificationType.UPDATE_AVAILABLE);
if (AppUpdateManager.getAppUpdateManager().isLastCheckSuccess()) if (!BuildConfig.ENABLE_AUTO_UPDATER || appUpdateManager.isLastCheckSuccess())
AppUpdateManager.getAppUpdateManager().checkUpdateCompat(); AppUpdateManager.getAppUpdateManager().checkUpdateCompat();
if (max != 0) { if (max != 0) {
int current = 0; int current = 0;

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

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