<commit_before>package net.ghosttrails.www.mydetic;

import android.app.Activity;
import android.os.SystemClock;

/**
 * A Base class for activities that lock themselves with the security PIN fragment when resumed.
 */
public abstract class LockableActivity extends Activity
        implements SecurityPinFragment.OnFragmentInteractionListener {

    // If we move from one LockableActivity to another in less than this amount, then
    // the screen isn't locked.
    public static long PIN_LOCK_DELAY_MS = 1000;

    private SecurityPinFragment pinFragment;

    @Override
    protected void onResume() {
        super.onResume();

        MemoryAppState appState = MemoryAppState.getInstance();

        boolean resumedQuickly = (SystemClock.elapsedRealtime()
                - getTimePaused()) < PIN_LOCK_DELAY_MS;
        if (appState.getConfig().isUsingSecurityPin()
                && (!resumedQuickly || isPinLockDisplayed())) {
            // Add the PIN fragment
            if (pinFragment == null) {
                pinFragment = new SecurityPinFragment();
            }
            getFragmentManager().beginTransaction()
                    .replace(R.id.pin_fragment_container, pinFragment).commit();
            setPinLockDisplayed(true);
        }
    }

    @Override
    protected void onPause() {
        super.onPause();
        setTimePaused();
    }

    @Override
    public void onDismissed() {
        if (pinFragment != null) {
            getFragmentManager().beginTransaction().remove(pinFragment).commit();
        }
        setPinLockDisplayed(false);
        pinFragment = null;
    }

    public void setPinLockDisplayed(boolean isDisplayed) {
        getSharedPreferences("MyDeticTransition", 0).edit()
                .putBoolean("IS_PIN_LOCK_DISPLAYED", isDisplayed).apply();
    }

    public boolean isPinLockDisplayed() {
        return getSharedPreferences("MyDeticTransition", 0).getBoolean("IS_PIN_LOCK_DISPLAYED",
                false);
    }

    /**
     * Save a timestamp when a LockableActivity is paused. The pin pad won't be displayed if the
     * next LockableActivity created is within PIN_LOCK_DELAY_MS.
     */
    public void setTimePaused() {
        getSharedPreferences("MyDeticTransition", 0).edit()
                .putLong("PAUSE_TIME_MS", SystemClock.elapsedRealtime()).apply();
    }

    public long getTimePaused() {
        return getSharedPreferences("MyDeticTransition", 0).getLong("PAUSE_TIME_MS", 1L);
    }

}
<commit_msg>Fix app unlocked on reboot.<commit_after>package net.ghosttrails.www.mydetic;

import android.app.Activity;
import android.os.SystemClock;

/**
 * A Base class for activities that lock themselves with the security PIN fragment when resumed.
 */
public abstract class LockableActivity extends Activity
        implements SecurityPinFragment.OnFragmentInteractionListener {

    // If we move from one LockableActivity to another in less than this amount, then
    // the screen isn't locked.
    public static long PIN_LOCK_DELAY_MS = 1000;

    private SecurityPinFragment pinFragment;

    @Override
    protected void onResume() {
        super.onResume();

        MemoryAppState appState = MemoryAppState.getInstance();

        long delayMillis = SystemClock.elapsedRealtime() - getTimePaused();
        // If the delay is negative, this may indicate a device reboot since the app was last
        // paused.
        boolean resumedQuickly = delayMillis > 0L && delayMillis < PIN_LOCK_DELAY_MS;
        if (appState.getConfig().isUsingSecurityPin()
                && (!resumedQuickly || isPinLockDisplayed())) {
            // Add the PIN fragment
            if (pinFragment == null) {
                pinFragment = new SecurityPinFragment();
            }
            getFragmentManager().beginTransaction()
                    .replace(R.id.pin_fragment_container, pinFragment).commit();
            setPinLockDisplayed(true);
        }
    }

    @Override
    protected void onPause() {
        super.onPause();
        setTimePaused();
    }

    @Override
    public void onDismissed() {
        if (pinFragment != null) {
            getFragmentManager().beginTransaction().remove(pinFragment).commit();
        }
        setPinLockDisplayed(false);
        pinFragment = null;
    }

    public void setPinLockDisplayed(boolean isDisplayed) {
        getSharedPreferences("MyDeticTransition", 0).edit()
                .putBoolean("IS_PIN_LOCK_DISPLAYED", isDisplayed).apply();
    }

    public boolean isPinLockDisplayed() {
        return getSharedPreferences("MyDeticTransition", 0).getBoolean("IS_PIN_LOCK_DISPLAYED",
                false);
    }

    /**
     * Save a timestamp when a LockableActivity is paused. The pin pad won't be displayed if the
     * next LockableActivity created is within PIN_LOCK_DELAY_MS.
     */
    public void setTimePaused() {
        getSharedPreferences("MyDeticTransition", 0).edit()
                .putLong("PAUSE_TIME_MS", SystemClock.elapsedRealtime()).apply();
    }

    public long getTimePaused() {
        return getSharedPreferences("MyDeticTransition", 0).getLong("PAUSE_TIME_MS", 1L);
    }

}

{'fraction_non_alphanumeric': 0.0934289591006009, 'fraction_numerical': 0.0036828842798992054, 'mean_word_length': 2.680456490727532, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6724129', 'n_tokens_mistral': 1428, 'n_tokens_neox': 1349, 'n_words': 334}