title: How to receive a log of recent screen unlocks?
body: <p>I’m writing an app where I’d like to request the user put in their passcode (KeyguardManager.createConfirmDeviceCredentialIntent), but only if the device has been unlocked for more than X amount of time. </p>
  
  <p>In iOS, this is called LATouchIDAuthenticationMaximumAllowableReuseDuration.</p>
  
  <p>I thought of three ways to accomplish this on Android, but have hit a wall with each one. Anyone have any better ideas?</p>
  
  <p>Idea #1: Runtime.getRuntime().exec(“dumpsys activity broadcasts history”);
  Issue: Requires android.permission.DUMP which is only available to system level applications</p>
  
  <p>Idea #2: Runtime.getRuntime().exec(“logcat -d |grep USER_PRESENT”);
  Issue: As of Android 4.1, logs originating from sources other than your app are filtered out. </p>
  
  <p>Idea #3: Set up a broadcast receiver for USER_PRESENT and log all screen unlocks. 
  Issue: As of API 26, this is ignored if registered in the manifest and needs to be registered at runtime which is unreliable.</p>
  
  <p>Sooo.. any other ideas?</p>
  
  <p>Thanks!</p>