From d2df3c90273736a130f92b6ce51a3a41a63f3011 Mon Sep 17 00:00:00 2001 From: Ricki Hirner Date: Thu, 17 Nov 2016 19:58:08 +0100 Subject: [PATCH] Rename account: don't crash when content providers are not accessible --- app/build.gradle | 2 +- .../at/bitfire/davdroid/resource/LocalAddressBook.java | 8 +++++--- .../java/at/bitfire/davdroid/resource/LocalTaskList.java | 8 +++++--- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 17a876b2..63e92fb0 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -17,7 +17,7 @@ android { minSdkVersion 15 targetSdkVersion 24 - versionCode 128 + versionCode 129 buildConfigField "long", "buildTime", System.currentTimeMillis() + "L" buildConfigField "boolean", "customCerts", "true" diff --git a/app/src/main/java/at/bitfire/davdroid/resource/LocalAddressBook.java b/app/src/main/java/at/bitfire/davdroid/resource/LocalAddressBook.java index e21762e3..4320a4ec 100644 --- a/app/src/main/java/at/bitfire/davdroid/resource/LocalAddressBook.java +++ b/app/src/main/java/at/bitfire/davdroid/resource/LocalAddressBook.java @@ -233,9 +233,11 @@ public class LocalAddressBook extends AndroidAddressBook implements LocalCollect public static void onRenameAccount(@NonNull ContentResolver resolver, @NonNull String oldName, @NonNull String newName) throws RemoteException { @Cleanup("release") ContentProviderClient client = resolver.acquireContentProviderClient(ContactsContract.AUTHORITY); - ContentValues values = new ContentValues(1); - values.put(RawContacts.ACCOUNT_NAME, newName); - client.update(RawContacts.CONTENT_URI, values, RawContacts.ACCOUNT_NAME + "=?", new String[] { oldName }); + if (client != null) { + ContentValues values = new ContentValues(1); + values.put(RawContacts.ACCOUNT_NAME, newName); + client.update(RawContacts.CONTENT_URI, values, RawContacts.ACCOUNT_NAME + "=?", new String[]{oldName}); + } } } diff --git a/app/src/main/java/at/bitfire/davdroid/resource/LocalTaskList.java b/app/src/main/java/at/bitfire/davdroid/resource/LocalTaskList.java index ee0517d2..a6b1414f 100644 --- a/app/src/main/java/at/bitfire/davdroid/resource/LocalTaskList.java +++ b/app/src/main/java/at/bitfire/davdroid/resource/LocalTaskList.java @@ -172,9 +172,11 @@ public class LocalTaskList extends AndroidTaskList implements LocalCollection { 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); - 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 }); + 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}); + } } }