<commit_before>package com.lukekorth.pebblelocker;

import java.util.ArrayList;
import java.util.Set;

import android.app.KeyguardManager;
import android.app.admin.DevicePolicyManager;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.net.Uri;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.PowerManager;
import android.preference.PreferenceManager;
import android.support.v4.content.LocalBroadcastManager;
import android.util.Log;

import com.lukekorth.pebblelocker.PebbleLocker.CustomDeviceAdminReceiver;

public class Locker {

	private Context mContext;
	private SharedPreferences mPrefs;
	private Logger mLogger;
	private DevicePolicyManager mDPM;

	public Locker(Context context, String tag) {
		mContext = context;
		mPrefs = PreferenceManager.getDefaultSharedPreferences(context);
		mLogger = new Logger(context, tag);
		mDPM = ((DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE));
	}

	public void handleLocking() {
		handleLocking(true);
	}

	public void handleLocking(boolean forceLock) {
        boolean connectedToDeviceOrWifi = connectedToDeviceOrWifi();
		if (connectedToDeviceOrWifi && isLocked(true))
			unlock();
		else if (!connectedToDeviceOrWifi && isLocked(false))
			lock(forceLock);
        else
            sendBroadcast();
	}

	public void lock() {
		lock(true);
	}

	public void lock(boolean forceLock) {
		if (!enabled())
			return;

		boolean passwordChanged = mDPM.resetPassword(mPrefs.getString("key_password", ""), DevicePolicyManager.RESET_PASSWORD_REQUIRE_ENTRY);
		mPrefs.edit().putBoolean(ConnectionReceiver.LOCKED, true).putBoolean(ConnectionReceiver.UNLOCK, false).commit();

		mLogger.log("Successfully locked: " + passwordChanged);

		if (forceLock && mPrefs.getBoolean("key_force_lock", false))
			mDPM.lockNow();

        sendBroadcast();
	}

	public void unlock() {
		if (!enabled())
			return;

		if (isDeviceOnLockscreen()) {
			mPrefs.edit().putBoolean(ConnectionReceiver.UNLOCK, true).commit();
			mLogger.log("Screen is on lockscreen, setting unlock true for future unlock");
		} else {
			boolean passwordChanged = false;

			try {
				passwordChanged = mDPM.resetPassword("", DevicePolicyManager.RESET_PASSWORD_REQUIRE_ENTRY);

				mPrefs.edit().putBoolean(ConnectionReceiver.LOCKED, false).commit();
			} catch (IllegalArgumentException e) {
                boolean passwordReset = mDPM.resetPassword(mPrefs.getString("key_password", ""), DevicePolicyManager.RESET_PASSWORD_REQUIRE_ENTRY);

                mPrefs.edit().putBoolean(ConnectionReceiver.LOCKED, true).commit();

                mLogger.log("There was an exception when setting the password to blank, setting it back. Successfully reset: " + passwordReset + " " + Log.getStackTraceString(e));
            }

			mPrefs.edit().putBoolean(ConnectionReceiver.UNLOCK, false).commit();

			mLogger.log("Sucessfully unlocked: " + passwordChanged);
		}

        sendBroadcast();
	}

	public boolean enabled() {
		boolean activeAdmin = mDPM.isAdminActive(new ComponentName(mContext, CustomDeviceAdminReceiver.class));
		boolean enabled = mPrefs.getBoolean("key_enable_locker", false);
        boolean password = mPrefs.getString("key_password", "").equals("");

		if (!activeAdmin)
			mLogger.log("Not an active admin");
		if (!enabled)
			mLogger.log("key_enable_locker is false");
        if (!password)
            mLogger.log("User's password is empty");

		return activeAdmin && enabled && password;
	}
<commit_msg>Fix incorrect boolean logic<commit_after>package com.lukekorth.pebblelocker;

import java.util.ArrayList;
import java.util.Set;

import android.app.KeyguardManager;
import android.app.admin.DevicePolicyManager;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.net.Uri;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.PowerManager;
import android.preference.PreferenceManager;
import android.support.v4.content.LocalBroadcastManager;
import android.util.Log;

import com.lukekorth.pebblelocker.PebbleLocker.CustomDeviceAdminReceiver;

public class Locker {

