<commit_before>package com.lukekorth.pebblelocker.receivers;

import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Build;
import android.preference.PreferenceManager;

import com.lukekorth.pebblelocker.LockState;
import com.lukekorth.pebblelocker.Locker;
import com.lukekorth.pebblelocker.PebbleLockerApplication;
import com.lukekorth.pebblelocker.helpers.DeviceHelper;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public abstract class BaseBroadcastReceiver extends BroadcastReceiver {

    public static final String LOCKED = "locked";
    protected static final int DELAYED_LOCK_REQUEST_CODE = 3439393;

    protected Context mContext;
    protected String mTag;
    protected Logger mLogger;
    protected DeviceHelper mDeviceHelper;
    protected String mAction;
    protected Intent mIntent;

    @Override
    public void onReceive(Context context, Intent intent) {
        mContext = context;
        mTag = PebbleLockerApplication.getUniqueTag();
        mLogger = LoggerFactory.getLogger(mTag);
        mDeviceHelper = new DeviceHelper(context, mTag);
        mAction = intent.getAction().toLowerCase();
        mIntent = intent;

        mLogger.debug("BroadcastReceiver action: " + mAction);

        checkForMalformedPassword();

        onReceive();

        LockState lockState = LockState.getCurrentState(mContext);
        if (lockState == LockState.AUTO) {
            handle();
        } else {
            mLogger.debug("Lock state was manually set to " + lockState.getDisplayName());
        }
        mDeviceHelper.sendLockStatusChangedEvent();
    }

    protected void handleLocking() {
        BaseBroadcastReceiver.handleLocking(mContext, mTag);
    }

    protected static void handleLocking(Context context, String tag) {
        new Locker(context, tag).handleLocking(true);
    }

    protected void lockWithDelay() {
        BaseBroadcastReceiver.lockWithDelay(mContext, mTag);
    }

    protected static void lockWithDelay(Context context, String tag) {
        Logger logger = LoggerFactory.getLogger(tag);
        int delay = Integer.parseInt(PreferenceManager.getDefaultSharedPreferences(context)
                .getString("key_grace_period", "2"));

        if (delay == 0) {
            logger.debug("No delay, handling locking now");
            BaseBroadcastReceiver.handleLocking(context, tag);
        } else {
            logger.debug("Delay of " + delay + "seconds, setting alarm");
            setDelayedLockAlarm(context, (delay * 1000));
        }
    }

    protected static void setDelayedLockAlarm(Context context, int delay) {<commit_msg>Add space to log<commit_after>package com.lukekorth.pebblelocker.receivers;

import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Build;
import android.preference.PreferenceManager;

import com.lukekorth.pebblelocker.LockState;
import com.lukekorth.pebblelocker.Locker;
import com.lukekorth.pebblelocker.PebbleLockerApplication;
import com.lukekorth.pebblelocker.helpers.DeviceHelper;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public abstract class BaseBroadcastReceiver extends BroadcastReceiver {

    public static final String LOCKED = "locked";
    protected static final int DELAYED_LOCK_REQUEST_CODE = 3439393;

    protected Context mContext;
    protected String mTag;
    protected Logger mLogger;
    protected DeviceHelper mDeviceHelper;
    protected String mAction;
    protected Intent mIntent;

    @Override
    public void onReceive(Context context, Intent intent) {
        mContext = context;
        mTag = PebbleLockerApplication.getUniqueTag();
        mLogger = LoggerFactory.getLogger(mTag);
        mDeviceHelper = new DeviceHelper(context, mTag);
        mAction = intent.getAction().toLowerCase();
        mIntent = intent;

        mLogger.debug("BroadcastReceiver action: " + mAction);

        checkForMalformedPassword();

        onReceive();

        LockState lockState = LockState.getCurrentState(mContext);
        if (lockState == LockState.AUTO) {
            handle();
        } else {
            mLogger.debug("Lock state was manually set to " + lockState.getDisplayName());
        }
        mDeviceHelper.sendLockStatusChangedEvent();
    }

    protected void handleLocking() {
        BaseBroadcastReceiver.handleLocking(mContext, mTag);
    }

    protected static void handleLocking(Context context, String tag) {
        new Locker(context, tag).handleLocking(true);
    }

    protected void lockWithDelay() {
        BaseBroadcastReceiver.lockWithDelay(mContext, mTag);
    }

    protected static void lockWithDelay(Context context, String tag) {
        Logger logger = LoggerFactory.getLogger(tag);
        int delay = Integer.parseInt(PreferenceManager.getDefaultSharedPreferences(context)
                .getString("key_grace_period", "2"));

        if (delay == 0) {
            logger.debug("No delay, handling locking now");
            BaseBroadcastReceiver.handleLocking(context, tag);
        } else {
            logger.debug("Delay of " + delay + " seconds, setting alarm");
            setDelayedLockAlarm(context, (delay * 1000));
        }
    }

    protected static void setDelayedLockAlarm(Context context, int delay) {
{'fraction_non_alphanumeric': 0.08725314183123878, 'fraction_numerical': 0.005385996409335727, 'mean_word_length': 3.424940428911835, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '7327493', 'n_tokens_mistral': 1556, 'n_tokens_neox': 1515, 'n_words': 343}