Android Open Source - nfcunlocker Flag Unlock






From Project

Back to project page nfcunlocker.

License

The source code is released under:

Apache License

If you think the Android project nfcunlocker listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.steelrat.nfcunlocker.unlockmethods;
//w ww .  j a v  a2s.c o m
import android.app.Activity;
import android.app.admin.DevicePolicyManager;
import android.view.WindowManager;

/**
 * Screen unlock method that uses FLAG_DISMISS_KEYGUARD window flag to unlock the lock screen and 
 * DevicePolicyManager to clear/set password.
 * 
 * <h3>How does this works:</h3>
 * <ol>
 * <li>Clear the password and dismiss keyguard using FLAG_DISMISS_KEYGUARD window flag.
 * This flag will totally dismiss keyguard (it will not re-appear upon navigation) if lock screen is not secured
 * (we are clearing password for such purposes).
 * <li>Finish activity only in onAttachedToWindow event method because window flag will be applied right there.
 * <li>Set password back on activity destroy.
 * </ol>
 * 
 * @author SteelRat
 *
 */
public class FlagUnlock extends DevicePolicyUnlockMethod {
  DevicePolicyManager mDPM;

  public FlagUnlock(Activity activity) {
    super(activity);
  }
  
  public void unlock(String password) {
    super.unlock(password);
    clearPassword();
        getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
  }
  
  @Override
  public void onActivityEvent(String event) {
    super.onActivityEvent(event);

    // We can safely reset password in onDestroy method of activity because the screen should be already unlocked.
    if (event.equals("onDestroy")) {
      restorePassword();
    // Finish event just after FLAG_DISMISS_KEYGUARD was applied to window.
    } else if (event.equals("onAttachedToWindow")) {
      getActivity().finish();
    }
  }
}




Java Source Code List

com.steelrat.nfcunlocker.AddActivity.java
com.steelrat.nfcunlocker.DiscoveredActivity.java
com.steelrat.nfcunlocker.MainActivity.java
com.steelrat.nfcunlocker.NFCApplication.java
com.steelrat.nfcunlocker.helpers.AppDeviceAdminReceiver.java
com.steelrat.nfcunlocker.helpers.TagsStorage.java
com.steelrat.nfcunlocker.settingsactivity.SettingsActivityBase.java
com.steelrat.nfcunlocker.settingsactivity.SettingsActivityOA.java
com.steelrat.nfcunlocker.settingsactivity.SettingsActivity.java
com.steelrat.nfcunlocker.unlockmethods.DevicePolicyUnlockMethod.java
com.steelrat.nfcunlocker.unlockmethods.FlagUnlock.java
com.steelrat.nfcunlocker.unlockmethods.InputUnlock.java
com.steelrat.nfcunlocker.unlockmethods.KeyguardUnlock.java
com.steelrat.nfcunlocker.unlockmethods.UnlockMethodFactory.java
com.steelrat.nfcunlocker.unlockmethods.UnlockMethod.java