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:
Greyson Parrelli 2019-12-03 00:00:08 -05:00
parent c1e6b6b086
commit 058c25808b

View File

@ -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;