- show device credentials only when set up

- allow press back/cancel during device credentials

Signed-off-by: tobiaskaminsky <tobias@kaminsky.me>
This commit is contained in:
tobiaskaminsky 2018-03-20 12:02:47 +01:00 committed by AndyScherzinger
parent 2b67067bc9
commit cadf4c0ba5
No known key found for this signature in database
GPG key ID: 6CADC7E3523C308B
4 changed files with 37 additions and 19 deletions

View file

@ -41,6 +41,8 @@ public class PassCodeManager {
private static final Set<Class> exemptOfPasscodeActivities;
public static final int PASSCODE_ACTIVITY = 9999;
static {
exemptOfPasscodeActivities = new HashSet<Class>();
exemptOfPasscodeActivities.add(PassCodeActivity.class);
@ -66,7 +68,7 @@ public class PassCodeManager {
protected PassCodeManager() {}
public void onActivityCreated(Activity activity) {
if (passCodeIsEnabled() || deviceCredentialsAreEnabled()) {
if (passCodeIsEnabled() || deviceCredentialsAreEnabled(activity)) {
activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE);
} else {
activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_SECURE);
@ -79,16 +81,16 @@ public class PassCodeManager {
Intent i = new Intent(MainApp.getAppContext(), PassCodeActivity.class);
i.setAction(PassCodeActivity.ACTION_CHECK);
i.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
activity.startActivity(i);
activity.startActivityForResult(i, PASSCODE_ACTIVITY);
}
if (!sExemptOfPasscodeActivites.contains(activity.getClass()) && Build.VERSION.SDK_INT >=
Build.VERSION_CODES.M && deviceCredentialsShouldBeRequested() &&
Build.VERSION_CODES.M && deviceCredentialsShouldBeRequested(activity) &&
!DeviceCredentialUtils.tryEncrypt(activity)) {
Intent i = new Intent(MainApp.getAppContext(), RequestCredentialsActivity.class);
i.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
activity.startActivity(i);
activity.startActivityForResult(i, PASSCODE_ACTIVITY);
}
visibleActivitiesCounter++; // keep it AFTER passCodeShouldBeRequested was checked
@ -100,7 +102,7 @@ public class PassCodeManager {
}
setUnlockTimestamp();
PowerManager powerMgr = (PowerManager) activity.getSystemService(Context.POWER_SERVICE);
if ((passCodeIsEnabled() || deviceCredentialsAreEnabled())&& powerMgr != null && !powerMgr.isScreenOn()) {
if ((passCodeIsEnabled() || deviceCredentialsAreEnabled(activity)) && powerMgr != null && !powerMgr.isScreenOn()) {
activity.moveTaskToBack(true);
}
}
@ -120,9 +122,9 @@ public class PassCodeManager {
.equals(Preferences.LOCK_PASSCODE));
}
private boolean deviceCredentialsShouldBeRequested() {
private boolean deviceCredentialsShouldBeRequested(Activity activity) {
if ((System.currentTimeMillis() - mTimestamp) > PASS_CODE_TIMEOUT && visibleActivitiesCounter <= 0) {
return deviceCredentialsAreEnabled();
return deviceCredentialsAreEnabled(activity);
}
return false;
}
@ -137,10 +139,8 @@ public class PassCodeManager {
appPrefs.getBoolean(Preferences.PREFERENCE_USE_FINGERPRINT, false);
}
private boolean deviceCredentialsAreEnabled() {
SharedPreferences appPrefs = PreferenceManager
.getDefaultSharedPreferences(MainApp.getAppContext());
return (appPrefs.getString(Preferences.PREFERENCE_LOCK, "")
.equals(Preferences.LOCK_DEVICE_CREDENTIALS));
private boolean deviceCredentialsAreEnabled(Activity activity) {
SharedPreferences appPrefs = PreferenceManager.getDefaultSharedPreferences(activity);
return appPrefs.getString(Preferences.PREFERENCE_LOCK, "").equals(Preferences.LOCK_DEVICE_CREDENTIALS);
}
}

View file

@ -34,6 +34,7 @@ import android.graphics.PorterDuff;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.support.design.widget.NavigationView;
@ -59,6 +60,7 @@ import com.bumptech.glide.request.target.SimpleTarget;
import com.owncloud.android.MainApp;
import com.owncloud.android.R;
import com.owncloud.android.authentication.AccountUtils;
import com.owncloud.android.authentication.PassCodeManager;
import com.owncloud.android.datamodel.ArbitraryDataProvider;
import com.owncloud.android.datamodel.ExternalLinksProvider;
import com.owncloud.android.datamodel.OCFile;
@ -1228,6 +1230,15 @@ public abstract class DrawerActivity extends ToolbarActivity implements DisplayU
} else {
updateAccountList();
}
} else if (requestCode == PassCodeManager.PASSCODE_ACTIVITY &&
Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && data != null) {
int result = data.getIntExtra(RequestCredentialsActivity.KEY_CHECK_RESULT,
RequestCredentialsActivity.KEY_CHECK_RESULT_FALSE);
if (result == RequestCredentialsActivity.KEY_CHECK_RESULT_CANCEL) {
Log_OC.d(TAG, "PassCodeManager cancelled");
super.onBackPressed();
}
}
}

View file

@ -596,8 +596,8 @@ public class Preferences extends PreferenceActivity
if (!passCodeEnabled) {
lockEntries.remove(1);
lockValues.remove(1);
} else if (!deviceCredentialsEnabled || Build.VERSION.SDK_INT <
Build.VERSION_CODES.M) {
} else if (!deviceCredentialsEnabled || Build.VERSION.SDK_INT < Build.VERSION_CODES.M ||
!DeviceCredentialUtils.areCredentialsAvailable(getApplicationContext())) {
lockEntries.remove(2);
lockValues.remove(2);
}
@ -881,7 +881,9 @@ public class Preferences extends PreferenceActivity
DisplayUtils.showSnackMessage(this, R.string.prefs_calendar_contacts_sync_setup_successful);
} else if (requestCode == ACTION_CONFIRM_DEVICE_CREDENTIALS && resultCode == RESULT_OK &&
Build.VERSION.SDK_INT >= Build.VERSION_CODES.M &&
data.getBooleanExtra(RequestCredentialsActivity.KEY_CHECK_RESULT, false)) {
data.getIntExtra(RequestCredentialsActivity.KEY_CHECK_RESULT,
RequestCredentialsActivity.KEY_CHECK_RESULT_FALSE) ==
RequestCredentialsActivity.KEY_CHECK_RESULT_TRUE) {
mLock.setValue(LOCK_NONE);
mLock.setSummary(mLock.getEntry());
DisplayUtils.showSnackMessage(this, R.string.credentials_disabled);

View file

@ -44,6 +44,9 @@ public class RequestCredentialsActivity extends Activity {
private static final String SCREEN_NAME = "Device credentials";
public final static String KEY_CHECK_RESULT = "KEY_CHECK_RESULT";
public final static int KEY_CHECK_RESULT_TRUE = 1;
public final static int KEY_CHECK_RESULT_FALSE = 0;
public final static int KEY_CHECK_RESULT_CANCEL = -1;
private static final int REQUEST_CODE_CONFIRM_DEVICE_CREDENTIALS = 1;
@Override
@ -51,7 +54,9 @@ public class RequestCredentialsActivity extends Activity {
if (requestCode == REQUEST_CODE_CONFIRM_DEVICE_CREDENTIALS) {
if (resultCode == Activity.RESULT_OK && DeviceCredentialUtils
.tryEncrypt(getApplicationContext())) {
finishWithResult(true);
finishWithResult(KEY_CHECK_RESULT_TRUE);
} else if (resultCode == Activity.RESULT_CANCELED) {
finishWithResult(KEY_CHECK_RESULT_CANCEL);
} else {
Toast.makeText(this, R.string.default_credentials_wrong, Toast.LENGTH_SHORT).show();
requestCredentials();
@ -69,7 +74,7 @@ public class RequestCredentialsActivity extends Activity {
requestCredentials();
} else {
DisplayUtils.showSnackMessage(this, R.string.prefs_lock_device_credentials_not_setup);
finishWithResult(true);
finishWithResult(KEY_CHECK_RESULT_TRUE);
}
}
@ -80,11 +85,11 @@ public class RequestCredentialsActivity extends Activity {
startActivityForResult(i, REQUEST_CODE_CONFIRM_DEVICE_CREDENTIALS);
} else {
Log_OC.e(TAG, "Keyguard manager is null");
finishWithResult(false);
finishWithResult(KEY_CHECK_RESULT_FALSE);
}
}
private void finishWithResult(boolean success) {
private void finishWithResult(int success) {
Intent resultIntent = new Intent();
resultIntent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
resultIntent.putExtra(KEY_CHECK_RESULT, success);