Refactored location of passcode check: a callback to rule them all
[pub/Android/ownCloud.git] / src / com / owncloud / android / authentication / PinCheck.java
1 package com.owncloud.android.authentication;
2
3 import android.app.Activity;
4 import android.content.SharedPreferences;
5 import android.preference.PreferenceManager;
6
7 import com.owncloud.android.MainApp;
8
9 public class PinCheck extends Activity {
10
11 private static Long timestamp = 0l;
12 private static Long lastStart = 0l; // this must be here because it's called twice - in onCreate and onResume
13 private static int PINCODE_TIMEOUT = 1000;
14
15 public static void setUnlockTimestamp() {
16 timestamp = System.currentTimeMillis();
17 }
18
19 public static boolean checkIfPinEntry(){
20 if ((System.currentTimeMillis() - timestamp) > PINCODE_TIMEOUT &&
21 (System.currentTimeMillis() - lastStart) > PINCODE_TIMEOUT
22 ){
23 SharedPreferences appPrefs = PreferenceManager.getDefaultSharedPreferences(MainApp.getAppContext());
24 if (appPrefs.getBoolean("set_pincode", false)) {
25 lastStart = System.currentTimeMillis();
26 return true;
27 }
28 }
29 return false;
30 }
31 }