Resolve merge conflicts

This commit is contained in:
Dominik Schürmann
2016-10-27 19:03:37 +02:00
89 changed files with 2152 additions and 1657 deletions

View File

@@ -57,7 +57,8 @@ public class EmailKeyHelper {
// Put them in a list and import
ArrayList<ParcelableKeyRing> keys = new ArrayList<>(entries.size());
for (ImportKeysListEntry entry : entries) {
keys.add(new ParcelableKeyRing(entry.getFingerprintHex(), entry.getKeyIdHex()));
keys.add(new ParcelableKeyRing(entry.getFingerprintHex(), entry.getKeyIdHex(), null,
null));
}
mKeyList = keys;
mKeyserver = keyserver;
@@ -97,7 +98,7 @@ public class EmailKeyHelper {
Set<ImportKeysListEntry> keys = new HashSet<>();
try {
for (ImportKeysListEntry key : keyServer.search(mail, proxy)) {
if (key.isRevoked() || key.isExpired()) continue;
if (key.isRevokedOrExpired()) continue;
for (String userId : key.getUserIds()) {
if (userId.toLowerCase().contains(mail.toLowerCase(Locale.ENGLISH))) {
keys.add(key);

View File

@@ -0,0 +1,17 @@
package org.sufficientlysecure.keychain.util;
import java.util.Iterator;
/**
* An extended iterator interface, which knows the total number of its entries beforehand.
*/
public interface IteratorWithSize<E> extends Iterator<E> {
/**
* Returns the total number of entries in this iterator.
*
* @return the number of entries in this iterator.
*/
int getSize();
}

View File

@@ -0,0 +1,22 @@
package org.sufficientlysecure.keychain.util;
import java.util.LinkedHashMap;
import java.util.Map;
// Source: http://stackoverflow.com/a/1953516
public class LruCache<A, B> extends LinkedHashMap<A, B> {
private final int maxEntries;
public LruCache(final int maxEntries) {
super(maxEntries + 1, 1.0f, true);
this.maxEntries = maxEntries;
}
@Override
protected boolean removeEldestEntry(final Map.Entry<A, B> eldest) {
return super.size() > maxEntries;
}
}

View File

@@ -52,12 +52,40 @@ public class ParcelableFileCache<E extends Parcelable> {
mFilename = filename;
}
public void writeCache(IteratorWithSize<E> it) throws IOException {
writeCache(it.getSize(), it);
public void writeCache(int numEntries, Iterator<E> it) throws IOException {
DataOutputStream oos = getOutputStream();
try {
oos.writeInt(numEntries);
while (it.hasNext()) {
writeParcelable(it.next(), oos);
}
} finally {
oos.close();
}
}
public void writeCache(int numEntries, Iterator<E> it) throws IOException {
public void writeCache(E obj) throws IOException {
DataOutputStream oos = getOutputStream();
try {
oos.writeInt(1);
writeParcelable(obj, oos);
} finally {
oos.close();
}
}
private void writeParcelable(E obj, DataOutputStream oos) throws IOException {
Parcel p = Parcel.obtain(); // creating empty parcel object
p.writeParcelable(obj, 0); // saving bundle as parcel
byte[] buf = p.marshall();
oos.writeInt(buf.length);
oos.write(buf);
p.recycle();
}
private DataOutputStream getOutputStream() throws IOException {
File cacheDir = mContext.getCacheDir();
if (cacheDir == null) {
// https://groups.google.com/forum/#!topic/android-developers/-694j87eXVU
@@ -65,29 +93,12 @@ public class ParcelableFileCache<E extends Parcelable> {
}
File tempFile = new File(mContext.getCacheDir(), mFilename);
DataOutputStream oos = new DataOutputStream(new FileOutputStream(tempFile));
try {
oos.writeInt(numEntries);
while (it.hasNext()) {
Parcel p = Parcel.obtain(); // creating empty parcel object
p.writeParcelable(it.next(), 0); // saving bundle as parcel
byte[] buf = p.marshall();
oos.writeInt(buf.length);
oos.write(buf);
p.recycle();
}
} finally {
oos.close();
}
return new DataOutputStream(new FileOutputStream(tempFile));
}
/**
* Reads from cache file and deletes it afterward. Convenience function for readCache(boolean).
*
* @return an IteratorWithSize object containing entries read from the cache file
* @throws IOException
*/
@@ -97,10 +108,11 @@ public class ParcelableFileCache<E extends Parcelable> {
/**
* Reads entries from a cache file and returns an IteratorWithSize object containing the entries
*
* @param deleteAfterRead if true, the cache file will be deleted after being read
* @return an IteratorWithSize object containing entries read from the cache file
* @throws IOException if cache directory/parcel import file does not exist, or a read error
* occurs
* occurs
*/
public IteratorWithSize<E> readCache(final boolean deleteAfterRead) throws IOException {
@@ -205,7 +217,6 @@ public class ParcelableFileCache<E extends Parcelable> {
}
public boolean delete() throws IOException {
File cacheDir = mContext.getCacheDir();
if (cacheDir == null) {
// https://groups.google.com/forum/#!topic/android-developers/-694j87eXVU
@@ -216,12 +227,4 @@ public class ParcelableFileCache<E extends Parcelable> {
return tempFile.delete();
}
/** As the name implies, this is an extended iterator interface, which
* knows the total number of its entries beforehand.
*/
public static interface IteratorWithSize<E> extends Iterator<E> {
/** Returns the number of total entries in this iterator. */
int getSize();
}
}