From aafa7780f62719c77d69ba26e1a6ee393beaa1b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Brey=20Vilas?= Date: Tue, 15 Feb 2022 10:24:24 +0100 Subject: [PATCH] PassCodeActivity: update lock timestamp when lock has just been set MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Prevents asking for pass immediately after setting it Signed-off-by: Álvaro Brey Vilas --- .../owncloud/android/authentication/PassCodeManager.kt | 6 +++++- .../owncloud/android/ui/activity/PassCodeActivity.java | 8 ++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/owncloud/android/authentication/PassCodeManager.kt b/src/main/java/com/owncloud/android/authentication/PassCodeManager.kt index 112ca041f7..23f0f02786 100644 --- a/src/main/java/com/owncloud/android/authentication/PassCodeManager.kt +++ b/src/main/java/com/owncloud/android/authentication/PassCodeManager.kt @@ -74,7 +74,7 @@ class PassCodeManager(private val preferences: AppPreferences) { } if (!askedForPin && preferences.lockTimestamp != 0L) { - preferences.lockTimestamp = SystemClock.elapsedRealtime() + updateLockTimestamp() } if (!isExemptActivity(activity)) { @@ -117,6 +117,10 @@ class PassCodeManager(private val preferences: AppPreferences) { } } + fun updateLockTimestamp() { + preferences.lockTimestamp = SystemClock.elapsedRealtime() + } + /** * `true` if the time elapsed since last unlock is longer than [PASS_CODE_TIMEOUT] and no activities are visible */ diff --git a/src/main/java/com/owncloud/android/ui/activity/PassCodeActivity.java b/src/main/java/com/owncloud/android/ui/activity/PassCodeActivity.java index afe0d7ed7a..225692ac38 100644 --- a/src/main/java/com/owncloud/android/ui/activity/PassCodeActivity.java +++ b/src/main/java/com/owncloud/android/ui/activity/PassCodeActivity.java @@ -41,6 +41,7 @@ import com.nextcloud.client.di.Injectable; import com.nextcloud.client.preferences.AppPreferences; import com.nextcloud.client.preferences.AppPreferencesImpl; import com.owncloud.android.R; +import com.owncloud.android.authentication.PassCodeManager; import com.owncloud.android.databinding.PasscodelockBinding; import com.owncloud.android.lib.common.utils.Log_OC; import com.owncloud.android.utils.theme.ThemeButtonUtils; @@ -74,6 +75,7 @@ public class PassCodeActivity extends AppCompatActivity implements Injectable { public final static String PREFERENCE_PASSCODE_D4 = "PrefPinCode4"; @Inject AppPreferences preferences; + @Inject PassCodeManager passCodeManager; private PasscodelockBinding binding; private final EditText[] passCodeEditTexts = new EditText[4]; private String [] passCodeDigits = {"","","",""}; @@ -242,7 +244,7 @@ public class PassCodeActivity extends AppCompatActivity implements Injectable { preferences.resetPinWrongAttempts(); /// pass code accepted in request, user is allowed to access the app - AppPreferencesImpl.fromContext(this).setLockTimestamp(SystemClock.elapsedRealtime()); + passCodeManager.updateLockTimestamp(); hideSoftKeyboard(); finish(); @@ -254,7 +256,7 @@ public class PassCodeActivity extends AppCompatActivity implements Injectable { } else if (ACTION_CHECK_WITH_RESULT.equals(getIntent().getAction())) { if (checkPassCode()) { - preferences.setLockTimestamp(SystemClock.elapsedRealtime()); + passCodeManager.updateLockTimestamp(); Intent resultIntent = new Intent(); resultIntent.putExtra(KEY_CHECK_RESULT, true); setResult(RESULT_OK, resultIntent); @@ -392,6 +394,8 @@ public class PassCodeActivity extends AppCompatActivity implements Injectable { setResult(RESULT_OK, resultIntent); + passCodeManager.updateLockTimestamp(); + finish(); }