Added Fingerprint Support

This commit is contained in:
Flole 2017-02-04 23:03:44 +01:00 committed by AndyScherzinger
parent fb4374d9fc
commit 8da1057f3b
No known key found for this signature in database
GPG key ID: 6CADC7E3523C308B

View file

@ -28,6 +28,7 @@ import android.preference.PreferenceManager;
import android.view.WindowManager;
import com.owncloud.android.MainApp;
import com.owncloud.android.ui.activity.FingerprintActivity;
import com.owncloud.android.ui.activity.PassCodeActivity;
import java.util.HashSet;
@ -40,6 +41,7 @@ public class PassCodeManager {
static {
sExemptOfPasscodeActivites = new HashSet<Class>();
sExemptOfPasscodeActivites.add(PassCodeActivity.class);
sExemptOfPasscodeActivites.add(FingerprintActivity.class);
// other activities may be exempted, if needed
}
@ -61,7 +63,7 @@ public class PassCodeManager {
protected PassCodeManager() {};
public void onActivityCreated(Activity activity) {
if (passCodeIsEnabled()) {
if (passCodeIsEnabled() || fingerprintIsEnabled()) {
activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE);
} else {
activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_SECURE);
@ -80,6 +82,17 @@ public class PassCodeManager {
}
if (!sExemptOfPasscodeActivites.contains(activity.getClass()) &&
fingerprintShouldBeRequested() && FingerprintActivity.isFingerprintReady(MainApp.getAppContext())
){
Intent i = new Intent(MainApp.getAppContext(), FingerprintActivity.class);
i.setAction(PassCodeActivity.ACTION_CHECK);
i.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
activity.startActivity(i);
}
mVisibleActivitiesCounter++; // keep it AFTER passCodeShouldBeRequested was checked
}
@ -89,7 +102,7 @@ public class PassCodeManager {
}
setUnlockTimestamp();
PowerManager powerMgr = (PowerManager) activity.getSystemService(Context.POWER_SERVICE);
if (passCodeIsEnabled() && powerMgr != null && !powerMgr.isScreenOn()) {
if ((passCodeIsEnabled() || fingerprintIsEnabled())&& powerMgr != null && !powerMgr.isScreenOn()) {
activity.moveTaskToBack(true);
}
}
@ -112,4 +125,18 @@ public class PassCodeManager {
return (appPrefs.getBoolean(PassCodeActivity.PREFERENCE_SET_PASSCODE, false));
}
private boolean fingerprintShouldBeRequested(){
if ((System.currentTimeMillis() - mTimestamp) > PASS_CODE_TIMEOUT &&
mVisibleActivitiesCounter <= 0
){
return fingerprintIsEnabled();
}
return false;
}
private boolean fingerprintIsEnabled() {
SharedPreferences appPrefs = PreferenceManager.getDefaultSharedPreferences(MainApp.getAppContext());
return (appPrefs.getBoolean(FingerprintActivity.PREFERENCE_USE_FINGERPRINT, false));
}
}