diff --git a/app/src/main/java/it/niedermann/owncloud/notes/android/activity/NotesListViewActivity.java b/app/src/main/java/it/niedermann/owncloud/notes/android/activity/NotesListViewActivity.java index a9d6806c..65658a02 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/android/activity/NotesListViewActivity.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/android/activity/NotesListViewActivity.java @@ -1,6 +1,8 @@ package it.niedermann.owncloud.notes.android.activity; +import android.app.KeyguardManager; import android.app.SearchManager; +import android.content.Context; import android.content.Intent; import android.content.res.Configuration; import android.database.sqlite.SQLiteConstraintException; @@ -187,6 +189,18 @@ public class NotesListViewActivity extends AppCompatActivity implements ItemAdap setupNavigationList(categoryAdapterSelectedItem); setupNavigationMenu(); setupNotesList(); + + if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) { + KeyguardManager keyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE); + if (keyguardManager != null) { + Intent i = keyguardManager.createConfirmDeviceCredentialIntent(null, null); + i.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); + startActivityForResult(i, 999); + } else { + Log.e(TAG, "Keyguard manager is null"); +// finishWithResult(-45); + } + } } @Override diff --git a/app/src/main/java/it/niedermann/owncloud/notes/util/DeviceCredentialUtil.java b/app/src/main/java/it/niedermann/owncloud/notes/util/DeviceCredentialUtil.java new file mode 100644 index 00000000..6d656fba --- /dev/null +++ b/app/src/main/java/it/niedermann/owncloud/notes/util/DeviceCredentialUtil.java @@ -0,0 +1,32 @@ +package it.niedermann.owncloud.notes.util; + +import android.app.KeyguardManager; +import android.content.Context; +import android.os.Build; +import android.util.Log; + +import androidx.annotation.RequiresApi; + +/** + * Utility class with methods for handling device credentials. + */ +@RequiresApi(Build.VERSION_CODES.M) +class DeviceCredentialUtils { + + private static final String TAG = DeviceCredentialUtils.class.getCanonicalName(); + + private DeviceCredentialUtils() { + // utility class -> private constructor + } + + public static boolean areCredentialsAvailable(Context context) { + KeyguardManager keyguardManager = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE); + + if (keyguardManager != null) { + return keyguardManager.isKeyguardSecure(); + } else { + Log.e(TAG, "Keyguard manager is null"); + return false; + } + } +}