From 0e6ee9c101f0ccf7d43f88161480df8a286ced94 Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Wed, 29 Nov 2017 13:05:11 +0000 Subject: [PATCH] Fix content provider leak. --- .../etesync/syncadapter/ui/ViewCollectionActivity.java | 8 ++++++-- .../syncadapter/ui/importlocal/ImportFragment.java | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/etesync/syncadapter/ui/ViewCollectionActivity.java b/app/src/main/java/com/etesync/syncadapter/ui/ViewCollectionActivity.java index 604599e9..ad4a8827 100644 --- a/app/src/main/java/com/etesync/syncadapter/ui/ViewCollectionActivity.java +++ b/app/src/main/java/com/etesync/syncadapter/ui/ViewCollectionActivity.java @@ -9,6 +9,7 @@ package com.etesync.syncadapter.ui; import android.accounts.Account; +import android.content.ContentProviderClient; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; @@ -42,6 +43,7 @@ import at.bitfire.ical4android.CalendarStorageException; import at.bitfire.vcard4android.ContactsStorageException; import io.requery.Persistable; import io.requery.sql.EntityDataStore; +import lombok.Cleanup; import tourguide.tourguide.ToolTip; import tourguide.tourguide.TourGuide; @@ -211,7 +213,8 @@ public class ViewCollectionActivity extends BaseActivity implements Refreshable if (info.type == CollectionInfo.Type.CALENDAR) { try { - LocalCalendar resource = LocalCalendar.findByName(account, getContentResolver().acquireContentProviderClient(CalendarContract.CONTENT_URI), LocalCalendar.Factory.INSTANCE, info.uid); + @Cleanup("release") ContentProviderClient providerClient = getContentResolver().acquireContentProviderClient(CalendarContract.CONTENT_URI); + LocalCalendar resource = LocalCalendar.findByName(account, providerClient, LocalCalendar.Factory.INSTANCE, info.uid); if (resource == null) { return null; } @@ -222,7 +225,8 @@ public class ViewCollectionActivity extends BaseActivity implements Refreshable } } else { try { - LocalAddressBook resource = LocalAddressBook.findByUid(ViewCollectionActivity.this, getContentResolver().acquireContentProviderClient(ContactsContract.Contacts.CONTENT_URI), account, info.uid); + @Cleanup("release") ContentProviderClient providerClient = getContentResolver().acquireContentProviderClient(ContactsContract.Contacts.CONTENT_URI); + LocalAddressBook resource = LocalAddressBook.findByUid(ViewCollectionActivity.this, providerClient, account, info.uid); if (resource == null) { return null; } diff --git a/app/src/main/java/com/etesync/syncadapter/ui/importlocal/ImportFragment.java b/app/src/main/java/com/etesync/syncadapter/ui/importlocal/ImportFragment.java index 0ca5e770..80847272 100644 --- a/app/src/main/java/com/etesync/syncadapter/ui/importlocal/ImportFragment.java +++ b/app/src/main/java/com/etesync/syncadapter/ui/importlocal/ImportFragment.java @@ -306,7 +306,7 @@ public class ImportFragment extends DialogFragment { finishParsingFile(contacts.length); - ContentProviderClient provider = getContext().getContentResolver().acquireContentProviderClient(ContactsContract.RawContacts.CONTENT_URI); + @Cleanup ContentProviderClient provider = getContext().getContentResolver().acquireContentProviderClient(ContactsContract.RawContacts.CONTENT_URI); LocalAddressBook localAddressBook = LocalAddressBook.findByUid(getContext(), provider, account, info.uid); for (Contact contact : contacts) {