mirror of
https://github.com/oxen-io/session-android.git
synced 2025-06-09 14:58:34 +00:00
Clean up website auto-update APKs.
I think previously we thought that because we always used the same filename, that we were just overwring the same file repeatedly. However, DownloadManager will actually append numbers to a filename instead of overwriting, so we were generating a ton of files. Now we just clear out any previous files before downloading a new one. Related to #9033
This commit is contained in:
parent
c1e6b6b086
commit
058c25808b
@ -25,9 +25,12 @@ import org.thoughtcrime.securesms.util.Hex;
|
||||
import org.thoughtcrime.securesms.util.JsonUtils;
|
||||
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.security.MessageDigest;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
@ -153,6 +156,8 @@ public class UpdateApkJob extends BaseJob {
|
||||
}
|
||||
|
||||
private void handleDownloadStart(String uri, String versionName, byte[] digest) {
|
||||
clearPreviousDownloads(context);
|
||||
|
||||
DownloadManager downloadManager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
|
||||
DownloadManager.Request downloadRequest = new DownloadManager.Request(Uri.parse(uri));
|
||||
|
||||
@ -203,6 +208,23 @@ public class UpdateApkJob extends BaseJob {
|
||||
}
|
||||
}
|
||||
|
||||
private static void clearPreviousDownloads(@NonNull Context context) {
|
||||
File directory = context.getExternalFilesDir(null);
|
||||
|
||||
if (directory == null) {
|
||||
Log.w(TAG, "Failed to read external files directory.");
|
||||
return;
|
||||
}
|
||||
|
||||
for (File file : directory.listFiles()) {
|
||||
if (file.getName().startsWith("signal-update")) {
|
||||
if (file.delete()) {
|
||||
Log.d(TAG, "Deleted " + file.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static class UpdateDescriptor {
|
||||
@JsonProperty
|
||||
private int versionCode;
|
||||
|
Loading…
x
Reference in New Issue
Block a user