inline-ttl: support "screen off" in preference
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -321,6 +321,7 @@ public class Preferences {
|
||||
public static final ArrayList<Integer> CACHE_TTLS;
|
||||
static {
|
||||
HashMap<Integer,Integer> 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<String> 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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user