<commit_before>/*
 SWService.java
 Copyright (c) 2014 NTT DOCOMO,INC.
 Released under the MIT license
 http://opensource.org/licenses/mit-license.php
 */
package org.deviceconnect.android.deviceplugin.sw;

import android.bluetooth.BluetoothDevice;

import org.deviceconnect.android.deviceplugin.bluetooth.BluetoothDeviceManager;
import org.deviceconnect.android.deviceplugin.sw.profile.SWKeyEventProfile;
import org.deviceconnect.android.deviceplugin.sw.profile.SWSystemProfile;
import org.deviceconnect.android.deviceplugin.sw.profile.SWTouchProfile;
import org.deviceconnect.android.deviceplugin.sw.service.SWService;
import org.deviceconnect.android.deviceplugin.sw.service.SWServiceFactory;
import org.deviceconnect.android.event.EventManager;
import org.deviceconnect.android.event.cache.MemoryCacheController;
import org.deviceconnect.android.message.DConnectMessageService;
import org.deviceconnect.android.profile.KeyEventProfile;
import org.deviceconnect.android.profile.SystemProfile;
import org.deviceconnect.android.profile.TouchProfile;
import org.deviceconnect.android.service.DConnectService;

import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;

/**
 * 本デバイスプラグインのプロファイルをDeviceConnectに登録するサービス.
 */
public class SWDeviceService extends DConnectMessageService {

    private final Logger mLogger = Logger.getLogger(SWConstants.LOGGER_NAME);

    private BluetoothDeviceManager mDeviceMgr;

    private final BluetoothDeviceManager.DeviceListener mDeviceListener
        = new BluetoothDeviceManager.DeviceListener() {
        @Override
        public void onFound(final BluetoothDevice smartWatch) {
            mLogger.info("onFound: name = " + smartWatch.getName());

            DConnectService service = getService(smartWatch);
            if (service == null) {
                service = SWServiceFactory.createService(smartWatch);
                getServiceProvider().addService(service);
            }
        }

        @Override
        public void onConnected(final BluetoothDevice smartWatch) {
            mLogger.info("onConnected: name = " + smartWatch.getName());
            // 接続状態は「スマートコネクト」アプリのデータベースから別途取得するため、
            // ここでは何もしない.
        }

        @Override
        public void onDisconnected(final BluetoothDevice smartWatch) {
            mLogger.info("onDisconnected: name = " + smartWatch.getName());
            // 接続状態は「スマートコネクト」アプリのデータベースから別途取得するため、
            // ここでは何もしない.
        }
    };

    private DConnectService getService(final BluetoothDevice device) {
        return getServiceProvider().getService(SWService.createServiceId(device));
    }

    @Override
    public void onCreate() {
        super.onCreate();

        EventManager.INSTANCE.setController(new MemoryCacheController());

        mDeviceMgr = new SWDeviceManager(this);
        mDeviceMgr.addDeviceListener(mDeviceListener);
        mDeviceMgr.start();
        for (BluetoothDevice smartWatch : mDeviceMgr.getCachedDeviceList()) {
            DConnectService service = SWServiceFactory.createService(smartWatch);
            getServiceProvider().addService(service);
        }
    }

    @Override
    public void onDestroy() {
        mDeviceMgr.removeDeviceListener(mDeviceListener);
        mDeviceMgr.stop();

        super.onDestroy();
    }

    @Override
    protected void onManagerUninstalled() {
        // Managerアンインストール検知時の処理。
        mLogger.info("Plug-in : onManagerUninstalled");
    }

    @Override
    protected void onManagerTerminated() {
        // Manager正常終了通知受信時の処理。
        mLogger.info("Plug-in : onManagerTerminated");
    }

    @Override
    protected void onManagerEventTransmitDisconnected(String sessionKey) {
        // ManagerのEvent送信経路切断通知受信時の処理。
        mLogger.info("Plug-in : onManagerEventTransmitDisconnected");
        if (sessionKey != null) {
            EventManager.INSTANCE.removeEvents(sessionKey);
        } else {
            EventManager.INSTANCE.removeAll();
        }
    }

    @Override
    protected void onDevicePluginReset() {
        // Device Plug-inへのReset要求受信時の処理。
        mLogger.info("Plug-in : onDevicePluginReset");
        resetPluginResource();
    }

