added a service to handle the caching, this'll ensure the cache works while no activity is around, which is better for k9mail integration
it also is a more efficient and much smarter cache, not requiring an own timer thread, just a service that sleeps must of the time, it also is more accurate in cleaning up the entries, ensuring that the worst case of too late removal is 5 seconds
This commit is contained in:
@@ -225,19 +225,30 @@ public class Apg {
|
||||
return cpp.passPhrase;
|
||||
}
|
||||
|
||||
public static void cleanUpCache(int ttl) {
|
||||
public static int cleanUpCache(int ttl, int initialDelay) {
|
||||
int delay = initialDelay;
|
||||
long realTtl = ttl * 1000;
|
||||
long now = new Date().getTime();
|
||||
|
||||
Vector<Long> oldKeys = new Vector<Long>();
|
||||
for (Map.Entry<Long, CachedPassPhrase> pair : mPassPhraseCache.entrySet()) {
|
||||
if ((now - pair.getValue().timestamp) >= 1000 * ttl) {
|
||||
long lived = now - pair.getValue().timestamp;
|
||||
if (lived >= realTtl) {
|
||||
oldKeys.add(pair.getKey());
|
||||
} else {
|
||||
// see, whether the remaining time for this cache entry improves our
|
||||
// check delay
|
||||
long nextCheck = realTtl - lived + 1000;
|
||||
if (nextCheck < delay) {
|
||||
delay = (int)nextCheck;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (long keyId : oldKeys) {
|
||||
mPassPhraseCache.remove(keyId);
|
||||
}
|
||||
|
||||
return delay;
|
||||
}
|
||||
|
||||
public static PGPSecretKey createKey(Context context,
|
||||
|
||||
Reference in New Issue
Block a user