<commit_before>/*
 * Copyright (C) 2014 OMRON Corporation
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package omron.HVC;

import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothGatt;
import android.bluetooth.BluetoothGattCallback;
import android.bluetooth.BluetoothGattCharacteristic;
import android.bluetooth.BluetoothGattDescriptor;
import android.bluetooth.BluetoothGattService;
import android.bluetooth.BluetoothProfile;
import android.content.Context;
import android.util.Log;

import java.lang.reflect.Method;
import java.util.UUID;

import org.deviceconnect.android.deviceplugin.hvc.BuildConfig;

/**
 * Service for managing connection and data communication with a GATT server hosted on a
 * given Bluetooth LE device.
 */
public class BleDeviceService {
    
    /**
     * DebugLog.
     */
    static final boolean DEBUG_LOG = BuildConfig.DEBUG;
    
    /** status. */
    public static final int STATE_DISCONNECTED = 0;
    /** status. */
    public static final int STATE_CONNECTING = 1;
    /** status. */
    public static final int STATE_CONNECTED = 2;

    /** action. */
    public static final String ACTION_GATT_CONNECTED = "ACTION_GATT_CONNECTED";
    /** action. */
    public static final String ACTION_GATT_DISCONNECTED = "ACTION_GATT_DISCONNECTED";
    /** action. */
    public static final String ACTION_GATT_SERVICES_DISCOVERED = "ACTION_GATT_SERVICES_DISCOVERED";
    /** action. */
    public static final String ACTION_DATA_AVAILABLE = "ACTION_DATA_AVAILABLE";
    /** data. */
	public static final String NAME_DATA = ":NAME_DATA";
    /** data. */
    public static final String EXTRA_DATA = ":EXTRA_DATA";
    /** value. */
    public static final String DEVICE_DOES_NOT_SUPPORT_UART = "DEVICE_DOES_NOT_SUPPORT_UART";

    /** CCCD. */
    public static final UUID CCCD = UUID.fromString("00002902-0000-1000-8000-00805f9b34fb");

    /** UUID2. */
    public static final UUID RX_SERVICE_UUID2 = UUID.fromString("35100001-d13a-4f39-8ab3-bf64d4fbb4b4");
    /** UUID2. */
    public static final UUID RX_CHAR_UUID2 = UUID.fromString("35100002-d13a-4f39-8ab3-bf64d4fbb4b4");
    /** UUID2. */
    public static final UUID TX_CHAR_UUID2 = UUID.fromString("35100003-d13a-4f39-8ab3-bf64d4fbb4b4");

    /** UUID. */
    public static final UUID NAME_CHAR_UUID = UUID.fromString("35100004-d13a-4f39-8ab3-bf64d4fbb4b4");

    /** BleCallback. */
    private BleCallback mCallBack = null;

    /** BluetoothGatt. */
    private BluetoothGatt mBluetoothGatt;
    /** BluetoothDeviceAddress. */
    private String mBluetoothDeviceAddress;
    /** ConnectionState. */
    private int mConnectionState = STATE_DISCONNECTED;

    /** TAG. */
    private static final String TAG = "BleDeviceService";

