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