Support for website distribution build with auto-updating APK

// FREEBIE
This commit is contained in:
Moxie Marlinspike
2017-02-26 14:36:43 -08:00
parent 79e925051a
commit 9b8719e2d5
11 changed files with 561 additions and 3 deletions

View File

@@ -1,6 +1,10 @@
package org.thoughtcrime.securesms.util;
import java.io.FileDescriptor;
import java.io.FileInputStream;
import java.io.IOException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
public class FileUtils {
@@ -10,4 +14,20 @@ public class FileUtils {
public static native int getFileDescriptorOwner(FileDescriptor fileDescriptor);
public static byte[] getFileDigest(FileInputStream fin) throws IOException {
try {
MessageDigest digest = MessageDigest.getInstance("SHA256");
byte[] buffer = new byte[4096];
int read = 0;
while ((read = fin.read(buffer, 0, buffer.length)) != -1) {
digest.update(buffer, 0, read);
}
return digest.digest();
} catch (NoSuchAlgorithmException e) {
throw new AssertionError(e);
}
}
}

View File

@@ -73,6 +73,9 @@ public class TextSecurePreferences {
private static final String PROMPTED_SHARE_PREF = "pref_prompted_share";
private static final String SIGNALING_KEY_PREF = "pref_signaling_key";
private static final String DIRECTORY_FRESH_TIME_PREF = "pref_directory_refresh_time";
private static final String UPDATE_APK_REFRESH_TIME_PREF = "pref_update_apk_refresh_time";
private static final String UPDATE_APK_DOWNLOAD_ID = "pref_update_apk_download_id";
private static final String UPDATE_APK_DIGEST = "pref_update_apk_digest";
private static final String SIGNED_PREKEY_ROTATION_TIME_PREF = "pref_signed_pre_key_rotation_time";
private static final String IN_THREAD_NOTIFICATION_PREF = "pref_key_inthread_notifications";
private static final String BLOCKING_IDENTITY_CHANGES_PREF = "pref_blocking_identity_changes";
@@ -264,6 +267,30 @@ public class TextSecurePreferences {
setLongPreference(context, DIRECTORY_FRESH_TIME_PREF, value);
}
public static long getUpdateApkRefreshTime(Context context) {
return getLongPreference(context, UPDATE_APK_REFRESH_TIME_PREF, 0L);
}
public static void setUpdateApkRefreshTime(Context context, long value) {
setLongPreference(context, UPDATE_APK_REFRESH_TIME_PREF, value);
}
public static void setUpdateApkDownloadId(Context context, long value) {
setLongPreference(context, UPDATE_APK_DOWNLOAD_ID, value);
}
public static long getUpdateApkDownloadId(Context context) {
return getLongPreference(context, UPDATE_APK_DOWNLOAD_ID, -1);
}
public static void setUpdateApkDigest(Context context, String value) {
setStringPreference(context, UPDATE_APK_DIGEST, value);
}
public static String getUpdateApkDigest(Context context) {
return getStringPreference(context, UPDATE_APK_DIGEST, null);
}
public static String getLocalNumber(Context context) {
return getStringPreference(context, LOCAL_NUMBER_PREF, "No Stored Number");
}