mirror of
https://github.com/nextcloud/android.git
synced 2024-11-28 02:06:56 +03:00
- moved check to PinCheck
- hardcoded 10s time-out
This commit is contained in:
parent
ed74bba5fb
commit
cb5f0971af
6 changed files with 90 additions and 66 deletions
|
@ -19,6 +19,7 @@ package com.owncloud.android;
|
|||
import android.app.Application;
|
||||
import android.content.Context;
|
||||
|
||||
import com.owncloud.android.authentication.PinCheck;
|
||||
import com.owncloud.android.datamodel.ThumbnailsCacheManager;
|
||||
import com.owncloud.android.lib.common.OwnCloudClientManagerFactory;
|
||||
import com.owncloud.android.lib.common.OwnCloudClientManagerFactory.Policy;
|
||||
|
@ -45,7 +46,7 @@ public class MainApp extends Application {
|
|||
|
||||
public void onCreate(){
|
||||
super.onCreate();
|
||||
MainApp.mContext = getApplicationContext();
|
||||
MainApp.mContext = getApplicationContext();
|
||||
|
||||
boolean isSamlAuth = AUTH_ON.equals(getString(R.string.auth_method_saml_web_sso));
|
||||
|
||||
|
@ -74,7 +75,7 @@ public class MainApp extends Application {
|
|||
public static Context getAppContext() {
|
||||
return MainApp.mContext;
|
||||
}
|
||||
|
||||
|
||||
// Methods to obtain Strings referring app_name
|
||||
// From AccountAuthenticator
|
||||
// public static final String ACCOUNT_TYPE = "owncloud";
|
||||
|
|
28
src/com/owncloud/android/authentication/PinCheck.java
Normal file
28
src/com/owncloud/android/authentication/PinCheck.java
Normal file
|
@ -0,0 +1,28 @@
|
|||
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;
|
||||
|
||||
public class PinCheck extends Activity {
|
||||
|
||||
private static Long timestamp = 0l;
|
||||
|
||||
public static void setUnlockTimestamp() {
|
||||
timestamp = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public static boolean checkIfPinEntry(){
|
||||
if ((System.currentTimeMillis() - timestamp) > 10000){
|
||||
SharedPreferences appPrefs = PreferenceManager.getDefaultSharedPreferences(MainApp.getAppContext());
|
||||
if (appPrefs.getBoolean("set_pincode", false)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -71,6 +71,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.datamodel.OCFile;
|
||||
import com.owncloud.android.files.services.FileDownloader;
|
||||
import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder;
|
||||
|
@ -160,6 +161,8 @@ OnSslUntrustedCertListener, OnEnforceableRefreshListener {
|
|||
private String DIALOG_UNTRUSTED_CERT;
|
||||
|
||||
private OCFile mWaitingToSend;
|
||||
|
||||
private Boolean mUnlocked = false;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
|
@ -168,9 +171,20 @@ OnSslUntrustedCertListener, OnEnforceableRefreshListener {
|
|||
|
||||
super.onCreate(savedInstanceState); // this calls onAccountChanged() when ownCloud Account is valid
|
||||
|
||||
checkIfRequestPin(savedInstanceState);
|
||||
|
||||
/// grant that FileObserverService is watching favourite files
|
||||
|
||||
if (PinCheck.checkIfPinEntry()){
|
||||
Intent i = new Intent(MainApp.getAppContext(), PinCodeActivity.class);
|
||||
i.putExtra(PinCodeActivity.EXTRA_ACTIVITY, "FileDisplayActivity");
|
||||
startActivity(i);
|
||||
}
|
||||
|
||||
// if (mUnlocked == false){
|
||||
// checkIfRequestPin(savedInstanceState);
|
||||
// } else {
|
||||
// mUnlocked = false;
|
||||
// }
|
||||
|
||||
/// grant that FileObserverService is watching favorite files
|
||||
if (savedInstanceState == null) {
|
||||
Intent initObserversIntent = FileObserverService.makeInitIntent(this);
|
||||
startService(initObserversIntent);
|
||||
|
@ -209,15 +223,6 @@ OnSslUntrustedCertListener, OnEnforceableRefreshListener {
|
|||
Log_OC.d(TAG, "onCreate() end");
|
||||
}
|
||||
|
||||
private void checkIfRequestPin(Bundle savedInstanceState){
|
||||
// PIN CODE request ; best location is to decide, let's try this first
|
||||
if (getIntent().getAction() != null && getIntent().getAction().equals(Intent.ACTION_MAIN) && savedInstanceState == null) {
|
||||
requestPinCode();
|
||||
} else if (getIntent().getAction() == null && savedInstanceState == null) {
|
||||
requestPinCode();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart() {
|
||||
super.onStart();
|
||||
|
@ -617,14 +622,6 @@ OnSslUntrustedCertListener, OnEnforceableRefreshListener {
|
|||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
|
||||
Log_OC.d(TAG, "requestCode: " + requestCode);
|
||||
if (requestCode == PinCodeActivity.EXTRA_PIN_CORRECT){
|
||||
Log_OC.d(TAG, "Extra pin: " + resultCode);
|
||||
if (resultCode == RESULT_OK) {
|
||||
resume();
|
||||
}
|
||||
}
|
||||
|
||||
if (requestCode == ACTION_SELECT_CONTENT_FROM_APPS && (resultCode == RESULT_OK || resultCode == UploadFilesActivity.RESULT_OK_AND_MOVE)) {
|
||||
//getClipData is only supported on api level 16+, Jelly Bean
|
||||
if (data.getData() == null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN){
|
||||
|
@ -814,7 +811,11 @@ OnSslUntrustedCertListener, OnEnforceableRefreshListener {
|
|||
super.onResume();
|
||||
Log_OC.e(TAG, "onResume() start");
|
||||
|
||||
checkIfRequestPin(null);
|
||||
if (PinCheck.checkIfPinEntry()){
|
||||
Intent i = new Intent(MainApp.getAppContext(), PinCodeActivity.class);
|
||||
i.putExtra(PinCodeActivity.EXTRA_ACTIVITY, "FileDisplayActivity");
|
||||
startActivity(i);
|
||||
}
|
||||
}
|
||||
|
||||
private void resume(){
|
||||
|
@ -863,7 +864,7 @@ OnSslUntrustedCertListener, OnEnforceableRefreshListener {
|
|||
mDownloadFinishReceiver = null;
|
||||
}
|
||||
|
||||
|
||||
PinCheck.setUnlockTimestamp();
|
||||
Log_OC.d(TAG, "onPause() end");
|
||||
super.onPause();
|
||||
}
|
||||
|
@ -1455,23 +1456,6 @@ OnSslUntrustedCertListener, OnEnforceableRefreshListener {
|
|||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Launch an intent to request the PIN code to the user before letting him use the app
|
||||
*/
|
||||
private void requestPinCode() {
|
||||
boolean pinStart = false;
|
||||
SharedPreferences appPrefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
|
||||
pinStart = appPrefs.getBoolean("set_pincode", false);
|
||||
if (pinStart) {
|
||||
Intent i = new Intent(getApplicationContext(), PinCodeActivity.class);
|
||||
// i.putExtra(PinCodeActivity.EXTRA_ACTIVITY, "FileDisplayActivity");
|
||||
startActivityForResult(i, PinCodeActivity.EXTRA_PIN_CORRECT);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onSavedCertificate() {
|
||||
startSyncFolderOperation(getCurrentDir(), false);
|
||||
|
|
|
@ -20,7 +20,9 @@ import java.util.Arrays;
|
|||
|
||||
import com.actionbarsherlock.app.ActionBar;
|
||||
import com.actionbarsherlock.app.SherlockFragmentActivity;
|
||||
import com.owncloud.android.MainApp;
|
||||
import com.owncloud.android.R;
|
||||
import com.owncloud.android.authentication.PinCheck;
|
||||
import com.owncloud.android.utils.DisplayUtils;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
|
@ -46,7 +48,6 @@ public class PinCodeActivity extends SherlockFragmentActivity {
|
|||
|
||||
public final static String EXTRA_ACTIVITY = "com.owncloud.android.ui.activity.PinCodeActivity.ACTIVITY";
|
||||
public final static String EXTRA_NEW_STATE = "com.owncloud.android.ui.activity.PinCodeActivity.NEW_STATE";
|
||||
public final static Integer EXTRA_PIN_CORRECT = 1;
|
||||
|
||||
private Button mBCancel;
|
||||
private TextView mPinHdr;
|
||||
|
@ -367,8 +368,15 @@ public class PinCodeActivity extends SherlockFragmentActivity {
|
|||
mPinCodeChecked = checkPincode();
|
||||
}
|
||||
|
||||
if (mPinCodeChecked &&
|
||||
( mActivity.equals("FileDisplayActivity") || mActivity.equals("PreviewImageActivity") ) ){
|
||||
// if (mPinCodeChecked &&
|
||||
// ( mActivity.equals("FileDisplayActivity") || mActivity.equals("PreviewImageActivity") ) ){
|
||||
// Intent data = new Intent();
|
||||
// data.putExtra(EXTRA_PIN_CORRECT, true);
|
||||
// setResult(RESULT_FIRST_USER, data);
|
||||
// finish();
|
||||
|
||||
if (mPinCodeChecked){
|
||||
PinCheck.setUnlockTimestamp();
|
||||
finish();
|
||||
} else if (mPinCodeChecked){
|
||||
|
||||
|
|
|
@ -396,9 +396,7 @@ public class OCFileListFragment extends ExtendedListFragment {
|
|||
|
||||
// Update Footer
|
||||
TextView footerText = (TextView) mFooterView.findViewById(R.id.footerText);
|
||||
Log_OC.d("footer", String.valueOf(System.currentTimeMillis()));
|
||||
footerText.setText(generateFooterText(directory));
|
||||
Log_OC.d("footer", String.valueOf(System.currentTimeMillis()));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
package com.owncloud.android.ui.preview;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.annotation.TargetApi;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
|
@ -37,8 +38,10 @@ 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.datamodel.FileDataStorageManager;
|
||||
import com.owncloud.android.datamodel.OCFile;
|
||||
import com.owncloud.android.files.services.FileDownloader;
|
||||
|
@ -89,6 +92,8 @@ ViewPager.OnPageChangeListener, OnRemoteOperationListener {
|
|||
|
||||
private View mFullScreenAnchorView;
|
||||
|
||||
private Boolean mUnlocked = false;
|
||||
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
|
@ -103,8 +108,10 @@ ViewPager.OnPageChangeListener, OnRemoteOperationListener {
|
|||
actionBar.hide();
|
||||
|
||||
// PIN CODE request
|
||||
if (getIntent().getExtras() != null && savedInstanceState == null && fromNotification()) {
|
||||
requestPinCode();
|
||||
if (PinCheck.checkIfPinEntry()){
|
||||
Intent i = new Intent(MainApp.getAppContext(), PinCodeActivity.class);
|
||||
i.putExtra(PinCodeActivity.EXTRA_ACTIVITY, "FileDisplayActivity");
|
||||
startActivity(i);
|
||||
}
|
||||
|
||||
// Make sure we're running on Honeycomb or higher to use FullScreen and
|
||||
|
@ -322,6 +329,15 @@ ViewPager.OnPageChangeListener, OnRemoteOperationListener {
|
|||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
|
||||
if (PinCheck.checkIfPinEntry()){
|
||||
Intent i = new Intent(MainApp.getAppContext(), PinCodeActivity.class);
|
||||
i.putExtra(PinCodeActivity.EXTRA_ACTIVITY, "FileDisplayActivity");
|
||||
startActivity(i);
|
||||
}
|
||||
}
|
||||
|
||||
private void resume(){
|
||||
//Log_OC.e(TAG, "ACTIVITY, ONRESUME");
|
||||
mDownloadFinishReceiver = new DownloadFinishReceiver();
|
||||
|
||||
|
@ -338,8 +354,12 @@ ViewPager.OnPageChangeListener, OnRemoteOperationListener {
|
|||
|
||||
@Override
|
||||
public void onPause() {
|
||||
unregisterReceiver(mDownloadFinishReceiver);
|
||||
mDownloadFinishReceiver = null;
|
||||
if (mDownloadFinishReceiver != null){
|
||||
unregisterReceiver(mDownloadFinishReceiver);
|
||||
mDownloadFinishReceiver = null;
|
||||
}
|
||||
|
||||
PinCheck.setUnlockTimestamp();
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
|
@ -526,22 +546,7 @@ ViewPager.OnPageChangeListener, OnRemoteOperationListener {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Launch an intent to request the PIN code to the user before letting him use the app
|
||||
*/
|
||||
private void requestPinCode() {
|
||||
boolean pinStart = false;
|
||||
SharedPreferences appPrefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
|
||||
pinStart = appPrefs.getBoolean("set_pincode", false);
|
||||
if (pinStart) {
|
||||
Intent i = new Intent(getApplicationContext(), PinCodeActivity.class);
|
||||
i.putExtra(PinCodeActivity.EXTRA_ACTIVITY, "PreviewImageActivity");
|
||||
startActivity(i);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onBrowsedDownTo(OCFile folder) {
|
||||
// TODO Auto-generated method stub
|
||||
|
|
Loading…
Reference in a new issue