X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/f1861497875cd33e3fa09df48fad140864161e60..HEAD:/src/com/owncloud/android/authentication/PassCodeManager.java?ds=sidebyside diff --git a/src/com/owncloud/android/authentication/PassCodeManager.java b/src/com/owncloud/android/authentication/PassCodeManager.java index ee1ba714..e60233df 100644 --- a/src/com/owncloud/android/authentication/PassCodeManager.java +++ b/src/com/owncloud/android/authentication/PassCodeManager.java @@ -1,12 +1,34 @@ +/** + * ownCloud Android client application + * + * @author David A. Velasco + * Copyright (C) 2015 ownCloud Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ package com.owncloud.android.authentication; import android.app.Activity; +import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; +import android.os.PowerManager; import android.preference.PreferenceManager; +import android.view.WindowManager; import com.owncloud.android.MainApp; -import com.owncloud.android.ui.activity.PinCodeActivity; +import com.owncloud.android.ui.activity.PassCodeActivity; import java.util.HashSet; import java.util.Set; @@ -17,12 +39,12 @@ public class PassCodeManager { static { sExemptOfPasscodeActivites = new HashSet(); - sExemptOfPasscodeActivites.add(PinCodeActivity.class); + sExemptOfPasscodeActivites.add(PassCodeActivity.class); // other activities may be exempted, if needed } private static int PASS_CODE_TIMEOUT = 1000; - // keeping a "low" value (not 0) is the easiest way to avoid prevent the pass code is requested on rotations + // keeping a "low" positive value is the easiest way to prevent the pass code is requested on rotations public static PassCodeManager mPassCodeManagerInstance = null; @@ -38,18 +60,27 @@ public class PassCodeManager { protected PassCodeManager() {}; + public void onActivityCreated(Activity activity) { + if (passCodeIsEnabled()) { + activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE); + } else { + activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_SECURE); + } + } + public void onActivityStarted(Activity activity) { if (!sExemptOfPasscodeActivites.contains(activity.getClass()) && passCodeShouldBeRequested() ){ - Intent i = new Intent(MainApp.getAppContext(), PinCodeActivity.class); - i.setAction(PinCodeActivity.ACTION_REQUEST); + Intent i = new Intent(MainApp.getAppContext(), PassCodeActivity.class); + i.setAction(PassCodeActivity.ACTION_REQUEST); i.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); activity.startActivity(i); + } - mVisibleActivitiesCounter++; // AFTER passCodeShouldBeRequested was checked + mVisibleActivitiesCounter++; // keep it AFTER passCodeShouldBeRequested was checked } public void onActivityStopped(Activity activity) { @@ -57,22 +88,28 @@ public class PassCodeManager { mVisibleActivitiesCounter--; } setUnlockTimestamp(); + PowerManager powerMgr = (PowerManager) activity.getSystemService(Context.POWER_SERVICE); + if (passCodeIsEnabled() && powerMgr != null && !powerMgr.isScreenOn()) { + activity.moveTaskToBack(true); + } + } + + private void setUnlockTimestamp() { + mTimestamp = System.currentTimeMillis(); } private boolean passCodeShouldBeRequested(){ if ((System.currentTimeMillis() - mTimestamp) > PASS_CODE_TIMEOUT && mVisibleActivitiesCounter <= 0 ){ - SharedPreferences appPrefs = PreferenceManager.getDefaultSharedPreferences(MainApp.getAppContext()); - if (appPrefs.getBoolean("set_pincode", false)) { - return true; - } + return passCodeIsEnabled(); } return false; } - private void setUnlockTimestamp() { - mTimestamp = System.currentTimeMillis(); + private boolean passCodeIsEnabled() { + SharedPreferences appPrefs = PreferenceManager.getDefaultSharedPreferences(MainApp.getAppContext()); + return (appPrefs.getBoolean("set_pincode", false)); } }