From 7eafe5d1e81fe3f72e66b600736e55f8eb21f038 Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Wed, 18 Nov 2015 19:23:40 +0100 Subject: inline-ttl: support "screen off" in preference --- .../keychain/service/PassphraseCacheService.java | 13 ++++++------- .../org/sufficientlysecure/keychain/util/Preferences.java | 4 +++- 2 files changed, 9 insertions(+), 8 deletions(-) (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/PassphraseCacheService.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/PassphraseCacheService.java index be14f1586..606daabed 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/PassphraseCacheService.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/PassphraseCacheService.java @@ -27,8 +27,6 @@ import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.os.Binder; -import android.os.Build.VERSION; -import android.os.Build.VERSION_CODES; import android.os.Bundle; import android.os.Handler; import android.os.HandlerThread; @@ -349,14 +347,14 @@ public class PassphraseCacheService extends Service { case ACTION_PASSPHRASE_CACHE_ADD: { long masterKeyId = intent.getLongExtra(EXTRA_KEY_ID, -1); long subKeyId = intent.getLongExtra(EXTRA_SUBKEY_ID, -1); - long timeoutTime = intent.getIntExtra(EXTRA_TTL, DEFAULT_TTL); + long timeoutTtl = intent.getIntExtra(EXTRA_TTL, DEFAULT_TTL); Passphrase passphrase = intent.getParcelableExtra(EXTRA_PASSPHRASE); String primaryUserID = intent.getStringExtra(EXTRA_USER_ID); Log.d(Constants.TAG, "PassphraseCacheService: Received ACTION_PASSPHRASE_CACHE_ADD intent in onStartCommand() with masterkeyId: " - + masterKeyId + ", subKeyId: " + subKeyId + ", ttl: " + timeoutTime + ", usrId: " + primaryUserID + + masterKeyId + ", subKeyId: " + subKeyId + ", ttl: " + timeoutTtl + ", usrId: " + primaryUserID ); // if we don't cache by specific subkey id, or the requested subkey is the master key, @@ -365,14 +363,15 @@ public class PassphraseCacheService extends Service { Preferences.getPreferences(mContext).getPassphraseCacheSubs() ? subKeyId : masterKeyId; CachedPassphrase cachedPassphrase; - if (timeoutTime == 0) { + if (timeoutTtl == 0L) { cachedPassphrase = CachedPassphrase.getPassphraseLock(passphrase, primaryUserID); } else { - cachedPassphrase = CachedPassphrase.getPassphraseTtlTimeout(passphrase, primaryUserID, timeoutTime); + cachedPassphrase = CachedPassphrase.getPassphraseTtlTimeout(passphrase, primaryUserID, timeoutTtl); + long triggerTime = new Date().getTime() + (timeoutTtl * 1000); // register new alarm with keyId for this passphrase AlarmManager am = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE); - am.set(AlarmManager.RTC_WAKEUP, timeoutTime, buildIntent(this, referenceKeyId)); + am.set(AlarmManager.RTC_WAKEUP, triggerTime, buildIntent(this, referenceKeyId)); } mPassphraseCache.put(referenceKeyId, cachedPassphrase); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/Preferences.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/Preferences.java index 8074d8eb1..cf4e5ad21 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/Preferences.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/Preferences.java @@ -321,6 +321,7 @@ public class Preferences { public static final ArrayList CACHE_TTLS; static { HashMap cacheTtlNames = new HashMap<>(); + cacheTtlNames.put(0, R.string.cache_ttl_lock_screen); cacheTtlNames.put(60 * 5, R.string.cache_ttl_five_minutes); cacheTtlNames.put(60 * 60, R.string.cache_ttl_one_hour); cacheTtlNames.put(60 * 60 * 3, R.string.cache_ttl_three_hours); @@ -353,10 +354,11 @@ public class Preferences { public static CacheTTLPrefs getDefault() { ArrayList ttlStrings = new ArrayList<>(); + ttlStrings.add(Integer.toString(0)); ttlStrings.add(Integer.toString(60 * 5)); ttlStrings.add(Integer.toString(60 * 60)); ttlStrings.add(Integer.toString(60 * 60 * 24)); - return new CacheTTLPrefs(ttlStrings, 60 * 5); + return new CacheTTLPrefs(ttlStrings, 0); } } -- cgit v1.2.3