	private Context mContext;
	private SharedPreferences mPrefs;
	private Logger mLogger;
	private DevicePolicyManager mDPM;

	public Locker(Context context, String tag) {
		mContext = context;
		mPrefs = PreferenceManager.getDefaultSharedPreferences(context);
		mLogger = new Logger(context, tag);
		mDPM = ((DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE));
	}

	public void handleLocking() {
		handleLocking(true);
	}

	public void handleLocking(boolean forceLock) {
        boolean connectedToDeviceOrWifi = connectedToDeviceOrWifi();
		if (connectedToDeviceOrWifi && isLocked(true))
			unlock();
		else if (!connectedToDeviceOrWifi && isLocked(false))
			lock(forceLock);
        else
            sendBroadcast();
	}

	public void lock() {
		lock(true);
	}

	public void lock(boolean forceLock) {
		if (!enabled())
			return;

		boolean passwordChanged = mDPM.resetPassword(mPrefs.getString("key_password", ""), DevicePolicyManager.RESET_PASSWORD_REQUIRE_ENTRY);
		mPrefs.edit().putBoolean(ConnectionReceiver.LOCKED, true).putBoolean(ConnectionReceiver.UNLOCK, false).commit();

		mLogger.log("Successfully locked: " + passwordChanged);

		if (forceLock && mPrefs.getBoolean("key_force_lock", false))
			mDPM.lockNow();

        sendBroadcast();
	}

	public void unlock() {
		if (!enabled())
			return;

		if (isDeviceOnLockscreen()) {
			mPrefs.edit().putBoolean(ConnectionReceiver.UNLOCK, true).commit();
			mLogger.log("Screen is on lockscreen, setting unlock true for future unlock");
		} else {
			boolean passwordChanged = false;

			try {
				passwordChanged = mDPM.resetPassword("", DevicePolicyManager.RESET_PASSWORD_REQUIRE_ENTRY);

				mPrefs.edit().putBoolean(ConnectionReceiver.LOCKED, false).commit();
			} catch (IllegalArgumentException e) {
                boolean passwordReset = mDPM.resetPassword(mPrefs.getString("key_password", ""), DevicePolicyManager.RESET_PASSWORD_REQUIRE_ENTRY);

                mPrefs.edit().putBoolean(ConnectionReceiver.LOCKED, true).commit();

                mLogger.log("There was an exception when setting the password to blank, setting it back. Successfully reset: " + passwordReset + " " + Log.getStackTraceString(e));
            }

			mPrefs.edit().putBoolean(ConnectionReceiver.UNLOCK, false).commit();

			mLogger.log("Sucessfully unlocked: " + passwordChanged);
		}

        sendBroadcast();
	}

	public boolean enabled() {
		boolean activeAdmin = mDPM.isAdminActive(new ComponentName(mContext, CustomDeviceAdminReceiver.class));
		boolean enabled = mPrefs.getBoolean("key_enable_locker", false);
        boolean password = !(mPrefs.getString("key_password", "").equals(""));

		if (!activeAdmin)
			mLogger.log("Not an active admin");
		if (!enabled)
			mLogger.log("key_enable_locker is false");
        if (!password)
            mLogger.log("User's password is empty");

		return activeAdmin && enabled && password;
	}

{'fraction_non_alphanumeric': 0.11173708920187793, 'fraction_numerical': 0.0002682763246143528, 'mean_word_length': 4.834115805946792, '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': '683971', 'n_tokens_mistral': 2312, 'n_tokens_neox': 2159, 'n_words': 441}