    /**
     * リソースリセット処理.
     */
    private void resetPluginResource() {
        /** 全イベント削除. */
        EventManager.INSTANCE.removeAll();

        /** KeyEvent イベント 解放. */
        List<SWKeyEventProfile> keyeventProfiles = new ArrayList<SWKeyEventProfile>();
        for (DConnectService service : getServiceProvider().getServiceList()) {
            SWKeyEventProfile profile = (SWKeyEventProfile) service.getProfile(KeyEventProfile.PROFILE_NAME);
            if (profile != null && !keyeventProfiles.contains(profile)) {
                keyeventProfiles.add(profile);
            }
        }
        for (SWKeyEventProfile profile : keyeventProfiles) {
            profile.releaseKeyEvent();
        }
<commit_msg>デバッグ用ログ修正。<commit_after>/*
 SWService.java
 Copyright (c) 2014 NTT DOCOMO,INC.
 Released under the MIT license
 http://opensource.org/licenses/mit-license.php
 */
package org.deviceconnect.android.deviceplugin.sw;

import android.bluetooth.BluetoothDevice;

import org.deviceconnect.android.deviceplugin.bluetooth.BluetoothDeviceManager;
import org.deviceconnect.android.deviceplugin.sw.profile.SWKeyEventProfile;
import org.deviceconnect.android.deviceplugin.sw.profile.SWSystemProfile;
import org.deviceconnect.android.deviceplugin.sw.profile.SWTouchProfile;
import org.deviceconnect.android.deviceplugin.sw.service.SWService;
import org.deviceconnect.android.deviceplugin.sw.service.SWServiceFactory;
import org.deviceconnect.android.event.EventManager;
import org.deviceconnect.android.event.cache.MemoryCacheController;
import org.deviceconnect.android.message.DConnectMessageService;
import org.deviceconnect.android.profile.KeyEventProfile;
import org.deviceconnect.android.profile.SystemProfile;
import org.deviceconnect.android.profile.TouchProfile;
import org.deviceconnect.android.service.DConnectService;

import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;

/**
 * 本デバイスプラグインのプロファイルをDeviceConnectに登録するサービス.
 */
public class SWDeviceService extends DConnectMessageService {

    private final Logger mLogger = Logger.getLogger(SWConstants.LOGGER_NAME);

    private BluetoothDeviceManager mDeviceMgr;

    private final BluetoothDeviceManager.DeviceListener mDeviceListener
        = new BluetoothDeviceManager.DeviceListener() {
        @Override
        public void onFound(final BluetoothDevice smartWatch) {
            mLogger.info("onFound: name = " + smartWatch.getName());

            DConnectService service = getService(smartWatch);
            if (service == null) {
                service = SWServiceFactory.createService(smartWatch);
                getServiceProvider().addService(service);
            }
        }

        @Override
        public void onConnected(final BluetoothDevice smartWatch) {
            mLogger.info("onConnected: name = " + smartWatch.getName());
            // 接続状態は「スマートコネクト」アプリのデータベースから別途取得するため、
            // ここでは何もしない.
        }

        @Override
        public void onDisconnected(final BluetoothDevice smartWatch) {
            mLogger.info("onDisconnected: name = " + smartWatch.getName());
            // 接続状態は「スマートコネクト」アプリのデータベースから別途取得するため、
            // ここでは何もしない.
        }
    };

    private DConnectService getService(final BluetoothDevice device) {
        return getServiceProvider().getService(SWService.createServiceId(device));
    }

    @Override
    public void onCreate() {
        super.onCreate();

        EventManager.INSTANCE.setController(new MemoryCacheController());

        mDeviceMgr = new SWDeviceManager(this);
        mDeviceMgr.addDeviceListener(mDeviceListener);
        mDeviceMgr.start();
        for (BluetoothDevice smartWatch : mDeviceMgr.getCachedDeviceList()) {
            DConnectService service = SWServiceFactory.createService(smartWatch);
            getServiceProvider().addService(service);
        }
    }

    @Override
    public void onDestroy() {
        mDeviceMgr.removeDeviceListener(mDeviceListener);
        mDeviceMgr.stop();

        super.onDestroy();
    }

    @Override
    protected void onManagerUninstalled() {
        // Managerアンインストール検知時の処理。
        if (BuildConfig.DEBUG) {
            mLogger.info("Plug-in : onManagerUninstalled");
        }
    }

    @Override
    protected void onManagerTerminated() {
        // Manager正常終了通知受信時の処理。
        if (BuildConfig.DEBUG) {
            mLogger.info("Plug-in : onManagerTerminated");
        }
    }

    @Override
    protected void onManagerEventTransmitDisconnected(String sessionKey) {
        // ManagerのEvent送信経路切断通知受信時の処理。
        if (BuildConfig.DEBUG) {
            mLogger.info("Plug-in : onManagerEventTransmitDisconnected");
        }
        if (sessionKey != null) {
            EventManager.INSTANCE.removeEvents(sessionKey);
        } else {
            EventManager.INSTANCE.removeAll();
        }
    }

    @Override
    protected void onDevicePluginReset() {
        // Device Plug-inへのReset要求受信時の処理。
        if (BuildConfig.DEBUG) {
            mLogger.info("Plug-in : onDevicePluginReset");
        }
        resetPluginResource();
    }

    /**
     * リソースリセット処理.
     */
    private void resetPluginResource() {
        /** 全イベント削除. */
        EventManager.INSTANCE.removeAll();

        /** KeyEvent イベント 解放. */
        List<SWKeyEventProfile> keyeventProfiles = new ArrayList<SWKeyEventProfile>();
        for (DConnectService service : getServiceProvider().getServiceList()) {
            SWKeyEventProfile profile = (SWKeyEventProfile) service.getProfile(KeyEventProfile.PROFILE_NAME);
            if (profile != null && !keyeventProfiles.contains(profile)) {
                keyeventProfiles.add(profile);
            }
        }
        for (SWKeyEventProfile profile : keyeventProfiles) {
            profile.releaseKeyEvent();
        }

{'fraction_non_alphanumeric': 0.09562431160508661, 'fraction_numerical': 0.0008010413537598879, 'mean_word_length': 3.009634684865516, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '5018307', 'n_tokens_mistral': 2928, 'n_tokens_neox': 2892, 'n_words': 430}