mirror of
https://github.com/etesync/android
synced 2025-03-25 03:45:46 +00:00
Remove lombok usage entirely, but keep it for the submodules
This commit is contained in:
parent
c65640586b
commit
dd96ea38d0
@ -38,7 +38,6 @@ import java.util.logging.Level;
|
||||
|
||||
import at.bitfire.vcard4android.ContactsStorageException;
|
||||
import at.bitfire.vcard4android.GroupMethod;
|
||||
import lombok.Cleanup;
|
||||
|
||||
public class AccountSettings {
|
||||
private final static int CURRENT_VERSION = 2;
|
||||
@ -255,7 +254,7 @@ public class AccountSettings {
|
||||
if (fromVersion < 2) {
|
||||
long affected = -1;
|
||||
long newCount = -1;
|
||||
@Cleanup("release") ContentProviderClient provider = context.getContentResolver().acquireContentProviderClient(ContactsContract.AUTHORITY);
|
||||
ContentProviderClient provider = context.getContentResolver().acquireContentProviderClient(ContactsContract.AUTHORITY);
|
||||
if (provider == null)
|
||||
// no access to contacts provider
|
||||
return;
|
||||
@ -267,14 +266,15 @@ public class AccountSettings {
|
||||
|
||||
try {
|
||||
// get previous address book settings (including URL)
|
||||
@Cleanup("recycle") Parcel parcel = Parcel.obtain();
|
||||
byte[] raw = ContactsContract.SyncState.get(provider, account);
|
||||
if (raw == null)
|
||||
App.log.info("No contacts sync state, ignoring account");
|
||||
else {
|
||||
Parcel parcel = Parcel.obtain();
|
||||
parcel.unmarshall(raw, 0, raw.length);
|
||||
parcel.setDataPosition(0);
|
||||
Bundle params = parcel.readBundle();
|
||||
parcel.recycle();
|
||||
String url = params.getString("url");
|
||||
if (url == null)
|
||||
App.log.info("No address book URL, ignoring account");
|
||||
@ -314,6 +314,8 @@ public class AccountSettings {
|
||||
throw new ContactsStorageException("Couldn't migrate contacts to new address book", e);
|
||||
}
|
||||
|
||||
provider.release();
|
||||
|
||||
// request sync of new address book account
|
||||
ContentResolver.setIsSyncable(account, App.getAddressBooksAuthority(), 1);
|
||||
setSyncInterval(App.getAddressBooksAuthority(), Constants.DEFAULT_SYNC_INTERVAL);
|
||||
|
@ -77,7 +77,6 @@ import io.requery.android.sqlite.DatabaseSource;
|
||||
import io.requery.meta.EntityModel;
|
||||
import io.requery.sql.Configuration;
|
||||
import io.requery.sql.EntityDataStore;
|
||||
import lombok.Cleanup;
|
||||
import okhttp3.internal.tls.OkHostnameVerifier;
|
||||
|
||||
@AcraCore(buildConfigClass = BuildConfig.class)
|
||||
@ -171,11 +170,13 @@ public class App extends Application {
|
||||
}
|
||||
|
||||
private void loadLanguage() {
|
||||
@Cleanup ServiceDB.OpenHelper serviceDB = new ServiceDB.OpenHelper(this);
|
||||
ServiceDB.OpenHelper serviceDB = new ServiceDB.OpenHelper(this);
|
||||
String lang = new Settings(serviceDB.getReadableDatabase()).getString(App.FORCE_LANGUAGE, null);
|
||||
if (lang != null && !lang.equals(DEFAULT_LANGUAGE)) {
|
||||
LanguageUtils.setLanguage(this, lang);
|
||||
}
|
||||
|
||||
serviceDB.close();
|
||||
}
|
||||
|
||||
public void reinitCertManager() {
|
||||
@ -183,17 +184,19 @@ public class App extends Application {
|
||||
if (certManager != null)
|
||||
certManager.close();
|
||||
|
||||
@Cleanup ServiceDB.OpenHelper dbHelper = new ServiceDB.OpenHelper(this);
|
||||
ServiceDB.OpenHelper dbHelper = new ServiceDB.OpenHelper(this);
|
||||
Settings settings = new Settings(dbHelper.getReadableDatabase());
|
||||
|
||||
certManager = new CustomCertManager(this, !settings.getBoolean(DISTRUST_SYSTEM_CERTIFICATES, false));
|
||||
sslSocketFactoryCompat = new SSLSocketFactoryCompat(certManager);
|
||||
hostnameVerifier = certManager.hostnameVerifier(OkHostnameVerifier.INSTANCE);
|
||||
|
||||
dbHelper.close();
|
||||
}
|
||||
}
|
||||
|
||||
public void reinitLogger() {
|
||||
@Cleanup ServiceDB.OpenHelper dbHelper = new ServiceDB.OpenHelper(this);
|
||||
ServiceDB.OpenHelper dbHelper = new ServiceDB.OpenHelper(this);
|
||||
Settings settings = new Settings(dbHelper.getReadableDatabase());
|
||||
|
||||
boolean logToFile = settings.getBoolean(LOG_TO_EXTERNAL_STORAGE, false),
|
||||
@ -250,6 +253,8 @@ public class App extends Application {
|
||||
nm.notify(Constants.NOTIFICATION_EXTERNAL_FILE_LOGGING, builder.build());
|
||||
} else
|
||||
nm.cancel(Constants.NOTIFICATION_EXTERNAL_FILE_LOGGING);
|
||||
|
||||
dbHelper.close();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@ -353,8 +358,9 @@ public class App extends Application {
|
||||
data.insert(journalEntity);
|
||||
}
|
||||
|
||||
@Cleanup SQLiteDatabase db = dbHelper.getWritableDatabase();
|
||||
SQLiteDatabase db = dbHelper.getWritableDatabase();
|
||||
db.delete(ServiceDB.Collections._TABLE, null, null);
|
||||
db.close();
|
||||
}
|
||||
|
||||
if (fromVersion < 7) {
|
||||
@ -414,21 +420,24 @@ public class App extends Application {
|
||||
|
||||
@NonNull
|
||||
private List<CollectionInfo> readCollections(ServiceDB.OpenHelper dbHelper) {
|
||||
@Cleanup SQLiteDatabase db = dbHelper.getWritableDatabase();
|
||||
SQLiteDatabase db = dbHelper.getWritableDatabase();
|
||||
List<CollectionInfo> collections = new LinkedList<>();
|
||||
@Cleanup Cursor cursor = db.query(ServiceDB.Collections._TABLE, null, null, null, null, null, null);
|
||||
Cursor cursor = db.query(ServiceDB.Collections._TABLE, null, null, null, null, null, null);
|
||||
while (cursor.moveToNext()) {
|
||||
ContentValues values = new ContentValues();
|
||||
DatabaseUtils.cursorRowToContentValues(cursor, values);
|
||||
collections.add(CollectionInfo.fromDB(values));
|
||||
}
|
||||
|
||||
db.close();
|
||||
cursor.close();
|
||||
return collections;
|
||||
}
|
||||
|
||||
public void migrateServices(ServiceDB.OpenHelper dbHelper) {
|
||||
@Cleanup SQLiteDatabase db = dbHelper.getReadableDatabase();
|
||||
SQLiteDatabase db = dbHelper.getReadableDatabase();
|
||||
EntityDataStore<Persistable> data = this.getData();
|
||||
@Cleanup Cursor cursor = db.query(ServiceDB.Services._TABLE, null, null, null, null, null, null);
|
||||
Cursor cursor = db.query(ServiceDB.Services._TABLE, null, null, null, null, null, null);
|
||||
while (cursor.moveToNext()) {
|
||||
ContentValues values = new ContentValues();
|
||||
DatabaseUtils.cursorRowToContentValues(cursor, values);
|
||||
@ -444,5 +453,7 @@ public class App extends Application {
|
||||
}
|
||||
|
||||
db.delete(ServiceDB.Services._TABLE, null, null);
|
||||
db.close();
|
||||
cursor.close();
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,6 @@
|
||||
|
||||
package com.etesync.syncadapter;
|
||||
|
||||
import android.os.Build;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.text.TextUtils;
|
||||
|
||||
@ -27,8 +26,6 @@ import javax.net.ssl.SSLSocket;
|
||||
import javax.net.ssl.SSLSocketFactory;
|
||||
import javax.net.ssl.X509TrustManager;
|
||||
|
||||
import lombok.Cleanup;
|
||||
|
||||
public class SSLSocketFactoryCompat extends SSLSocketFactory {
|
||||
|
||||
private SSLSocketFactory delegate;
|
||||
@ -39,7 +36,7 @@ public class SSLSocketFactoryCompat extends SSLSocketFactory {
|
||||
static String protocols[] = null, cipherSuites[] = null;
|
||||
static {
|
||||
try {
|
||||
@Cleanup SSLSocket socket = (SSLSocket)SSLSocketFactory.getDefault().createSocket();
|
||||
SSLSocket socket = (SSLSocket)SSLSocketFactory.getDefault().createSocket();
|
||||
if (socket != null) {
|
||||
/* set reasonable protocol versions */
|
||||
// - enable all supported protocols (enables TLSv1.1 and TLSv1.2 on Android <5.0)
|
||||
@ -92,6 +89,7 @@ public class SSLSocketFactoryCompat extends SSLSocketFactory {
|
||||
|
||||
App.log.info("Enabling (only) those TLS ciphers: " + TextUtils.join(", ", enabledCiphers));
|
||||
SSLSocketFactoryCompat.cipherSuites = enabledCiphers.toArray(new String[enabledCiphers.size()]);
|
||||
socket.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
App.log.severe("Couldn't determine default TLS settings");
|
||||
|
@ -20,9 +20,7 @@ import java.io.Serializable;
|
||||
|
||||
import io.requery.Persistable;
|
||||
import io.requery.sql.EntityDataStore;
|
||||
import lombok.ToString;
|
||||
|
||||
@ToString(exclude = {"id"})
|
||||
public class CollectionInfo implements Serializable {
|
||||
@Deprecated
|
||||
public long id;
|
||||
@ -110,4 +108,9 @@ public class CollectionInfo implements Serializable {
|
||||
return (i == null) ? null : (i != 0);
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
@java.lang.SuppressWarnings("all")
|
||||
public java.lang.String toString() {
|
||||
return "CollectionInfo(serviceID=" + this.serviceID + ", version=" + this.version + ", type=" + this.type + ", uid=" + this.uid + ", displayName=" + this.displayName + ", description=" + this.description + ", color=" + this.color + ", timeZone=" + this.timeZone + ", selected=" + this.selected + ")";
|
||||
}
|
||||
}
|
||||
|
@ -8,21 +8,15 @@
|
||||
|
||||
package com.etesync.syncadapter.model;
|
||||
|
||||
import android.accounts.Account;
|
||||
import android.content.ContentValues;
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.database.sqlite.SQLiteException;
|
||||
import android.database.sqlite.SQLiteOpenHelper;
|
||||
import android.os.Build;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.annotation.RequiresApi;
|
||||
|
||||
import com.etesync.syncadapter.App;
|
||||
import com.etesync.syncadapter.Constants;
|
||||
import lombok.Cleanup;
|
||||
|
||||
public class ServiceDB {
|
||||
|
||||
@ -101,11 +95,11 @@ public class ServiceDB {
|
||||
db.beginTransactionNonExclusive();
|
||||
|
||||
// iterate through all tables
|
||||
@Cleanup Cursor cursorTables = db.query("sqlite_master", new String[]{"name"}, "type='table'", null, null, null, null);
|
||||
Cursor cursorTables = db.query("sqlite_master", new String[]{"name"}, "type='table'", null, null, null, null);
|
||||
while (cursorTables.moveToNext()) {
|
||||
String table = cursorTables.getString(0);
|
||||
sb.append(table).append("\n");
|
||||
@Cleanup Cursor cursor = db.query(table, null, null, null, null, null, null);
|
||||
Cursor cursor = db.query(table, null, null, null, null, null, null);
|
||||
|
||||
// print columns
|
||||
int cols = cursor.getColumnCount();
|
||||
@ -138,8 +132,10 @@ public class ServiceDB {
|
||||
}
|
||||
sb.append("\n");
|
||||
}
|
||||
cursor.close();
|
||||
sb.append("----------\n");
|
||||
}
|
||||
cursorTables.close();
|
||||
db.endTransaction();
|
||||
}
|
||||
}
|
||||
|
@ -13,8 +13,6 @@ import android.database.Cursor;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import lombok.Cleanup;
|
||||
|
||||
public class Settings {
|
||||
|
||||
final SQLiteDatabase db;
|
||||
@ -25,12 +23,16 @@ public class Settings {
|
||||
|
||||
|
||||
public boolean getBoolean(String name, boolean defaultValue) {
|
||||
@Cleanup Cursor cursor = db.query(ServiceDB.Settings._TABLE, new String[] { ServiceDB.Settings.VALUE },
|
||||
Cursor cursor = db.query(ServiceDB.Settings._TABLE, new String[] { ServiceDB.Settings.VALUE },
|
||||
ServiceDB.Settings.NAME + "=?", new String[] { name }, null, null, null);
|
||||
if (cursor.moveToNext() && !cursor.isNull(0))
|
||||
return cursor.getInt(0) != 0;
|
||||
else
|
||||
return defaultValue;
|
||||
try {
|
||||
if (cursor.moveToNext() && !cursor.isNull(0))
|
||||
return cursor.getInt(0) != 0;
|
||||
else
|
||||
return defaultValue;
|
||||
} finally {
|
||||
cursor.close();
|
||||
}
|
||||
}
|
||||
|
||||
public void putBoolean(String name, boolean value) {
|
||||
@ -42,12 +44,16 @@ public class Settings {
|
||||
|
||||
|
||||
public int getInt(String name, int defaultValue) {
|
||||
@Cleanup Cursor cursor = db.query(ServiceDB.Settings._TABLE, new String[] { ServiceDB.Settings.VALUE },
|
||||
Cursor cursor = db.query(ServiceDB.Settings._TABLE, new String[] { ServiceDB.Settings.VALUE },
|
||||
ServiceDB.Settings.NAME + "=?", new String[] { name }, null, null, null);
|
||||
if (cursor.moveToNext() && !cursor.isNull(0))
|
||||
return cursor.isNull(0) ? defaultValue : cursor.getInt(0);
|
||||
else
|
||||
return defaultValue;
|
||||
try {
|
||||
if (cursor.moveToNext() && !cursor.isNull(0))
|
||||
return cursor.isNull(0) ? defaultValue : cursor.getInt(0);
|
||||
else
|
||||
return defaultValue;
|
||||
} finally {
|
||||
cursor.close();
|
||||
}
|
||||
}
|
||||
|
||||
public void putInt(String name, int value) {
|
||||
@ -60,12 +66,16 @@ public class Settings {
|
||||
|
||||
@Nullable
|
||||
public String getString(String name, @Nullable String defaultValue) {
|
||||
@Cleanup Cursor cursor = db.query(ServiceDB.Settings._TABLE, new String[] { ServiceDB.Settings.VALUE },
|
||||
Cursor cursor = db.query(ServiceDB.Settings._TABLE, new String[] { ServiceDB.Settings.VALUE },
|
||||
ServiceDB.Settings.NAME + "=?", new String[] { name }, null, null, null);
|
||||
if (cursor.moveToNext())
|
||||
return cursor.getString(0);
|
||||
else
|
||||
return defaultValue;
|
||||
try {
|
||||
if (cursor.moveToNext())
|
||||
return cursor.getString(0);
|
||||
else
|
||||
return defaultValue;
|
||||
} finally {
|
||||
cursor.close();
|
||||
}
|
||||
}
|
||||
|
||||
public void putString(String name, @Nullable String value) {
|
||||
|
@ -49,7 +49,6 @@ import at.bitfire.vcard4android.AndroidContact;
|
||||
import at.bitfire.vcard4android.AndroidGroup;
|
||||
import at.bitfire.vcard4android.CachedGroupMembership;
|
||||
import at.bitfire.vcard4android.ContactsStorageException;
|
||||
import lombok.Cleanup;
|
||||
|
||||
|
||||
public class LocalAddressBook extends AndroidAddressBook implements LocalCollection {
|
||||
@ -245,11 +244,14 @@ public class LocalAddressBook extends AndroidAddressBook implements LocalCollect
|
||||
@Override
|
||||
public long count() throws ContactsStorageException {
|
||||
try {
|
||||
@Cleanup Cursor cursor = provider.query(syncAdapterURI(RawContacts.CONTENT_URI),
|
||||
Cursor cursor = provider.query(syncAdapterURI(RawContacts.CONTENT_URI),
|
||||
null,
|
||||
null, null, null);
|
||||
|
||||
return cursor.getCount();
|
||||
try {
|
||||
return cursor.getCount();
|
||||
} finally {
|
||||
cursor.close();
|
||||
}
|
||||
} catch (RemoteException e) {
|
||||
throw new ContactsStorageException("Couldn't query contacts", e);
|
||||
}
|
||||
@ -282,7 +284,7 @@ public class LocalAddressBook extends AndroidAddressBook implements LocalCollect
|
||||
|
||||
@NonNull LocalContact[] getByGroupMembership(long groupID) throws ContactsStorageException {
|
||||
try {
|
||||
@Cleanup Cursor cursor = provider.query(syncAdapterURI(ContactsContract.Data.CONTENT_URI),
|
||||
Cursor cursor = provider.query(syncAdapterURI(ContactsContract.Data.CONTENT_URI),
|
||||
new String[] { RawContacts.Data.RAW_CONTACT_ID },
|
||||
"(" + GroupMembership.MIMETYPE + "=? AND " + GroupMembership.GROUP_ROW_ID + "=?) OR (" + CachedGroupMembership.MIMETYPE + "=? AND " + CachedGroupMembership.GROUP_ID + "=?)",
|
||||
new String[] { GroupMembership.CONTENT_ITEM_TYPE, String.valueOf(groupID), CachedGroupMembership.CONTENT_ITEM_TYPE, String.valueOf(groupID) },
|
||||
@ -292,6 +294,8 @@ public class LocalAddressBook extends AndroidAddressBook implements LocalCollect
|
||||
while (cursor != null && cursor.moveToNext())
|
||||
ids.add(cursor.getLong(0));
|
||||
|
||||
cursor.close();
|
||||
|
||||
LocalContact[] contacts = new LocalContact[ids.size()];
|
||||
int i = 0;
|
||||
for (Long id : ids)
|
||||
@ -322,12 +326,16 @@ public class LocalAddressBook extends AndroidAddressBook implements LocalCollect
|
||||
*/
|
||||
public long findOrCreateGroup(@NonNull String title) throws ContactsStorageException {
|
||||
try {
|
||||
@Cleanup Cursor cursor = provider.query(syncAdapterURI(Groups.CONTENT_URI),
|
||||
Cursor cursor = provider.query(syncAdapterURI(Groups.CONTENT_URI),
|
||||
new String[] { Groups._ID },
|
||||
Groups.TITLE + "=?", new String[] { title },
|
||||
null);
|
||||
if (cursor != null && cursor.moveToNext())
|
||||
return cursor.getLong(0);
|
||||
try {
|
||||
if (cursor != null && cursor.moveToNext())
|
||||
return cursor.getLong(0);
|
||||
} finally {
|
||||
cursor.close();
|
||||
}
|
||||
|
||||
ContentValues values = new ContentValues();
|
||||
values.put(Groups.TITLE, title);
|
||||
|
@ -40,8 +40,6 @@ import at.bitfire.ical4android.AndroidCalendarFactory;
|
||||
import at.bitfire.ical4android.BatchOperation;
|
||||
import at.bitfire.ical4android.CalendarStorageException;
|
||||
import at.bitfire.ical4android.DateUtils;
|
||||
import at.bitfire.vcard4android.ContactsStorageException;
|
||||
import lombok.Cleanup;
|
||||
|
||||
public class LocalCalendar extends AndroidCalendar implements LocalCollection {
|
||||
|
||||
@ -167,7 +165,7 @@ public class LocalCalendar extends AndroidCalendar implements LocalCollection {
|
||||
// process deleted exceptions
|
||||
App.log.info("Processing deleted exceptions");
|
||||
try {
|
||||
@Cleanup Cursor cursor = provider.query(
|
||||
Cursor cursor = provider.query(
|
||||
syncAdapterURI(Events.CONTENT_URI),
|
||||
new String[] { Events._ID, Events.ORIGINAL_ID, LocalEvent.COLUMN_SEQUENCE },
|
||||
Events.DELETED + "!=0 AND " + Events.ORIGINAL_ID + " IS NOT NULL", null, null);
|
||||
@ -177,12 +175,13 @@ public class LocalCalendar extends AndroidCalendar implements LocalCollection {
|
||||
originalID = cursor.getLong(1); // can't be null (by query)
|
||||
|
||||
// get original event's SEQUENCE
|
||||
@Cleanup Cursor cursor2 = provider.query(
|
||||
Cursor cursor2 = provider.query(
|
||||
syncAdapterURI(ContentUris.withAppendedId(Events.CONTENT_URI, originalID)),
|
||||
new String[] { LocalEvent.COLUMN_SEQUENCE },
|
||||
null, null, null);
|
||||
int originalSequence = (cursor2 == null || cursor2.isNull(0)) ? 0 : cursor2.getInt(0);
|
||||
|
||||
cursor2.close();
|
||||
BatchOperation batch = new BatchOperation(provider);
|
||||
// re-schedule original event and set it to DIRTY
|
||||
batch.enqueue(new BatchOperation.Operation(
|
||||
@ -196,6 +195,7 @@ public class LocalCalendar extends AndroidCalendar implements LocalCollection {
|
||||
));
|
||||
batch.commit();
|
||||
}
|
||||
cursor.close();
|
||||
} catch (RemoteException e) {
|
||||
throw new CalendarStorageException("Couldn't process locally modified exception", e);
|
||||
}
|
||||
@ -203,7 +203,7 @@ public class LocalCalendar extends AndroidCalendar implements LocalCollection {
|
||||
// process dirty exceptions
|
||||
App.log.info("Processing dirty exceptions");
|
||||
try {
|
||||
@Cleanup Cursor cursor = provider.query(
|
||||
Cursor cursor = provider.query(
|
||||
syncAdapterURI(Events.CONTENT_URI),
|
||||
new String[] { Events._ID, Events.ORIGINAL_ID, LocalEvent.COLUMN_SEQUENCE },
|
||||
Events.DIRTY + "!=0 AND " + Events.ORIGINAL_ID + " IS NOT NULL", null, null);
|
||||
@ -227,6 +227,7 @@ public class LocalCalendar extends AndroidCalendar implements LocalCollection {
|
||||
));
|
||||
batch.commit();
|
||||
}
|
||||
cursor.close();
|
||||
} catch (RemoteException e) {
|
||||
throw new CalendarStorageException("Couldn't process locally modified exception", e);
|
||||
}
|
||||
@ -238,11 +239,15 @@ public class LocalCalendar extends AndroidCalendar implements LocalCollection {
|
||||
String whereArgs[] = {String.valueOf(id)};
|
||||
|
||||
try {
|
||||
@Cleanup Cursor cursor = provider.query(
|
||||
Cursor cursor = provider.query(
|
||||
syncAdapterURI(Events.CONTENT_URI),
|
||||
null,
|
||||
where, whereArgs, null);
|
||||
return cursor.getCount();
|
||||
try {
|
||||
return cursor.getCount();
|
||||
} finally {
|
||||
cursor.close();
|
||||
}
|
||||
} catch (RemoteException e) {
|
||||
throw new CalendarStorageException("Couldn't query calendar events", e);
|
||||
}
|
||||
|
@ -22,7 +22,6 @@ import android.support.annotation.Nullable;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.etesync.syncadapter.App;
|
||||
import com.etesync.syncadapter.BuildConfig;
|
||||
import com.etesync.syncadapter.Constants;
|
||||
import com.etesync.syncadapter.model.UnknownProperties;
|
||||
|
||||
@ -43,7 +42,6 @@ import at.bitfire.vcard4android.Contact;
|
||||
import at.bitfire.vcard4android.ContactsStorageException;
|
||||
import ezvcard.Ezvcard;
|
||||
import ezvcard.VCardVersion;
|
||||
import lombok.Cleanup;
|
||||
|
||||
import static at.bitfire.vcard4android.GroupMethod.GROUP_VCARDS;
|
||||
|
||||
@ -236,10 +234,15 @@ public class LocalContact extends AndroidContact implements LocalResource {
|
||||
App.log.severe("getLastHashCode() should not be called on Android <7");
|
||||
|
||||
try {
|
||||
@Cleanup Cursor c = addressBook.provider.query(rawContactSyncURI(), new String[] { COLUMN_HASHCODE }, null, null, null);
|
||||
if (c == null || !c.moveToNext() || c.isNull(0))
|
||||
return 0;
|
||||
return c.getInt(0);
|
||||
Cursor c = addressBook.provider.query(rawContactSyncURI(), new String[] { COLUMN_HASHCODE }, null, null, null);
|
||||
try {
|
||||
if (c == null || !c.moveToNext() || c.isNull(0))
|
||||
return 0;
|
||||
return c.getInt(0);
|
||||
} finally {
|
||||
if (c != null)
|
||||
c.close();
|
||||
}
|
||||
} catch(RemoteException e) {
|
||||
throw new ContactsStorageException("Could't read last hash code", e);
|
||||
}
|
||||
|
@ -36,7 +36,6 @@ import at.bitfire.ical4android.AndroidEventFactory;
|
||||
import at.bitfire.ical4android.CalendarStorageException;
|
||||
import at.bitfire.ical4android.Event;
|
||||
import at.bitfire.vcard4android.ContactsStorageException;
|
||||
import lombok.Cleanup;
|
||||
|
||||
@TargetApi(17)
|
||||
public class LocalEvent extends AndroidEvent implements LocalResource {
|
||||
@ -154,12 +153,13 @@ public class LocalEvent extends AndroidEvent implements LocalResource {
|
||||
public void prepareForUpload() throws CalendarStorageException {
|
||||
try {
|
||||
String uid = null;
|
||||
@Cleanup Cursor c = calendar.provider.query(eventSyncURI(), new String[] { COLUMN_UID }, null, null, null);
|
||||
Cursor c = calendar.provider.query(eventSyncURI(), new String[] { COLUMN_UID }, null, null, null);
|
||||
if (c.moveToNext())
|
||||
uid = c.getString(0);
|
||||
if (uid == null)
|
||||
uid = UUID.randomUUID().toString();
|
||||
|
||||
c.close();
|
||||
final String newFileName = uid;
|
||||
|
||||
ContentValues values = new ContentValues(2);
|
||||
|
@ -44,12 +44,9 @@ import at.bitfire.vcard4android.CachedGroupMembership;
|
||||
import at.bitfire.vcard4android.Contact;
|
||||
import at.bitfire.vcard4android.ContactsStorageException;
|
||||
import ezvcard.VCardVersion;
|
||||
import lombok.Cleanup;
|
||||
import lombok.ToString;
|
||||
|
||||
import static at.bitfire.vcard4android.GroupMethod.GROUP_VCARDS;
|
||||
|
||||
@ToString(callSuper=true)
|
||||
public class LocalGroup extends AndroidGroup implements LocalResource {
|
||||
protected String uuid;
|
||||
/** marshalled list of member UIDs, as sent by server */
|
||||
@ -136,10 +133,11 @@ public class LocalGroup extends AndroidGroup implements LocalResource {
|
||||
protected ContentValues contentValues() {
|
||||
ContentValues values = super.contentValues();
|
||||
|
||||
@Cleanup("recycle") Parcel members = Parcel.obtain();
|
||||
Parcel members = Parcel.obtain();
|
||||
members.writeStringList(contact.members);
|
||||
values.put(COLUMN_PENDING_MEMBERS, members.marshall());
|
||||
|
||||
members.recycle();
|
||||
return values;
|
||||
}
|
||||
|
||||
@ -169,7 +167,7 @@ public class LocalGroup extends AndroidGroup implements LocalResource {
|
||||
*/
|
||||
public static void applyPendingMemberships(LocalAddressBook addressBook) throws ContactsStorageException {
|
||||
try {
|
||||
@Cleanup Cursor cursor = addressBook.provider.query(
|
||||
Cursor cursor = addressBook.provider.query(
|
||||
addressBook.syncAdapterURI(Groups.CONTENT_URI),
|
||||
new String[] { Groups._ID, COLUMN_PENDING_MEMBERS },
|
||||
COLUMN_PENDING_MEMBERS + " IS NOT NULL", new String[] {},
|
||||
@ -193,10 +191,11 @@ public class LocalGroup extends AndroidGroup implements LocalResource {
|
||||
// extract list of member UIDs
|
||||
List<String> members = new LinkedList<>();
|
||||
byte[] raw = cursor.getBlob(1);
|
||||
@Cleanup("recycle") Parcel parcel = Parcel.obtain();
|
||||
Parcel parcel = Parcel.obtain();
|
||||
parcel.unmarshall(raw, 0, raw.length);
|
||||
parcel.setDataPosition(0);
|
||||
parcel.readStringList(members);
|
||||
parcel.recycle();
|
||||
|
||||
// insert memberships
|
||||
for (String uid : members) {
|
||||
@ -226,6 +225,7 @@ public class LocalGroup extends AndroidGroup implements LocalResource {
|
||||
|
||||
batch.commit();
|
||||
}
|
||||
cursor.close();
|
||||
} catch(RemoteException e) {
|
||||
throw new ContactsStorageException("Couldn't get pending memberships", e);
|
||||
}
|
||||
@ -248,7 +248,7 @@ public class LocalGroup extends AndroidGroup implements LocalResource {
|
||||
assertID();
|
||||
List<Long> members = new LinkedList<>();
|
||||
try {
|
||||
@Cleanup Cursor cursor = addressBook.provider.query(
|
||||
Cursor cursor = addressBook.provider.query(
|
||||
addressBook.syncAdapterURI(ContactsContract.Data.CONTENT_URI),
|
||||
new String[] { Data.RAW_CONTACT_ID },
|
||||
GroupMembership.MIMETYPE + "=? AND " + GroupMembership.GROUP_ROW_ID + "=?",
|
||||
@ -257,12 +257,18 @@ public class LocalGroup extends AndroidGroup implements LocalResource {
|
||||
);
|
||||
while (cursor != null && cursor.moveToNext())
|
||||
members.add(cursor.getLong(0));
|
||||
cursor.close();
|
||||
} catch(RemoteException e) {
|
||||
throw new ContactsStorageException("Couldn't list group members", e);
|
||||
}
|
||||
return ArrayUtils.toPrimitive(members.toArray(new Long[members.size()]));
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
@java.lang.SuppressWarnings("all")
|
||||
public java.lang.String toString() {
|
||||
return "LocalGroup(super=" + super.toString() + ", uuid=" + this.getUuid() + ")";
|
||||
}
|
||||
|
||||
// factory
|
||||
|
||||
|
@ -30,7 +30,6 @@ import at.bitfire.ical4android.AndroidTaskList;
|
||||
import at.bitfire.ical4android.AndroidTaskListFactory;
|
||||
import at.bitfire.ical4android.CalendarStorageException;
|
||||
import at.bitfire.ical4android.TaskProvider;
|
||||
import lombok.Cleanup;
|
||||
|
||||
public class LocalTaskList extends AndroidTaskList implements LocalCollection {
|
||||
|
||||
@ -116,11 +115,15 @@ public class LocalTaskList extends AndroidTaskList implements LocalCollection {
|
||||
String whereArgs[] = {String.valueOf(getId())};
|
||||
|
||||
try {
|
||||
@Cleanup Cursor cursor = provider.client.query(
|
||||
Cursor cursor = provider.client.query(
|
||||
syncAdapterURI(provider.tasksUri()),
|
||||
null,
|
||||
where, whereArgs, null);
|
||||
return cursor.getCount();
|
||||
try {
|
||||
return cursor.getCount();
|
||||
} finally {
|
||||
cursor.close();
|
||||
}
|
||||
} catch (RemoteException e) {
|
||||
throw new CalendarStorageException("Couldn't query calendar events", e);
|
||||
}
|
||||
@ -132,8 +135,13 @@ public class LocalTaskList extends AndroidTaskList implements LocalCollection {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
|
||||
return context.getPackageManager().resolveContentProvider(TaskProvider.ProviderName.OpenTasks.authority, 0) != null;
|
||||
else {
|
||||
@Cleanup TaskProvider provider = TaskProvider.acquire(context.getContentResolver(), TaskProvider.ProviderName.OpenTasks);
|
||||
return provider != null;
|
||||
TaskProvider provider = TaskProvider.acquire(context.getContentResolver(), TaskProvider.ProviderName.OpenTasks);
|
||||
try {
|
||||
return provider != null;
|
||||
} finally {
|
||||
if (provider != null)
|
||||
provider.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -156,11 +164,12 @@ public class LocalTaskList extends AndroidTaskList implements LocalCollection {
|
||||
// HELPERS
|
||||
|
||||
public static void onRenameAccount(@NonNull ContentResolver resolver, @NonNull String oldName, @NonNull String newName) throws RemoteException {
|
||||
@Cleanup("release") ContentProviderClient client = resolver.acquireContentProviderClient(TaskProvider.ProviderName.OpenTasks.authority);
|
||||
ContentProviderClient client = resolver.acquireContentProviderClient(TaskProvider.ProviderName.OpenTasks.authority);
|
||||
if (client != null) {
|
||||
ContentValues values = new ContentValues(1);
|
||||
values.put(Tasks.ACCOUNT_NAME, newName);
|
||||
client.update(Tasks.getContentUri(TaskProvider.ProviderName.OpenTasks.authority), values, Tasks.ACCOUNT_NAME + "=?", new String[]{oldName});
|
||||
client.release();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -43,7 +43,6 @@ import java.util.logging.Level;
|
||||
import at.bitfire.vcard4android.ContactsStorageException;
|
||||
import io.requery.Persistable;
|
||||
import io.requery.sql.EntityDataStore;
|
||||
import lombok.Cleanup;
|
||||
|
||||
import static com.etesync.syncadapter.Constants.KEY_ACCOUNT;
|
||||
|
||||
@ -69,7 +68,7 @@ public class AddressBooksSyncAdapterService extends SyncAdapterService {
|
||||
notificationManager.cancel();
|
||||
|
||||
try {
|
||||
@Cleanup("release") ContentProviderClient contactsProvider = getContext().getContentResolver().acquireContentProviderClient(ContactsContract.AUTHORITY);
|
||||
ContentProviderClient contactsProvider = getContext().getContentResolver().acquireContentProviderClient(ContactsContract.AUTHORITY);
|
||||
if (contactsProvider == null) {
|
||||
App.log.severe("Couldn't access contacts provider");
|
||||
syncResult.databaseError = true;
|
||||
@ -84,6 +83,8 @@ public class AddressBooksSyncAdapterService extends SyncAdapterService {
|
||||
|
||||
updateLocalAddressBooks(contactsProvider, account);
|
||||
|
||||
contactsProvider.release();
|
||||
|
||||
AccountManager accountManager = AccountManager.get(getContext());
|
||||
for (Account addressBookAccount : accountManager.getAccountsByType(App.getAddressBookAccountType())) {
|
||||
App.log.log(Level.INFO, "Running sync for address book", addressBookAccount);
|
||||
|
@ -49,7 +49,6 @@ import at.bitfire.ical4android.CalendarStorageException;
|
||||
import at.bitfire.vcard4android.BatchOperation;
|
||||
import at.bitfire.vcard4android.Contact;
|
||||
import at.bitfire.vcard4android.ContactsStorageException;
|
||||
import lombok.Cleanup;
|
||||
import okhttp3.HttpUrl;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
@ -273,11 +272,16 @@ public class ContactsSyncManager extends SyncManager {
|
||||
|
||||
ResponseBody body = response.body();
|
||||
if (body != null) {
|
||||
@Cleanup InputStream stream = body.byteStream();
|
||||
if (response.isSuccessful() && stream != null) {
|
||||
return IOUtils.toByteArray(stream);
|
||||
} else
|
||||
App.log.severe("Couldn't download external resource");
|
||||
InputStream stream = body.byteStream();
|
||||
try {
|
||||
if (response.isSuccessful() && stream != null) {
|
||||
return IOUtils.toByteArray(stream);
|
||||
} else
|
||||
App.log.severe("Couldn't download external resource");
|
||||
} finally {
|
||||
if (stream != null)
|
||||
stream.close();
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
App.log.log(Level.SEVERE, "Couldn't download external resource", e);
|
||||
|
@ -42,7 +42,6 @@ import java.io.InputStream;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import ezvcard.Ezvcard;
|
||||
import lombok.Cleanup;
|
||||
|
||||
public class AboutActivity extends BaseActivity {
|
||||
|
||||
@ -215,8 +214,9 @@ public class AboutActivity extends BaseActivity {
|
||||
public Spanned loadInBackground() {
|
||||
App.log.fine("Loading license file " + fileName);
|
||||
try {
|
||||
@Cleanup InputStream is = getContext().getResources().getAssets().open(fileName);
|
||||
InputStream is = getContext().getResources().getAssets().open(fileName);
|
||||
byte[] raw = IOUtils.toByteArray(is);
|
||||
is.close();
|
||||
return content = Html.fromHtml(new String(raw));
|
||||
} catch (IOException e) {
|
||||
App.log.log(Level.SEVERE, "Couldn't read license file", e);
|
||||
|
@ -56,7 +56,6 @@ import java.util.logging.Level;
|
||||
import at.bitfire.vcard4android.ContactsStorageException;
|
||||
import io.requery.Persistable;
|
||||
import io.requery.sql.EntityDataStore;
|
||||
import lombok.Cleanup;
|
||||
|
||||
import static com.etesync.syncadapter.Constants.KEY_ACCOUNT;
|
||||
|
||||
@ -270,8 +269,9 @@ public class DebugInfoActivity extends BaseActivity implements LoaderManager.Loa
|
||||
report.append("\n");
|
||||
|
||||
report.append("SQLITE DUMP\n");
|
||||
@Cleanup ServiceDB.OpenHelper dbHelper = new ServiceDB.OpenHelper(context);
|
||||
ServiceDB.OpenHelper dbHelper = new ServiceDB.OpenHelper(context);
|
||||
dbHelper.dump(report);
|
||||
dbHelper.close();
|
||||
report.append("\n");
|
||||
|
||||
report.append("SERVICES DUMP\n");
|
||||
|
@ -43,7 +43,6 @@ 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;
|
||||
|
||||
@ -213,8 +212,9 @@ public class ViewCollectionActivity extends BaseActivity implements Refreshable
|
||||
|
||||
if (info.type == CollectionInfo.Type.CALENDAR) {
|
||||
try {
|
||||
@Cleanup("release") ContentProviderClient providerClient = getContentResolver().acquireContentProviderClient(CalendarContract.CONTENT_URI);
|
||||
ContentProviderClient providerClient = getContentResolver().acquireContentProviderClient(CalendarContract.CONTENT_URI);
|
||||
LocalCalendar resource = LocalCalendar.findByName(account, providerClient, LocalCalendar.Factory.INSTANCE, info.uid);
|
||||
providerClient.release();
|
||||
if (resource == null) {
|
||||
return null;
|
||||
}
|
||||
@ -225,8 +225,9 @@ public class ViewCollectionActivity extends BaseActivity implements Refreshable
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
@Cleanup("release") ContentProviderClient providerClient = getContentResolver().acquireContentProviderClient(ContactsContract.Contacts.CONTENT_URI);
|
||||
ContentProviderClient providerClient = getContentResolver().acquireContentProviderClient(ContactsContract.Contacts.CONTENT_URI);
|
||||
LocalAddressBook resource = LocalAddressBook.findByUid(ViewCollectionActivity.this, providerClient, account, info.uid);
|
||||
providerClient.release();
|
||||
if (resource == null) {
|
||||
return null;
|
||||
}
|
||||
|
@ -39,11 +39,10 @@ import at.bitfire.ical4android.Event;
|
||||
import at.bitfire.ical4android.InvalidCalendarException;
|
||||
import at.bitfire.vcard4android.Contact;
|
||||
import at.bitfire.vcard4android.ContactsStorageException;
|
||||
import lombok.Cleanup;
|
||||
|
||||
import static com.etesync.syncadapter.Constants.KEY_ACCOUNT;
|
||||
import static com.etesync.syncadapter.Constants.KEY_COLLECTION_INFO;
|
||||
import static com.etesync.syncadapter.ui.importlocal.ResultFragment.*;
|
||||
import static com.etesync.syncadapter.ui.importlocal.ResultFragment.ImportResult;
|
||||
|
||||
public class ImportFragment extends DialogFragment {
|
||||
private static final int REQUEST_CODE = 6384; // onActivityResult request
|
||||
@ -247,10 +246,11 @@ public class ImportFragment extends DialogFragment {
|
||||
ImportResult result = new ImportResult();
|
||||
|
||||
try {
|
||||
@Cleanup FileInputStream importStream = new FileInputStream(importFile);
|
||||
FileInputStream importStream = new FileInputStream(importFile);
|
||||
|
||||
if (info.type.equals(CollectionInfo.Type.CALENDAR)) {
|
||||
final Event[] events = Event.fromStream(importStream, Charsets.UTF_8);
|
||||
importStream.close();
|
||||
|
||||
if (events.length == 0) {
|
||||
App.log.warning("Empty/invalid file.");
|
||||
@ -306,7 +306,7 @@ public class ImportFragment extends DialogFragment {
|
||||
|
||||
finishParsingFile(contacts.length);
|
||||
|
||||
@Cleanup ContentProviderClient provider = getContext().getContentResolver().acquireContentProviderClient(ContactsContract.RawContacts.CONTENT_URI);
|
||||
ContentProviderClient provider = getContext().getContentResolver().acquireContentProviderClient(ContactsContract.RawContacts.CONTENT_URI);
|
||||
LocalAddressBook localAddressBook = LocalAddressBook.findByUid(getContext(), provider, account, info.uid);
|
||||
|
||||
for (Contact contact : contacts) {
|
||||
@ -326,6 +326,7 @@ public class ImportFragment extends DialogFragment {
|
||||
|
||||
entryProcessed();
|
||||
}
|
||||
provider.release();
|
||||
}
|
||||
|
||||
return result;
|
||||
|
@ -13,8 +13,6 @@ import com.etesync.syncadapter.R;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import lombok.ToString;
|
||||
|
||||
/**
|
||||
* Created by tal on 30/03/17.
|
||||
*/
|
||||
@ -75,7 +73,6 @@ public class ResultFragment extends DialogFragment {
|
||||
.create();
|
||||
}
|
||||
|
||||
@ToString
|
||||
public static class ImportResult implements Serializable {
|
||||
public long total;
|
||||
public long added;
|
||||
@ -89,6 +86,12 @@ public class ResultFragment extends DialogFragment {
|
||||
public long getSkipped() {
|
||||
return total - (added + updated);
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
@java.lang.SuppressWarnings("all")
|
||||
public java.lang.String toString() {
|
||||
return "ResultFragment.ImportResult(total=" + this.total + ", added=" + this.added + ", updated=" + this.updated + ", e=" + this.e + ")";
|
||||
}
|
||||
}
|
||||
|
||||
public interface OnImportCallback {
|
||||
|
@ -25,7 +25,6 @@ import java.util.Map;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import lombok.ToString;
|
||||
import okhttp3.HttpUrl;
|
||||
import okhttp3.OkHttpClient;
|
||||
|
||||
@ -84,7 +83,6 @@ public class BaseConfigurationFinder {
|
||||
|
||||
// data classes
|
||||
|
||||
@ToString(exclude={"logs", "authtoken", "rawPassword", "password"})
|
||||
public static class Configuration implements Serializable {
|
||||
// We have to use URI here because HttpUrl is not serializable!
|
||||
|
||||
@ -98,9 +96,14 @@ public class BaseConfigurationFinder {
|
||||
this.failed = failed;
|
||||
}
|
||||
|
||||
@ToString
|
||||
public static class ServiceInfo implements Serializable {
|
||||
public final Map<String, CollectionInfo> collections = new HashMap<>();
|
||||
|
||||
@java.lang.Override
|
||||
@java.lang.SuppressWarnings("all")
|
||||
public java.lang.String toString() {
|
||||
return "BaseConfigurationFinder.Configuration.ServiceInfo(collections=" + this.collections + ")";
|
||||
}
|
||||
}
|
||||
|
||||
public final URI url;
|
||||
@ -122,6 +125,12 @@ public class BaseConfigurationFinder {
|
||||
public boolean isFailed() {
|
||||
return failed;
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
@java.lang.SuppressWarnings("all")
|
||||
public java.lang.String toString() {
|
||||
return "BaseConfigurationFinder.Configuration(url=" + this.url + ", userName=" + this.userName + ", keyPair=" + this.keyPair + ", cardDAV=" + this.cardDAV + ", calDAV=" + this.calDAV + ", error=" + this.error + ", failed=" + this.isFailed() + ")";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user