    /**
     * Implements callback methods for GATT events that the app cares about.  For example,
     * connection change and services discovered.
     */
    private final BluetoothGattCallback mGattCallback = new BluetoothGattCallback() {
        @Override
        public void onConnectionStateChange(final BluetoothGatt gatt, final int status, final int newState) {
            String intentAction;

            if (newState == BluetoothProfile.STATE_CONNECTED) {
                intentAction = ACTION_GATT_CONNECTED;
                setmConnectionState(STATE_CONNECTED);
                broadcastUpdate(intentAction);
                if (DEBUG_LOG) {
                    Log.i(TAG, "Connected to GATT server.");
                }
                // Attempts to discover services after successful connection.
                if (DEBUG_LOG) {
                    Log.i(TAG, "Attempting to start service discovery:"
                        + mBluetoothGatt.discoverServices());
                }
            } else if (newState == BluetoothProfile.STATE_DISCONNECTED) {
                intentAction = ACTION_GATT_DISCONNECTED;
                setmConnectionState(STATE_DISCONNECTED);
                if (DEBUG_LOG) {<commit_msg>Bug fix: cannot detect if release build.<commit_after>/*
 * Copyright (C) 2014 OMRON Corporation
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package omron.HVC;

import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothGatt;
import android.bluetooth.BluetoothGattCallback;
import android.bluetooth.BluetoothGattCharacteristic;
import android.bluetooth.BluetoothGattDescriptor;
import android.bluetooth.BluetoothGattService;
import android.bluetooth.BluetoothProfile;
import android.content.Context;
import android.util.Log;

import java.lang.reflect.Method;
import java.util.UUID;

import org.deviceconnect.android.deviceplugin.hvc.BuildConfig;

/**
 * Service for managing connection and data communication with a GATT server hosted on a
 * given Bluetooth LE device.
 */
public class BleDeviceService {
    
    /**
     * DebugLog.
     */
    static final boolean DEBUG_LOG = BuildConfig.DEBUG;
    
    /** status. */
    public static final int STATE_DISCONNECTED = 0;
    /** status. */
    public static final int STATE_CONNECTING = 1;
    /** status. */
    public static final int STATE_CONNECTED = 2;

    /** action. */
    public static final String ACTION_GATT_CONNECTED = "ACTION_GATT_CONNECTED";
    /** action. */
    public static final String ACTION_GATT_DISCONNECTED = "ACTION_GATT_DISCONNECTED";
    /** action. */
    public static final String ACTION_GATT_SERVICES_DISCOVERED = "ACTION_GATT_SERVICES_DISCOVERED";
    /** action. */
    public static final String ACTION_DATA_AVAILABLE = "ACTION_DATA_AVAILABLE";
    /** data. */
	public static final String NAME_DATA = ":NAME_DATA";
    /** data. */
    public static final String EXTRA_DATA = ":EXTRA_DATA";
    /** value. */
    public static final String DEVICE_DOES_NOT_SUPPORT_UART = "DEVICE_DOES_NOT_SUPPORT_UART";

    /** CCCD. */
    public static final UUID CCCD = UUID.fromString("00002902-0000-1000-8000-00805f9b34fb");

    /** UUID2. */
    public static final UUID RX_SERVICE_UUID2 = UUID.fromString("35100001-d13a-4f39-8ab3-bf64d4fbb4b4");
    /** UUID2. */
    public static final UUID RX_CHAR_UUID2 = UUID.fromString("35100002-d13a-4f39-8ab3-bf64d4fbb4b4");
    /** UUID2. */
    public static final UUID TX_CHAR_UUID2 = UUID.fromString("35100003-d13a-4f39-8ab3-bf64d4fbb4b4");

    /** UUID. */
    public static final UUID NAME_CHAR_UUID = UUID.fromString("35100004-d13a-4f39-8ab3-bf64d4fbb4b4");

    /** BleCallback. */
    private BleCallback mCallBack = null;

    /** BluetoothGatt. */
    private BluetoothGatt mBluetoothGatt;
    /** BluetoothDeviceAddress. */
    private String mBluetoothDeviceAddress;
    /** ConnectionState. */
    private int mConnectionState = STATE_DISCONNECTED;

    /** TAG. */
    private static final String TAG = "BleDeviceService";

    /**
     * Implements callback methods for GATT events that the app cares about.  For example,
     * connection change and services discovered.
     */
    private final BluetoothGattCallback mGattCallback = new BluetoothGattCallback() {
        @Override
        public void onConnectionStateChange(final BluetoothGatt gatt, final int status, final int newState) {
            String intentAction;

            if (newState == BluetoothProfile.STATE_CONNECTED) {
                intentAction = ACTION_GATT_CONNECTED;
                setmConnectionState(STATE_CONNECTED);
                broadcastUpdate(intentAction);
                if (DEBUG_LOG) {
                    Log.i(TAG, "Connected to GATT server.");
                }
                // Attempts to discover services after successful connection.
                boolean result = mBluetoothGatt.discoverServices();
                if (DEBUG_LOG) {
                    Log.i(TAG, "Attempting to start service discovery:"
                        + result);
                }
            } else if (newState == BluetoothProfile.STATE_DISCONNECTED) {
                intentAction = ACTION_GATT_DISCONNECTED;
                setmConnectionState(STATE_DISCONNECTED);
                if (DEBUG_LOG) {
{'fraction_non_alphanumeric': 0.09076855123674912, 'fraction_numerical': 0.027606007067137808, 'mean_word_length': 2.958479020979021, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, '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': '3525103', 'n_tokens_mistral': 2769, 'n_tokens_neox': 2586, 'n_words': 698}