mirror of
https://github.com/oxen-io/session-android.git
synced 2025-02-20 06:28:27 +00:00
Add synchronized access to cache
This commit is contained in:
parent
ef6a5c69af
commit
6230abb524
@ -34,17 +34,19 @@ public class MessageDisplayHelper {
|
|||||||
};
|
};
|
||||||
|
|
||||||
private static String checkCacheForBody(String body) {
|
private static String checkCacheForBody(String body) {
|
||||||
if (decryptedBodyCache.containsKey(body)) {
|
synchronized (decryptedBodyCache) {
|
||||||
String decryptedBody = decryptedBodyCache.get(body).get();
|
if (decryptedBodyCache.containsKey(body)) {
|
||||||
if (decryptedBody != null) {
|
String decryptedBody = decryptedBodyCache.get(body).get();
|
||||||
return decryptedBody;
|
if (decryptedBody != null) {
|
||||||
} else {
|
return decryptedBody;
|
||||||
decryptedBodyCache.remove(body);
|
} else {
|
||||||
return null;
|
decryptedBodyCache.remove(body);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getDecryptedMessageBody(MasterCipher bodyCipher, String body) throws InvalidMessageException {
|
public static String getDecryptedMessageBody(MasterCipher bodyCipher, String body) throws InvalidMessageException {
|
||||||
@ -55,11 +57,14 @@ public class MessageDisplayHelper {
|
|||||||
return cacheResult;
|
return cacheResult;
|
||||||
|
|
||||||
String decryptedBody = bodyCipher.decryptBody(body.substring(Prefix.SYMMETRIC_ENCRYPT.length()));
|
String decryptedBody = bodyCipher.decryptBody(body.substring(Prefix.SYMMETRIC_ENCRYPT.length()));
|
||||||
decryptedBodyCache.put(body, new SoftReference<String>(decryptedBody));
|
|
||||||
|
synchronized (decryptedBodyCache) {
|
||||||
|
decryptedBodyCache.put(body, new SoftReference<String>(decryptedBody));
|
||||||
|
}
|
||||||
|
|
||||||
return decryptedBody;
|
return decryptedBody;
|
||||||
}
|
}
|
||||||
|
|
||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user