From 1ab32be0f6d87458b90fe21e4ef0d15bb0ece154 Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Fri, 21 Apr 2017 11:19:10 +0100 Subject: [PATCH] Add support for read-only journals. This change only works for calendars at the moment, because we don't have shared address books anyway. This is currently only implemented in the client, and only as a read-only attribute, you can't make a journal read-only yet. This requires server support that is not yet there, but it's better to be ready for this sooner rather than later. --- app/src/main/java/com/etesync/syncadapter/App.java | 2 +- .../etesync/syncadapter/journalmanager/JournalManager.java | 3 +++ .../java/com/etesync/syncadapter/model/CollectionInfo.java | 4 ---- .../main/java/com/etesync/syncadapter/model/JournalModel.java | 3 +++ .../java/com/etesync/syncadapter/resource/LocalCalendar.java | 2 +- .../etesync/syncadapter/syncadapter/SyncAdapterService.java | 1 + .../main/java/com/etesync/syncadapter/ui/AccountActivity.java | 2 +- 7 files changed, 10 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/com/etesync/syncadapter/App.java b/app/src/main/java/com/etesync/syncadapter/App.java index 478de93d..a899785a 100644 --- a/app/src/main/java/com/etesync/syncadapter/App.java +++ b/app/src/main/java/com/etesync/syncadapter/App.java @@ -228,7 +228,7 @@ public class App extends Application { public EntityDataStore getData() { if (dataStore == null) { // override onUpgrade to handle migrating to a new version - DatabaseSource source = new MyDatabaseSource(this, Models.DEFAULT, 3); + DatabaseSource source = new MyDatabaseSource(this, Models.DEFAULT, 4); Configuration configuration = source.getConfiguration(); dataStore = new EntityDataStore<>(configuration); } diff --git a/app/src/main/java/com/etesync/syncadapter/journalmanager/JournalManager.java b/app/src/main/java/com/etesync/syncadapter/journalmanager/JournalManager.java index d681b024..b04f350f 100644 --- a/app/src/main/java/com/etesync/syncadapter/journalmanager/JournalManager.java +++ b/app/src/main/java/com/etesync/syncadapter/journalmanager/JournalManager.java @@ -137,6 +137,9 @@ public class JournalManager extends BaseManager { @Getter private int version = -1; + @Getter + private boolean readOnly = false; + private transient byte[] hmac = null; @SuppressWarnings("unused") diff --git a/app/src/main/java/com/etesync/syncadapter/model/CollectionInfo.java b/app/src/main/java/com/etesync/syncadapter/model/CollectionInfo.java index 1e7b0abb..f1f99c48 100644 --- a/app/src/main/java/com/etesync/syncadapter/model/CollectionInfo.java +++ b/app/src/main/java/com/etesync/syncadapter/model/CollectionInfo.java @@ -43,8 +43,6 @@ public class CollectionInfo implements Serializable { public String uid; - @Expose - public boolean readOnly; @Expose public String displayName, description; @Expose @@ -64,7 +62,6 @@ public class CollectionInfo implements Serializable { CollectionInfo info = new CollectionInfo(); info.displayName = "Default"; info.selected = true; - info.readOnly = false; info.type = service; return info; @@ -85,7 +82,6 @@ public class CollectionInfo implements Serializable { info.serviceID = values.getAsInteger(Collections.SERVICE_ID); info.uid = values.getAsString(Collections.URL); - info.readOnly = values.getAsInteger(Collections.READ_ONLY) != 0; info.displayName = values.getAsString(Collections.DISPLAY_NAME); info.description = values.getAsString(Collections.DESCRIPTION); diff --git a/app/src/main/java/com/etesync/syncadapter/model/JournalModel.java b/app/src/main/java/com/etesync/syncadapter/model/JournalModel.java index ad383ff1..7e6b4fe3 100644 --- a/app/src/main/java/com/etesync/syncadapter/model/JournalModel.java +++ b/app/src/main/java/com/etesync/syncadapter/model/JournalModel.java @@ -47,6 +47,9 @@ public class JournalModel { boolean deleted; + @Column(value = "false") + boolean readOnly; + @PostLoad void afterLoad() { this.info.serviceID = this.serviceModel.id; diff --git a/app/src/main/java/com/etesync/syncadapter/resource/LocalCalendar.java b/app/src/main/java/com/etesync/syncadapter/resource/LocalCalendar.java index 89854c14..44ed7ab9 100644 --- a/app/src/main/java/com/etesync/syncadapter/resource/LocalCalendar.java +++ b/app/src/main/java/com/etesync/syncadapter/resource/LocalCalendar.java @@ -103,7 +103,7 @@ public class LocalCalendar extends AndroidCalendar implements LocalCollection { if (withColor) values.put(Calendars.CALENDAR_COLOR, info.color != null ? info.color : defaultColor); - if (info.readOnly) + if (journalEntity.isReadOnly()) values.put(Calendars.CALENDAR_ACCESS_LEVEL, Calendars.CAL_ACCESS_READ); else { values.put(Calendars.CALENDAR_ACCESS_LEVEL, Calendars.CAL_ACCESS_OWNER); diff --git a/app/src/main/java/com/etesync/syncadapter/syncadapter/SyncAdapterService.java b/app/src/main/java/com/etesync/syncadapter/syncadapter/SyncAdapterService.java index d9ee2705..06946fc0 100644 --- a/app/src/main/java/com/etesync/syncadapter/syncadapter/SyncAdapterService.java +++ b/app/src/main/java/com/etesync/syncadapter/syncadapter/SyncAdapterService.java @@ -198,6 +198,7 @@ public abstract class SyncAdapterService extends Service { JournalEntity journalEntity = JournalEntity.fetchOrCreate(data, collection); journalEntity.setOwner(journal.getOwner()); journalEntity.setEncryptedKey(journal.getKey()); + journalEntity.setReadOnly(journal.isReadOnly()); journalEntity.setDeleted(false); data.upsert(journalEntity); diff --git a/app/src/main/java/com/etesync/syncadapter/ui/AccountActivity.java b/app/src/main/java/com/etesync/syncadapter/ui/AccountActivity.java index 67049265..1936a777 100644 --- a/app/src/main/java/com/etesync/syncadapter/ui/AccountActivity.java +++ b/app/src/main/java/com/etesync/syncadapter/ui/AccountActivity.java @@ -414,7 +414,7 @@ public class AccountActivity extends AppCompatActivity implements Toolbar.OnMenu } View readOnly = v.findViewById(R.id.read_only); - readOnly.setVisibility(info.readOnly ? View.VISIBLE : View.GONE); + readOnly.setVisibility(journalEntity.isReadOnly() ? View.VISIBLE : View.GONE); final View shared = v.findViewById(R.id.shared); shared.setVisibility(account.name.equals(journalEntity.getOwner()) ? View.GONE : View.VISIBLE);