mirror of
https://github.com/nextcloud/android.git
synced 2024-11-23 21:55:48 +03:00
Prevent that PIN code is requested when system windows partially overlapping the app disappear and the app is resumed
This commit is contained in:
parent
e0867d2b28
commit
84e99c3cc7
8 changed files with 85 additions and 78 deletions
|
@ -30,7 +30,7 @@ import android.os.Build;
|
|||
import android.os.Bundle;
|
||||
|
||||
import com.owncloud.android.authentication.AuthenticatorActivity;
|
||||
import com.owncloud.android.authentication.PinCheck;
|
||||
import com.owncloud.android.authentication.PassCodeManager;
|
||||
import com.owncloud.android.datamodel.ThumbnailsCacheManager;
|
||||
import com.owncloud.android.lib.common.OwnCloudClientManagerFactory;
|
||||
import com.owncloud.android.lib.common.OwnCloudClientManagerFactory.Policy;
|
||||
|
@ -52,14 +52,6 @@ public class MainApp extends Application {
|
|||
|
||||
private static final String AUTH_ON = "on";
|
||||
|
||||
private static final Set<String> sExemptOfPasscodeActivites;
|
||||
|
||||
static {
|
||||
sExemptOfPasscodeActivites = new HashSet<String>();
|
||||
sExemptOfPasscodeActivites.add(AuthenticatorActivity.class.getCanonicalName());
|
||||
sExemptOfPasscodeActivites.add(PinCodeActivity.class.getCanonicalName());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private static final String POLICY_SINGLE_SESSION_PER_ACCOUNT = "single session per account";
|
||||
@SuppressWarnings("unused")
|
||||
|
@ -106,31 +98,23 @@ public class MainApp extends Application {
|
|||
@Override
|
||||
public void onActivityStarted(Activity activity) {
|
||||
Log_OC.d(TAG, activity.getClass().getSimpleName() + " in onStart()" );
|
||||
PassCodeManager.getPassCodeManager().onActivityStarted(activity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityResumed(Activity activity) {
|
||||
Log_OC.d(TAG, activity.getClass().getSimpleName() + " in onResume()" );
|
||||
if (!sExemptOfPasscodeActivites.contains(activity.getClass().getCanonicalName()) &&
|
||||
PinCheck.checkIfPinEntry()
|
||||
){
|
||||
Intent i = new Intent(MainApp.getAppContext(), PinCodeActivity.class);
|
||||
//i.putExtra(PinCodeActivity.EXTRA_ACTIVITY, activity.getClass().getSimpleName());
|
||||
i.setAction(PinCodeActivity.ACTION_REQUEST);
|
||||
activity.startActivity(i);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityPaused(Activity activity) {
|
||||
Log_OC.d(TAG, activity.getClass().getSimpleName() + " in onPause()");
|
||||
PinCheck.setUnlockTimestamp();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityStopped(Activity activity) {
|
||||
Log_OC.d(TAG, activity.getClass().getSimpleName() + " in onStop()" );
|
||||
|
||||
PassCodeManager.getPassCodeManager().onActivityStopped(activity);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
76
src/com/owncloud/android/authentication/PasscodeManager.java
Normal file
76
src/com/owncloud/android/authentication/PasscodeManager.java
Normal file
|
@ -0,0 +1,76 @@
|
|||
package com.owncloud.android.authentication;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.preference.PreferenceManager;
|
||||
|
||||
import com.owncloud.android.MainApp;
|
||||
import com.owncloud.android.ui.activity.PinCodeActivity;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class PassCodeManager {
|
||||
|
||||
private static final Set<Class> sExemptOfPasscodeActivites;
|
||||
|
||||
static {
|
||||
sExemptOfPasscodeActivites = new HashSet<Class>();
|
||||
sExemptOfPasscodeActivites.add(AuthenticatorActivity.class); // maybe not so good idea
|
||||
sExemptOfPasscodeActivites.add(PinCodeActivity.class);
|
||||
}
|
||||
|
||||
private static int PASS_CODE_TIMEOUT = 1000;
|
||||
|
||||
public static PassCodeManager mPassCodeManagerInstance = null;
|
||||
|
||||
public static PassCodeManager getPassCodeManager() {
|
||||
if (mPassCodeManagerInstance == null) {
|
||||
mPassCodeManagerInstance = new PassCodeManager();
|
||||
}
|
||||
return mPassCodeManagerInstance;
|
||||
}
|
||||
|
||||
private Long mTimestamp = 0l;
|
||||
private int mVisibleActivitiesCounter = 0;
|
||||
|
||||
protected PassCodeManager() {};
|
||||
|
||||
public void onActivityStarted(Activity activity) {
|
||||
if (!sExemptOfPasscodeActivites.contains(activity.getClass()) &&
|
||||
passCodeShouldBeRequested()
|
||||
){
|
||||
|
||||
Intent i = new Intent(MainApp.getAppContext(), PinCodeActivity.class);
|
||||
i.setAction(PinCodeActivity.ACTION_REQUEST);
|
||||
activity.startActivity(i);
|
||||
}
|
||||
|
||||
mVisibleActivitiesCounter++; // AFTER passCodeShouldBeRequested was checked
|
||||
}
|
||||
|
||||
public void onActivityStopped(Activity activity) {
|
||||
if (mVisibleActivitiesCounter > 0) {
|
||||
mVisibleActivitiesCounter--;
|
||||
}
|
||||
setUnlockTimestamp();
|
||||
}
|
||||
|
||||
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 false;
|
||||
}
|
||||
|
||||
private void setUnlockTimestamp() {
|
||||
mTimestamp = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,31 +0,0 @@
|
|||
package com.owncloud.android.authentication;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.SharedPreferences;
|
||||
import android.preference.PreferenceManager;
|
||||
|
||||
import com.owncloud.android.MainApp;
|
||||
|
||||
public class PinCheck extends Activity {
|
||||
|
||||
private static Long timestamp = 0l;
|
||||
private static Long lastStart = 0l; // this must be here because it's called twice - in onCreate and onResume
|
||||
private static int PINCODE_TIMEOUT = 1000;
|
||||
|
||||
public static void setUnlockTimestamp() {
|
||||
timestamp = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public static boolean checkIfPinEntry(){
|
||||
if ((System.currentTimeMillis() - timestamp) > PINCODE_TIMEOUT &&
|
||||
(System.currentTimeMillis() - lastStart) > PINCODE_TIMEOUT
|
||||
){
|
||||
SharedPreferences appPrefs = PreferenceManager.getDefaultSharedPreferences(MainApp.getAppContext());
|
||||
if (appPrefs.getBoolean("set_pincode", false)) {
|
||||
lastStart = System.currentTimeMillis();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -65,7 +65,7 @@ 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.PinCheck;
|
||||
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;
|
||||
|
@ -164,14 +164,6 @@ OnSslUntrustedCertListener, OnEnforceableRefreshListener {
|
|||
|
||||
super.onCreate(savedInstanceState); // this calls onAccountChanged() when ownCloud Account is valid
|
||||
|
||||
/* TODO remove
|
||||
if (PinCheck.checkIfPinEntry()){
|
||||
Intent i = new Intent(MainApp.getAppContext(), PinCodeActivity.class);
|
||||
i.putExtra(PinCodeActivity.EXTRA_ACTIVITY, "FileDisplayActivity");
|
||||
startActivity(i);
|
||||
}
|
||||
*/
|
||||
|
||||
/// grant that FileObserverService is watching favorite files
|
||||
if (savedInstanceState == null) {
|
||||
Intent initObserversIntent = FileObserverService.makeInitIntent(this);
|
||||
|
@ -843,8 +835,6 @@ OnSslUntrustedCertListener, OnEnforceableRefreshListener {
|
|||
mDownloadFinishReceiver = null;
|
||||
}
|
||||
|
||||
PinCheck.setUnlockTimestamp();
|
||||
|
||||
super.onPause();
|
||||
Log_OC.d(TAG, "onPause() end");
|
||||
}
|
||||
|
|
|
@ -21,7 +21,6 @@ package com.owncloud.android.ui.activity;
|
|||
|
||||
import java.util.Arrays;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
|
@ -40,7 +39,7 @@ import android.widget.Toast;
|
|||
import com.actionbarsherlock.app.ActionBar;
|
||||
import com.actionbarsherlock.app.SherlockFragmentActivity;
|
||||
import com.owncloud.android.R;
|
||||
import com.owncloud.android.authentication.PinCheck;
|
||||
import com.owncloud.android.authentication.PassCodeManager;
|
||||
import com.owncloud.android.utils.DisplayUtils;
|
||||
|
||||
public class PinCodeActivity extends SherlockFragmentActivity {
|
||||
|
@ -367,7 +366,8 @@ public class PinCodeActivity extends SherlockFragmentActivity {
|
|||
}
|
||||
|
||||
if (mPinCodeChecked) {
|
||||
PinCheck.setUnlockTimestamp();
|
||||
// TODO remove or update:
|
||||
// PassCodeManager.setUnlockTimestamp();
|
||||
|
||||
if (ACTION_REQUEST.equals(getIntent().getAction())) {
|
||||
finish();
|
||||
|
|
|
@ -58,7 +58,7 @@ import com.owncloud.android.MainApp;
|
|||
import com.owncloud.android.R;
|
||||
import com.owncloud.android.authentication.AccountUtils;
|
||||
import com.owncloud.android.authentication.AuthenticatorActivity;
|
||||
import com.owncloud.android.authentication.PinCheck;
|
||||
import com.owncloud.android.authentication.PassCodeManager;
|
||||
import com.owncloud.android.datamodel.FileDataStorageManager;
|
||||
import com.owncloud.android.datamodel.OCFile;
|
||||
import com.owncloud.android.db.DbHandler;
|
||||
|
@ -394,13 +394,6 @@ public class Preferences extends SherlockPreferenceActivity
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
|
||||
PinCheck.setUnlockTimestamp();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
|
||||
|
||||
|
|
|
@ -64,8 +64,6 @@ import com.actionbarsherlock.view.MenuItem;
|
|||
import com.owncloud.android.MainApp;
|
||||
import com.owncloud.android.R;
|
||||
import com.owncloud.android.authentication.AccountAuthenticator;
|
||||
import com.owncloud.android.authentication.PinCheck;
|
||||
import com.owncloud.android.datamodel.FileDataStorageManager;
|
||||
import com.owncloud.android.datamodel.OCFile;
|
||||
import com.owncloud.android.files.services.FileUploader;
|
||||
import com.owncloud.android.lib.common.operations.RemoteOperation;
|
||||
|
|
|
@ -38,10 +38,9 @@ import com.actionbarsherlock.app.ActionBar;
|
|||
import com.actionbarsherlock.view.MenuItem;
|
||||
import com.actionbarsherlock.view.Window;
|
||||
import com.ortiz.touch.ExtendedViewPager;
|
||||
import com.owncloud.android.MainApp;
|
||||
import com.owncloud.android.R;
|
||||
import com.owncloud.android.authentication.AccountUtils;
|
||||
import com.owncloud.android.authentication.PinCheck;
|
||||
import com.owncloud.android.authentication.PassCodeManager;
|
||||
import com.owncloud.android.datamodel.FileDataStorageManager;
|
||||
import com.owncloud.android.datamodel.OCFile;
|
||||
import com.owncloud.android.files.services.FileDownloader;
|
||||
|
@ -58,7 +57,6 @@ import com.owncloud.android.operations.RemoveFileOperation;
|
|||
import com.owncloud.android.operations.UnshareLinkOperation;
|
||||
import com.owncloud.android.ui.activity.FileActivity;
|
||||
import com.owncloud.android.ui.activity.FileDisplayActivity;
|
||||
import com.owncloud.android.ui.activity.PinCodeActivity;
|
||||
import com.owncloud.android.ui.fragment.FileFragment;
|
||||
import com.owncloud.android.utils.DisplayUtils;
|
||||
|
||||
|
@ -340,7 +338,6 @@ ViewPager.OnPageChangeListener, OnRemoteOperationListener {
|
|||
mDownloadFinishReceiver = null;
|
||||
}
|
||||
|
||||
PinCheck.setUnlockTimestamp();
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue