From: David A. Velasco Date: Mon, 4 May 2015 08:52:57 +0000 (+0200) Subject: When pass code is enabled, the app is sent to background if the screen is turned... X-Git-Tag: test~19^2~12 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/3eb64bcdd745438391038a7ba7c1c8b29fc00516?ds=inline;hp=-c When pass code is enabled, the app is sent to background if the screen is turned off and the windows are made secure to prevent they are rendered in the 'recents' menu --- 3eb64bcdd745438391038a7ba7c1c8b29fc00516 diff --git a/src/com/owncloud/android/MainApp.java b/src/com/owncloud/android/MainApp.java index 486ca652..657469ef 100644 --- a/src/com/owncloud/android/MainApp.java +++ b/src/com/owncloud/android/MainApp.java @@ -88,6 +88,7 @@ public class MainApp extends Application { @Override public void onActivityCreated(Activity activity, Bundle savedInstanceState) { Log_OC.d(activity.getClass().getSimpleName(), "onCreate(Bundle) starting" ); + PassCodeManager.getPassCodeManager().onActivityCreated(activity); } @Override diff --git a/src/com/owncloud/android/authentication/PassCodeManager.java b/src/com/owncloud/android/authentication/PassCodeManager.java index ee1ba714..a49b2ab8 100644 --- a/src/com/owncloud/android/authentication/PassCodeManager.java +++ b/src/com/owncloud/android/authentication/PassCodeManager.java @@ -1,9 +1,13 @@ 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.View; +import android.view.WindowManager; import com.owncloud.android.MainApp; import com.owncloud.android.ui.activity.PinCodeActivity; @@ -22,7 +26,7 @@ public class PassCodeManager { } 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,6 +42,14 @@ 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() @@ -47,9 +59,10 @@ public class PassCodeManager { i.setAction(PinCodeActivity.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 +70,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)); } } diff --git a/src/com/owncloud/android/ui/activity/FileDisplayActivity.java b/src/com/owncloud/android/ui/activity/FileDisplayActivity.java index e0956608..c9c8420e 100644 --- a/src/com/owncloud/android/ui/activity/FileDisplayActivity.java +++ b/src/com/owncloud/android/ui/activity/FileDisplayActivity.java @@ -65,7 +65,6 @@ import com.actionbarsherlock.view.Window; import com.owncloud.android.BuildConfig; import com.owncloud.android.MainApp; import com.owncloud.android.R; -import com.owncloud.android.authentication.PassCodeManager; import com.owncloud.android.datamodel.OCFile; import com.owncloud.android.files.services.FileDownloader; import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder;