mirror of
https://github.com/signalapp/Signal-Android.git
synced 2025-12-26 14:09:58 +00:00
Ensure network call resources are closed.
This commit is contained in:
committed by
Alex Hart
parent
1f581c074d
commit
7fafa4d5e6
@@ -95,13 +95,12 @@ public class RetrieveProfileAvatarJob extends BaseJob {
|
||||
return;
|
||||
}
|
||||
|
||||
File downloadDestination = File.createTempFile("avatar", "jpg", context.getCacheDir());
|
||||
File downloadDestination = File.createTempFile("avatar", "jpg", context.getCacheDir());
|
||||
|
||||
try {
|
||||
SignalServiceMessageReceiver receiver = ApplicationDependencies.getSignalServiceMessageReceiver();
|
||||
InputStream avatarStream = receiver.retrieveProfileAvatar(profileAvatar, downloadDestination, profileKey, AvatarHelper.AVATAR_DOWNLOAD_FAILSAFE_MAX_SIZE);
|
||||
SignalServiceMessageReceiver receiver = ApplicationDependencies.getSignalServiceMessageReceiver();
|
||||
|
||||
try {
|
||||
try (InputStream avatarStream = receiver.retrieveProfileAvatar(profileAvatar, downloadDestination, profileKey, AvatarHelper.AVATAR_DOWNLOAD_FAILSAFE_MAX_SIZE)) {
|
||||
AvatarHelper.setAvatar(context, recipient.getId(), avatarStream);
|
||||
|
||||
if (recipient.isSelf()) {
|
||||
|
||||
@@ -71,28 +71,29 @@ public class UpdateApkJob extends BaseJob {
|
||||
OkHttpClient client = new OkHttpClient();
|
||||
Request request = new Request.Builder().url(String.format("%s/latest.json", BuildConfig.NOPLAY_UPDATE_URL)).build();
|
||||
|
||||
Response response = client.newCall(request).execute();
|
||||
try (Response response = client.newCall(request).execute()) {
|
||||
|
||||
if (!response.isSuccessful()) {
|
||||
throw new IOException("Bad response: " + response.message());
|
||||
}
|
||||
if (!response.isSuccessful() || response.body() == null) {
|
||||
throw new IOException("Bad response: " + response.message());
|
||||
}
|
||||
|
||||
UpdateDescriptor updateDescriptor = JsonUtils.fromJson(response.body().string(), UpdateDescriptor.class);
|
||||
byte[] digest = Hex.fromStringCondensed(updateDescriptor.getDigest());
|
||||
UpdateDescriptor updateDescriptor = JsonUtils.fromJson(response.body().string(), UpdateDescriptor.class);
|
||||
byte[] digest = Hex.fromStringCondensed(updateDescriptor.getDigest());
|
||||
|
||||
Log.i(TAG, "Got descriptor: " + updateDescriptor);
|
||||
Log.i(TAG, "Got descriptor: " + updateDescriptor);
|
||||
|
||||
if (updateDescriptor.getVersionCode() > getVersionCode()) {
|
||||
DownloadStatus downloadStatus = getDownloadStatus(updateDescriptor.getUrl(), digest);
|
||||
if (updateDescriptor.getVersionCode() > getVersionCode()) {
|
||||
DownloadStatus downloadStatus = getDownloadStatus(updateDescriptor.getUrl(), digest);
|
||||
|
||||
Log.i(TAG, "Download status: " + downloadStatus.getStatus());
|
||||
Log.i(TAG, "Download status: " + downloadStatus.getStatus());
|
||||
|
||||
if (downloadStatus.getStatus() == DownloadStatus.Status.COMPLETE) {
|
||||
Log.i(TAG, "Download status complete, notifying...");
|
||||
handleDownloadNotify(downloadStatus.getDownloadId());
|
||||
} else if (downloadStatus.getStatus() == DownloadStatus.Status.MISSING) {
|
||||
Log.i(TAG, "Download status missing, starting download...");
|
||||
handleDownloadStart(updateDescriptor.getUrl(), updateDescriptor.getVersionName(), digest);
|
||||
if (downloadStatus.getStatus() == DownloadStatus.Status.COMPLETE) {
|
||||
Log.i(TAG, "Download status complete, notifying...");
|
||||
handleDownloadNotify(downloadStatus.getDownloadId());
|
||||
} else if (downloadStatus.getStatus() == DownloadStatus.Status.MISSING) {
|
||||
Log.i(TAG, "Download status missing, starting download...");
|
||||
handleDownloadStart(updateDescriptor.getUrl(), updateDescriptor.getVersionName(), digest);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -182,8 +182,7 @@ public class LinkPreviewRepository {
|
||||
CallRequestController controller = new CallRequestController(call);
|
||||
|
||||
SignalExecutors.UNBOUNDED.execute(() -> {
|
||||
try {
|
||||
Response response = call.execute();
|
||||
try (Response response = call.execute()) {
|
||||
if (!response.isSuccessful() || response.body() == null) {
|
||||
callback.accept(Optional.empty());
|
||||
return;
|
||||
|
||||
@@ -236,10 +236,10 @@ public class SubmitDebugLogRepository {
|
||||
|
||||
@WorkerThread
|
||||
private @NonNull String uploadContent(@NonNull String contentType, @NonNull RequestBody requestBody) throws IOException {
|
||||
try {
|
||||
OkHttpClient client = new OkHttpClient.Builder().addInterceptor(new StandardUserAgentInterceptor()).dns(SignalServiceNetworkAccess.DNS).build();
|
||||
Response response = client.newCall(new Request.Builder().url(API_ENDPOINT).get().build()).execute();
|
||||
ResponseBody body = response.body();
|
||||
OkHttpClient client = new OkHttpClient.Builder().addInterceptor(new StandardUserAgentInterceptor()).dns(SignalServiceNetworkAccess.DNS).build();
|
||||
|
||||
try (Response response = client.newCall(new Request.Builder().url(API_ENDPOINT).get().build()).execute()) {
|
||||
ResponseBody body = response.body();
|
||||
|
||||
if (!response.isSuccessful() || body == null) {
|
||||
throw new IOException("Unsuccessful response: " + response);
|
||||
@@ -261,10 +261,10 @@ public class SubmitDebugLogRepository {
|
||||
|
||||
post.addFormDataPart("file", "file", requestBody);
|
||||
|
||||
Response postResponse = client.newCall(new Request.Builder().url(url).post(post.build()).build()).execute();
|
||||
|
||||
if (!postResponse.isSuccessful()) {
|
||||
throw new IOException("Bad response: " + postResponse);
|
||||
try (Response postResponse = client.newCall(new Request.Builder().url(url).post(post.build()).build()).execute()) {
|
||||
if (!postResponse.isSuccessful()) {
|
||||
throw new IOException("Bad response: " + postResponse);
|
||||
}
|
||||
}
|
||||
|
||||
return API_ENDPOINT + "/" + item;
|
||||
|
||||
Reference in New Issue
Block a user