Add encryption key and account type to caldav

pull/898/head
Alex Baker 5 years ago
parent d694a1a8ec
commit a0d6aada98

File diff suppressed because it is too large Load Diff

@ -58,7 +58,7 @@ import org.tasks.notifications.NotificationDao;
CaldavAccount.class, CaldavAccount.class,
GoogleTaskAccount.class GoogleTaskAccount.class
}, },
version = 70) version = 71)
public abstract class Database extends RoomDatabase { public abstract class Database extends RoomDatabase {
public static final String NAME = "database"; public static final String NAME = "database";

@ -14,6 +14,8 @@ import org.tasks.security.Encryption;
@Entity(tableName = "caldav_accounts") @Entity(tableName = "caldav_accounts")
public class CaldavAccount implements Parcelable { public class CaldavAccount implements Parcelable {
public static final int TYPE_CALDAV = 0;
public static final int TYPE_ETESYNC = 1;
public static final Parcelable.Creator<CaldavAccount> CREATOR = public static final Parcelable.Creator<CaldavAccount> CREATOR =
new Parcelable.Creator<CaldavAccount>() { new Parcelable.Creator<CaldavAccount>() {
@ -53,6 +55,12 @@ public class CaldavAccount implements Parcelable {
@ColumnInfo(name = "cda_repeat") @ColumnInfo(name = "cda_repeat")
private boolean suppressRepeatingTasks; private boolean suppressRepeatingTasks;
@ColumnInfo(name = "cda_encryption_key")
private transient String encryptionKey;
@ColumnInfo(name = "cda_account_type")
private int accountType;
public CaldavAccount() {} public CaldavAccount() {}
@Ignore @Ignore
@ -65,6 +73,8 @@ public class CaldavAccount implements Parcelable {
password = source.readString(); password = source.readString();
error = source.readString(); error = source.readString();
suppressRepeatingTasks = ParcelCompat.readBoolean(source); suppressRepeatingTasks = ParcelCompat.readBoolean(source);
accountType = source.readInt();
encryptionKey = source.readString();
} }
public long getId() { public long getId() {
@ -119,6 +129,18 @@ public class CaldavAccount implements Parcelable {
return encryption.decrypt(password); return encryption.decrypt(password);
} }
public String getEncryptionKey() {
return encryptionKey;
}
public void setEncryptionKey(String encryptionKey) {
this.encryptionKey = encryptionKey;
}
public String getEncryptionPassword(Encryption encryption) {
return encryption.decrypt(encryptionKey);
}
public String getError() { public String getError() {
return error; return error;
} }
@ -135,6 +157,22 @@ public class CaldavAccount implements Parcelable {
this.suppressRepeatingTasks = suppressRepeatingTasks; this.suppressRepeatingTasks = suppressRepeatingTasks;
} }
public int getAccountType() {
return accountType;
}
public void setAccountType(int accountType) {
this.accountType = accountType;
}
public boolean isCaldavAccount() {
return accountType == TYPE_CALDAV;
}
public boolean isEteSyncAccount() {
return accountType == TYPE_ETESYNC;
}
@Override @Override
public String toString() { public String toString() {
return "CaldavAccount{" return "CaldavAccount{"
@ -160,6 +198,11 @@ public class CaldavAccount implements Parcelable {
+ '\'' + '\''
+ ", suppressRepeatingTasks=" + ", suppressRepeatingTasks="
+ suppressRepeatingTasks + suppressRepeatingTasks
+ ", encryptionKey='"
+ encryptionKey
+ '\''
+ ", accountType="
+ accountType
+ '}'; + '}';
} }
@ -180,6 +223,9 @@ public class CaldavAccount implements Parcelable {
if (suppressRepeatingTasks != that.suppressRepeatingTasks) { if (suppressRepeatingTasks != that.suppressRepeatingTasks) {
return false; return false;
} }
if (accountType != that.accountType) {
return false;
}
if (uuid != null ? !uuid.equals(that.uuid) : that.uuid != null) { if (uuid != null ? !uuid.equals(that.uuid) : that.uuid != null) {
return false; return false;
} }
@ -195,7 +241,12 @@ public class CaldavAccount implements Parcelable {
if (password != null ? !password.equals(that.password) : that.password != null) { if (password != null ? !password.equals(that.password) : that.password != null) {
return false; return false;
} }
return error != null ? error.equals(that.error) : that.error == null; if (error != null ? !error.equals(that.error) : that.error != null) {
return false;
}
return encryptionKey != null
? encryptionKey.equals(that.encryptionKey)
: that.encryptionKey == null;
} }
@Override @Override
@ -208,6 +259,8 @@ public class CaldavAccount implements Parcelable {
result = 31 * result + (password != null ? password.hashCode() : 0); result = 31 * result + (password != null ? password.hashCode() : 0);
result = 31 * result + (error != null ? error.hashCode() : 0); result = 31 * result + (error != null ? error.hashCode() : 0);
result = 31 * result + (suppressRepeatingTasks ? 1 : 0); result = 31 * result + (suppressRepeatingTasks ? 1 : 0);
result = 31 * result + (encryptionKey != null ? encryptionKey.hashCode() : 0);
result = 31 * result + accountType;
return result; return result;
} }
@ -226,5 +279,7 @@ public class CaldavAccount implements Parcelable {
dest.writeString(password); dest.writeString(password);
dest.writeString(error); dest.writeString(error);
ParcelCompat.writeBoolean(dest, suppressRepeatingTasks); ParcelCompat.writeBoolean(dest, suppressRepeatingTasks);
dest.writeInt(accountType);
dest.writeString(encryptionKey);
} }
} }

@ -381,6 +381,16 @@ public class Migrations {
} }
}; };
private static final Migration MIGRATION_70_71 =
new Migration(70, 71) {
@Override
public void migrate(@NonNull SupportSQLiteDatabase database) {
database.execSQL("ALTER TABLE `caldav_account` ADD COLUMN `cda_encryption_key` TEXT");
database.execSQL(
"ALTER TABLE `caldav_account` ADD COLUMN `cda_account_type` INTEGER NOT NULL DEFAULT 0");
}
};
public static final Migration[] MIGRATIONS = public static final Migration[] MIGRATIONS =
new Migration[] { new Migration[] {
MIGRATION_35_36, MIGRATION_35_36,
@ -408,7 +418,8 @@ public class Migrations {
MIGRATION_66_67, MIGRATION_66_67,
MIGRATION_67_68, MIGRATION_67_68,
MIGRATION_68_69, MIGRATION_68_69,
MIGRATION_69_70 MIGRATION_69_70,
MIGRATION_70_71
}; };
private static Migration NOOP(int from, int to) { private static Migration NOOP(int from, int to) {

Loading…
Cancel
Save