Android — Make app locking mechanism to protect app from illegal operations by third party when app come back to the foreground

M.I.
2 min readJan 31, 2021

Protect application with Biometric API and device credentials.

Motivation

In the development of apps that are categorized into finance and apps that handle personal informations and etc…

These apps are often required to have a feature that prevents illegal operation by a third party.

Therefore I created app lock screen that appears when app come back to the foreground using ActivityLifecycleCallbacks and ProcessLifecycleOwner.

Core libraries

  1. ProcessLifecycleOwner (detect process state. background/foreground)
  2. ActivityLifeclcleCallbacks
  3. Biometric (to use the biometric API and device credentials)
  4. Dagger (for dependency injection)

Behaviors

Dependencies

// lifecycle
def lifecycle_version = "2.2.0"
implementation "androidx.lifecycle:lifecycle-runtime-ktx:$lifecycle_version"
implementation "androidx.lifecycle:lifecycle-process:$lifecycle_version"

// dagger
implementation "com.google.dagger:dagger:2.29.1"
implementation "com.google.dagger:dagger-android-support:2.29.1"
kapt "com.google.dagger:dagger-compiler:2.29.1"
kapt "com.google.dagger:dagger-android-processor:2.29.1"

// biometric prompt
implementation "androidx.biometric:biometric:1.1.0"

Core class implementation

AppLockManager

AppSettings

Setup AppLockManager in Application class

Sample repository

--

--