<commit_before>package com.openxc.remote;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.util.Log;

import com.openxc.DataPipeline;
import com.openxc.interfaces.VehicleInterface;
import com.openxc.interfaces.VehicleInterfaceException;
import com.openxc.interfaces.VehicleInterfaceFactory;
import com.openxc.interfaces.VehicleInterfaceManagerUtils;
import com.openxc.interfaces.usb.UsbVehicleInterface;
import com.openxc.sinks.RemoteCallbackSink;
import com.openxc.sinks.VehicleDataSink;
import com.openxc.sources.ApplicationSource;
import com.openxc.sources.VehicleDataSource;

/**
 * The VehicleService is the centralized source of all vehicle data.
 *
 * This server is intended to be a singleton on an Android device. All OpenXC
 * applciations funnel data to and from this service so they can share sources,
 * sinks and vehicle interfaces.
 *
 * Applications should not use this service directly, but should bind to the
 * in-process {@link com.openxc.VehicleManager} instead - that has an interface
 * that respects Measurement types. The interface used for the
 * VehicleService is purposefully primative as there are a small set of
 * objects that can be natively marshalled through an AIDL interface.
 *
 * By default, the {@link UsbVehicleInterface} is activated as a
 * {@link VehicleInterface}. Other vehicle interfaces can be activated with the
 * {@link #addVehicleInterface(Class, String)} method and they can removed with
 * {@link #removeVehicleInterface(Class)}.
 *
 * This service uses the same {@link com.openxc.DataPipeline} as the
 * {@link com.openxc.VehicleManager} to move data from sources to sinks, but it
 * the pipeline is not modifiable by the application as there is no good way to
 * pass running sources through the AIDL interface. The same style is used here
 * for clarity and in order to share code.
 */
public class VehicleService extends Service {
    private final static String TAG = "VehicleService";

    private DataPipeline mPipeline;
    private RemoteCallbackSink mNotifier;
    private ApplicationSource mApplicationSource;
    private CopyOnWriteArrayList<VehicleInterface> mInterfaces;

    @Override
    public void onCreate() {
        super.onCreate();
        Log.i(TAG, "Service starting");
        mPipeline = new DataPipeline();
        mApplicationSource = new ApplicationSource();
        mInterfaces = new CopyOnWriteArrayList<VehicleInterface>();
    }

    /**
     * Shut down any associated services when this service is about to die.
     *
     * This stops the data source (e.g. stops trace playback) and kills the
     * thread used for notifying measurement listeners.
     */
    @Override
    public void onDestroy() {
        Log.i(TAG, "Service being destroyed");
        if(mPipeline != null) {
            mPipeline.stop();
        }
    }

    /**
     * Initialize the service and data source when a client binds to us.
     */
    @Override
    public IBinder onBind(Intent intent) {
        Log.i(TAG, "Service binding in response to " + intent);

        initializeDefaultSources();
        initializeDefaultSinks(mPipeline);
        return mBinder;
    }

    private void initializeDefaultSinks(DataPipeline pipeline) {
        mNotifier = new RemoteCallbackSink();
        pipeline.addSink(mNotifier);
    }

    private void initializeDefaultSources() {
        mPipeline.addSource(mApplicationSource);
        addVehicleInterface(UsbVehicleInterface.class);
    }<commit_msg>Initialize members at declaration instead of in onCreate.<commit_after>package com.openxc.remote;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.util.Log;

import com.openxc.DataPipeline;
import com.openxc.interfaces.VehicleInterface;
import com.openxc.interfaces.VehicleInterfaceException;
import com.openxc.interfaces.VehicleInterfaceFactory;
import com.openxc.interfaces.VehicleInterfaceManagerUtils;
import com.openxc.interfaces.usb.UsbVehicleInterface;
import com.openxc.sinks.RemoteCallbackSink;
import com.openxc.sinks.VehicleDataSink;
import com.openxc.sources.ApplicationSource;
import com.openxc.sources.VehicleDataSource;

/**
 * The VehicleService is the centralized source of all vehicle data.
 *
 * This server is intended to be a singleton on an Android device. All OpenXC
 * applciations funnel data to and from this service so they can share sources,
 * sinks and vehicle interfaces.
 *
 * Applications should not use this service directly, but should bind to the
 * in-process {@link com.openxc.VehicleManager} instead - that has an interface
 * that respects Measurement types. The interface used for the
 * VehicleService is purposefully primative as there are a small set of
 * objects that can be natively marshalled through an AIDL interface.
 *
 * By default, the {@link UsbVehicleInterface} is activated as a
 * {@link VehicleInterface}. Other vehicle interfaces can be activated with the
 * {@link #addVehicleInterface(Class, String)} method and they can removed with
 * {@link #removeVehicleInterface(Class)}.
 *
 * This service uses the same {@link com.openxc.DataPipeline} as the
 * {@link com.openxc.VehicleManager} to move data from sources to sinks, but it
 * the pipeline is not modifiable by the application as there is no good way to
 * pass running sources through the AIDL interface. The same style is used here
 * for clarity and in order to share code.
 */
public class VehicleService extends Service {
    private final static String TAG = "VehicleService";

    private DataPipeline mPipeline = new DataPipeline();
    private ApplicationSource mApplicationSource = new ApplicationSource();
    private CopyOnWriteArrayList<VehicleInterface> mInterfaces =
            new CopyOnWriteArrayList<VehicleInterface>();
    private RemoteCallbackSink mNotifier = new RemoteCallbackSink();

    @Override
    public void onCreate() {
        super.onCreate();
        Log.i(TAG, "Service starting");
    }

    /**
     * Shut down any associated services when this service is about to die.
     *
     * This stops the data source (e.g. stops trace playback) and kills the
     * thread used for notifying measurement listeners.
     */
    @Override
    public void onDestroy() {
        Log.i(TAG, "Service being destroyed");
        mPipeline.stop();
    }

    /**
     * Initialize the service and data source when a client binds to us.
     */
    @Override
    public IBinder onBind(Intent intent) {
        Log.i(TAG, "Service binding in response to " + intent);

        initializeDefaultSources();
        initializeDefaultSinks(mPipeline);
        return mBinder;
    }

    private void initializeDefaultSinks(DataPipeline pipeline) {
        pipeline.addSink(mNotifier);
    }

    private void initializeDefaultSources() {
        mPipeline.addSource(mApplicationSource);
        addVehicleInterface(UsbVehicleInterface.class);
    }
{'fraction_non_alphanumeric': 0.07505241090146751, 'fraction_numerical': 0.0, 'mean_word_length': 3.8286099865047234, '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': '5226', 'n_tokens_mistral': 1887, 'n_tokens_neox': 1873, 'n_words': 671}