#365 Password protection

This commit is contained in:
stefan-niedermann 2020-01-25 13:05:51 +01:00
parent 8bca3aa3b4
commit a1be4f7284

View file

@ -3,6 +3,7 @@ package it.niedermann.owncloud.notes.android.activity;
import android.app.KeyguardManager;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import androidx.annotation.Nullable;
@ -18,23 +19,32 @@ public abstract class LockedActivity extends AppCompatActivity {
private static final int REQUEST_CODE_UNLOCK = 100;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Thread.currentThread().setUncaughtExceptionHandler(new ExceptionHandler(this));
if(isTaskRoot()) {
askToUnlock();
}
}
@Override
protected void onResume() {
super.onResume();
Thread.currentThread().setUncaughtExceptionHandler(new ExceptionHandler(this));
if (!isTaskRoot()) {
askToUnlock();
}
}
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
if (Notes.isLocked()) {
KeyguardManager keyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
if (keyguardManager != null) {
Intent i = keyguardManager.createConfirmDeviceCredentialIntent(getString(R.string.unlock_notes), null);
i.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
startActivityForResult(i, REQUEST_CODE_UNLOCK);
} else {
Log.e(TAG, "Keyguard manager is null");
}
}
@Override
protected void onStop() {
super.onStop();
if (isTaskRoot()) {
Notes.lock();
}
}
@ -54,4 +64,19 @@ public abstract class LockedActivity extends AppCompatActivity {
}
}
}
private void askToUnlock() {
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
if (Notes.isLocked()) {
KeyguardManager keyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
if (keyguardManager != null) {
Intent i = keyguardManager.createConfirmDeviceCredentialIntent(getString(R.string.unlock_notes), null);
i.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
startActivityForResult(i, REQUEST_CODE_UNLOCK);
} else {
Log.e(TAG, "Keyguard manager is null");
}
}
}
}
}