Projects >> openxc-android >>77896951b9d9f33f22b91df6aef2dcc82ced374d

Chunk
Conflicting content
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceChangeListener;
<<<<<<< HEAD

import android.preference.EditTextPreference;
=======
>>>>>>> e1f1dd3bfb6284b81b1b288e3e6efb0dae734f25
import android.preference.PreferenceActivity;
import android.preference.PreferenceFragment;
import android.preference.PreferenceManager;
Solution content
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceChangeListener;

import android.preference.PreferenceActivity;
import android.preference.PreferenceFragment;
import android.preference.PreferenceManager;
File
SettingsActivity.java
Developer's decision
Version 2
Kind of conflict
Import
Chunk
Conflicting content
    private BluetoothAdapter mBluetoothAdapter;
    private ListPreference mBluetoothDeviceListPreference;
<<<<<<< HEAD
    private EditTextPreference mEthernetConnectionPreference;
=======
    private CheckBoxPreference mUploadingPreference;
    private Preference mUploadingPathPreference;
>>>>>>> e1f1dd3bfb6284b81b1b288e3e6efb0dae734f25
    private BroadcastReceiver mReceiver;

    @Override
Solution content
    private BluetoothAdapter mBluetoothAdapter;
    private ListPreference mBluetoothDeviceListPreference;
    private CheckBoxPreference mUploadingPreference;
    private EditTextPreference mEthernetConnectionPreference;
    private Preference mUploadingPathPreference;
    private BroadcastReceiver mReceiver;

    @Override
File
SettingsActivity.java
Developer's decision
Combination
Kind of conflict
Attribute
Chunk
Conflicting content
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

<<<<<<< HEAD
        mPreferences = PreferenceManager.getDefaultSharedPreferences(this);
        mPreferenceListener = new PreferenceListener();

        if(Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
            addPreferencesFromResource(R.xml.recording_preferences);
            addPreferencesFromResource(R.xml.data_source_preferences);
            addPreferencesFromResource(R.xml.output_preferences);
            mBluetoothDeviceListPreference = (ListPreference)
                    findPreference(getString(R.string.bluetooth_mac_key));
            mEthernetConnectionPreference = (EditTextPreference)
                    findPreference(getString(R.string.ethernet_connection_key));
            initializeBluetooth(mBluetoothDeviceListPreference,
                    findPreference(getString(R.string.bluetooth_checkbox_key)));
=======
        String action = getIntent().getAction();
        if(action != null) {
            if(action.equals(RECORDING_PREFERENCE)) {
                addPreferencesFromResource(R.xml.recording_preferences);

                mUploadingPreference = (CheckBoxPreference) findPreference(
                        getString(R.string.uploading_checkbox_key));
                mUploadingPathPreference = (EditTextPreference) findPreference(
                        getString(R.string.uploading_path_key));
                initializeUploadingPreferences(mUploadingPreference,
                        mUploadingPathPreference);

            } else if(action.equals(DATA_SOURCE_PREFERENCE)) {
                addPreferencesFromResource(R.xml.data_source_preferences);

                mBluetoothDeviceListPreference = (ListPreference)
                        findPreference(getString(R.string.bluetooth_mac_key));
                initializeBluetoothPreferences(mBluetoothDeviceListPreference,
                        findPreference(getString(R.string.bluetooth_checkbox_key)));
            } else if(action.equals(OUTPUT_PREFERENCE)) {
                addPreferencesFromResource(R.xml.output_preferences);
            }
        } else if(Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
            addPreferencesFromResource(R.xml.preference_headers_legacy);
>>>>>>> e1f1dd3bfb6284b81b1b288e3e6efb0dae734f25
        }

Solution content
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        String action = getIntent().getAction();
        if(action != null) {
            if(action.equals(RECORDING_PREFERENCE)) {
                addPreferencesFromResource(R.xml.recording_preferences);

                mUploadingPreference = (CheckBoxPreference) findPreference(
                        getString(R.string.uploading_checkbox_key));
                mUploadingPathPreference = (EditTextPreference) findPreference(
                        getString(R.string.uploading_path_key));
                initializeUploadingPreferences(mUploadingPreference,
                        mUploadingPathPreference);

            } else if(action.equals(DATA_SOURCE_PREFERENCE)) {
                addPreferencesFromResource(R.xml.data_source_preferences);

                mBluetoothDeviceListPreference = (ListPreference)
                        findPreference(getString(R.string.bluetooth_mac_key));
                initializeBluetoothPreferences(mBluetoothDeviceListPreference,
                        findPreference(getString(R.string.bluetooth_checkbox_key)));

                mEthernetConnectionPreference = (EditTextPreference)
                        findPreference(getString(R.string.ethernet_connection_key));
                initializeEthernet((EditTextPreference) findPreference(
                        getString(R.string.ethernet_connection_key)),
                        findPreference(getString(R.string.ethernet_checkbox_key)));
            } else if(action.equals(OUTPUT_PREFERENCE)) {
                addPreferencesFromResource(R.xml.output_preferences);
            }
        } else if(Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
            addPreferencesFromResource(R.xml.preference_headers_legacy);
        }
File
SettingsActivity.java
Developer's decision
Manual
Kind of conflict
Attribute
Cast expression
If statement
Method invocation
Variable
Chunk
Conflicting content
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            addPreferencesFromResource(R.xml.data_source_preferences);
<<<<<<< HEAD
            ((SettingsActivity)getActivity()).initializeBluetooth(
=======
            ((SettingsActivity)getActivity()).initializeBluetoothPreferences(
>>>>>>> e1f1dd3bfb6284b81b1b288e3e6efb0dae734f25
                (ListPreference)
                findPreference(getString(R.string.bluetooth_mac_key)),
                findPreference(getString(R.string.bluetooth_checkbox_key)));
Solution content
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            addPreferencesFromResource(R.xml.data_source_preferences);
            ((SettingsActivity)getActivity()).initializeBluetoothPreferences(
                (ListPreference)
                findPreference(getString(R.string.bluetooth_mac_key)),
                findPreference(getString(R.string.bluetooth_checkbox_key)));
File
SettingsActivity.java
Developer's decision
Version 2
Kind of conflict
Method invocation
Chunk
Conflicting content
        }
    }

<<<<<<< HEAD
    protected void initializeBluetooth(ListPreference listPreference,
=======
    protected void initializeUploadingPreferences(Preference uploadingPreference,
            Preference uploadingPathPreference) {
        mUploadingPreference = (CheckBoxPreference) uploadingPreference;
        mUploadingPathPreference = uploadingPathPreference;

        mUploadingPreference.setOnPreferenceChangeListener(
                mUploadingPreferenceListener);
        mUploadingPathPreference.setOnPreferenceChangeListener(
                mUploadingPathPreferenceListener);
    }

    protected void initializeBluetoothPreferences(ListPreference listPreference,
>>>>>>> e1f1dd3bfb6284b81b1b288e3e6efb0dae734f25
            Preference checkboxPreference) {
        mBluetoothDeviceListPreference = listPreference;
        mBluetoothDeviceListPreference.setOnPreferenceChangeListener(
Solution content
        }
    }

    protected void initializeUploadingPreferences(Preference uploadingPreference,
            Preference uploadingPathPreference) {
        mUploadingPreference = (CheckBoxPreference) uploadingPreference;
        mUploadingPathPreference = uploadingPathPreference;

        mUploadingPreference.setOnPreferenceChangeListener(
                mUploadingPreferenceListener);
        mUploadingPathPreference.setOnPreferenceChangeListener(
                mUploadingPathPreferenceListener);
    }

    protected void initializeBluetoothPreferences(ListPreference listPreference,
            Preference checkboxPreference) {
        mBluetoothDeviceListPreference = listPreference;
        mBluetoothDeviceListPreference.setOnPreferenceChangeListener(
File
SettingsActivity.java
Developer's decision
Version 2
Kind of conflict
Method declaration
Method signature
Chunk
Conflicting content
import com.openxc.sources.SourceCallback;
import com.openxc.sources.VehicleDataSource;
import com.openxc.sources.usb.UsbVehicleDataSource;
<<<<<<< HEAD
import com.openxc.sources.ethernet.EthernetVehicleDataSource;
import com.openxc.util.AndroidFileOpener;

import android.widget.Toast;
=======
>>>>>>> e1f1dd3bfb6284b81b1b288e3e6efb0dae734f25

/**
 * The VehicleManager is an in-process Android service and the primary entry
Solution content
import com.openxc.sources.SourceCallback;
import com.openxc.sources.VehicleDataSource;
import com.openxc.sources.usb.UsbVehicleDataSource;

/**
 * The VehicleManager is an in-process Android service and the primary entry
File
VehicleManager.java
Developer's decision
Version 2
Kind of conflict
Import
Chunk
Conflicting content
    private VehicleServiceInterface mRemoteService;
    private DataPipeline mPipeline;
    private RemoteListenerSource mRemoteSource;
<<<<<<< HEAD
    private VehicleDataSink mFileRecorder;
    private VehicleDataSource mNativeLocationSource;
    private BluetoothVehicleDataSource mBluetoothSource;
    private EthernetVehicleDataSource mEthernetSource;
    private MockedLocationSink mMockedLocationSink;
    private VehicleDataSink mUploader;
=======
>>>>>>> e1f1dd3bfb6284b81b1b288e3e6efb0dae734f25
    private MeasurementListenerSink mNotifier;
    // The DataPipeline in this class must only have 1 source - the special
    // RemoteListenerSource that receives measurements from the
Solution content
    private VehicleServiceInterface mRemoteService;
    private DataPipeline mPipeline;
    private RemoteListenerSource mRemoteSource;
    private MeasurementListenerSink mNotifier;
    // The DataPipeline in this class must only have 1 source - the special
    // RemoteListenerSource that receives measurements from the
File
VehicleManager.java
Developer's decision
Version 2
Kind of conflict
Attribute
Chunk
Conflicting content
        if(mPipeline != null) {
            mPipeline.stop();
        }
<<<<<<< HEAD
        if(mBluetoothSource != null) {
            mBluetoothSource.close();
        }
        if (mEthernetSource != null)
        {
            mEthernetSource.stop();
        }
        unwatchPreferences(mPreferences, mPreferenceListener);
=======
>>>>>>> e1f1dd3bfb6284b81b1b288e3e6efb0dae734f25
        unbindRemote();
    }
Solution content
        if(mPipeline != null) {
            mPipeline.stop();
        }
        unbindRemote();
    }
File
VehicleManager.java
Developer's decision
Version 2
Kind of conflict
If statement
Method invocation
Chunk
Conflicting content
        RawMeasurement rawCommand = command.toRaw();
        // prefer the Bluetooth controller, if connected
<<<<<<< HEAD
        if(mBluetoothSource != null) {
            Log.d(TAG, "Sending " + rawCommand + " over Bluetooth to " +
                    mBluetoothSource);
            mBluetoothSource.set(rawCommand);
        } else if (mEthernetSource != null)
        {
            Log.d(TAG, "Sending " + rawCommand + " over Ethernet to " + mEthernetSource);
            mEthernetSource.set(rawCommand);
        } else {
            if(mRemoteService == null) {
                Log.w(TAG, "Not connected to the VehicleService");
                return;
            }
=======
        // TODO since we now manage the bluetooth source in the enabler, the
        // VehicleManager should instead look through all existing data sources
        // to see if any are writeable
        // if(mBluetoothSource != null) {
            // Log.d(TAG, "Sending " + rawCommand + " over Bluetooth to " +
                    // mBluetoothSource);
            // mBluetoothSource.set(rawCommand);
        // } else {
        if(mRemoteService == null) {
            Log.w(TAG, "Not connected to the VehicleService");
            return;
        }
>>>>>>> e1f1dd3bfb6284b81b1b288e3e6efb0dae734f25

        try {
            mRemoteService.set(rawCommand);
Solution content
        RawMeasurement rawCommand = command.toRaw();
        // prefer the Bluetooth controller, if connected
        // TODO since we now manage the bluetooth source in the enabler, the
        // VehicleManager should instead look through all existing data sources
        // to see if any are writeable
        // if(mBluetoothSource != null) {
            // Log.d(TAG, "Sending " + rawCommand + " over Bluetooth to " +
                    // mBluetoothSource);
            // mBluetoothSource.set(rawCommand);
        // } else {
        // TODO handle ethernet, too
        if(mRemoteService == null) {
            Log.w(TAG, "Not connected to the VehicleService");
            return;
        }

        try {
            mRemoteService.set(rawCommand);
File
VehicleManager.java
Developer's decision
Manual
Kind of conflict
Comment
If statement
Method invocation
Chunk
Conflicting content
     *
    }

    /**
<<<<<<< HEAD
     * Enable or disable uploading of a vehicle trace to a remote web server.
     *
     * The URL of the web server to upload the trace to is read from the shared
     * preferences.
     *
     * @param enabled true if uploading should be enabled
     * @throws VehicleServiceException if the listener is unable to be
     *      unregistered with the library internals - an exceptional situation
     *      that shouldn't occur.
     */
    public void setUploadingStatus(boolean enabled)
            throws VehicleServiceException {
        Log.i(TAG, "Setting uploading to " + enabled);
        if(enabled) {
            String path = mPreferences.getString(
                    getString(R.string.uploading_path_key), null);
            String error = "Target URL in preferences not valid " +
                    "-- not starting uploading a trace";
            if(!UploaderSink.validatePath(path)) {
                Log.w(TAG, error);
            } else {
                try {
                    mUploader = mPipeline.addSink(new UploaderSink(this, path));
                } catch(java.net.URISyntaxException e) {
                    Log.w(TAG, error, e);
                }
            }
        } else {
            mPipeline.removeSink(mUploader);
        }
    }

    /**
     * Enable or disable receiving vehicle data from a Bluetooth CAN device.
     *
     * @param enabled true if bluetooth should be enabled
     * @throws VehicleServiceException if the listener is unable to be
     *      unregistered with the library internals - an exceptional
     *      situation that shouldn't occur.
     */
    public void setBluetoothSourceStatus(boolean enabled)
            throws VehicleServiceException {
        Log.i(TAG, "Setting bluetooth data source to " + enabled);
        if(enabled) {
            String deviceAddress = mPreferences.getString(
                    getString(R.string.bluetooth_mac_key), null);
            if(deviceAddress != null) {
                removeSource(mBluetoothSource);
                if(mBluetoothSource != null) {
                    mBluetoothSource.close();
                }

                try {
                    mBluetoothSource =
                        new BluetoothVehicleDataSource(this, deviceAddress);
                } catch(DataSourceException e) {
                    Log.w(TAG, "Unable to add Bluetooth source", e);
                    return;
                }
                addSource(mBluetoothSource);
            } else {
                Log.d(TAG, "No Bluetooth device MAC set yet (" + deviceAddress +
                        "), not starting source");
            }
        }
        else {
            removeSource(mBluetoothSource);
            if(mBluetoothSource != null) {
                mBluetoothSource.close();
            }
        }
    }

    /**
     * Enable or disable receiving vehicle data from a Ethernet device
     *
     * @param enabled
     *            true if ethernet should be enabled
     * @throws VehicleServiceException
     *             if the listener is unable to be unregistered with the library
     *             internals - an exceptional situation that shouldn't occur.
     */
    public void setEthernetSourceStatus(boolean enabled)
            throws VehicleServiceException {
        Log.i(TAG, "Setting ethernet data source to " + enabled);
        if(enabled) {
            String deviceAddress = mPreferences.getString(
                    getString(R.string.ethernet_connection_key), null);

            InetSocketAddress ethernetAddr;
            String addressSplit[] = deviceAddress.split(":");
            if(addressSplit.length != 2) {
                throw new VehicleServiceException(
                    "Device address in wrong format! Expected: ip:port");
            } else {
                Integer port = new Integer(addressSplit[1]);

                String host = addressSplit[0];
                ethernetAddr = new InetSocketAddress(host, port.intValue());
            }

            if(deviceAddress != null) {
                removeSource(mEthernetSource);
                if(mEthernetSource != null) {
                    mEthernetSource.stop();
                }

                try {
                    mEthernetSource = new EthernetVehicleDataSource(
                            ethernetAddr, this);
                    mEthernetSource.start();
                } catch (DataSourceException e) {
                    Log.w(TAG, "Unable to add Ethernet source", e);
                    return;
                }
                addSource(mEthernetSource);
            }
            else {
                Log.d(TAG, "No ethernet address set yet (" + deviceAddress +
                        "), not starting source");
            }
        }
        else {
            removeSource(mEthernetSource);
            if(mEthernetSource != null) {
                mEthernetSource.stop();
            }
        }
    }
    /**
     * Enable or disable recording of a trace file.
     *
     * @param enabled true if recording should be enabled
     * @throws VehicleServiceException if the listener is unable to be
     *      unregistered with the library internals - an exceptional
     *      situation that shouldn't occur.
     */
    public void setFileRecordingStatus(boolean enabled)
            throws VehicleServiceException {
        Log.i(TAG, "Setting recording to " + enabled);
        if(enabled) {
            String directory = mPreferences.getString(
                    getString(R.string.recording_directory_key), null);
            try {
                mFileRecorder = mPipeline.addSink(new FileRecorderSink(
                            new AndroidFileOpener(this, directory)));
            } catch(DataSinkException e) {
                Log.w(TAG, "Unable to start trace recording", e);
            }
        }
        else {
            mPipeline.removeSink(mFileRecorder);
        }
    }

    /**
     * Enable or disable reading GPS from the native Android stack.
     *
     * @param enabled true if native GPS should be passed through
     * @throws VehicleServiceException if native GPS status is unable to be set
     *      - an exceptional situation that shouldn't occur.
     */
    public void setNativeGpsStatus(boolean enabled)
            throws VehicleServiceException {
        Log.i(TAG, "Setting native GPS to " + enabled);
        if(enabled) {
            mNativeLocationSource = mPipeline.addSource(
                    new NativeLocationSource(this));
        } else if(mNativeLocationSource != null) {
            mPipeline.removeSource(mNativeLocationSource);
            mNativeLocationSource = null;
        }
    }

    /**
     * Enable or disable overwriting native GPS measurements with those from the
     * vehicle.
     *
     * @see MockedLocationSink#setOverwritingStatus
     * @param enabled true if native GPS should be overwritte.
     * @throws VehicleServiceException if GPS overwriting status is unable to be
     *      set - an exceptional situation that shouldn't occur.
     */
    public void setNativeGpsOverwriteStatus(boolean enabled)
            throws VehicleServiceException {
        Log.i(TAG, "Setting native GPS overwriting to " + enabled);
        mMockedLocationSink.setOverwritingStatus(enabled);
    }

    /**
=======
>>>>>>> e1f1dd3bfb6284b81b1b288e3e6efb0dae734f25
     * Read the number of messages received by the vehicle service.
     *
     * @throws VehicleServiceException if the listener is unable to be
Solution content
    }

    /**
     * Read the number of messages received by the vehicle service.
     *
     * @throws VehicleServiceException if the listener is unable to be
File
VehicleManager.java
Developer's decision
Version 2
Kind of conflict
Comment
Method declaration
Chunk
Conflicting content
            mRemoteBoundLock.unlock();
        }
    }
<<<<<<< HEAD

    private class PreferenceListener
            implements SharedPreferences.OnSharedPreferenceChangeListener {

        SharedPreferences mPreferences;

        public PreferenceListener(SharedPreferences preferences) {
            mPreferences = preferences;
        }

        public void readStoredPreferences() {
            try {
                setFileRecordingStatus(mPreferences.getBoolean(
                            getString(R.string.recording_checkbox_key), false));
                setNativeGpsStatus(mPreferences.getBoolean(
                            getString(R.string.native_gps_checkbox_key), false));
                setNativeGpsOverwriteStatus(mPreferences.getBoolean(
                            getString(R.string.gps_overwrite_checkbox_key),
                            false));
                setUploadingStatus(mPreferences.getBoolean(
                            getString(R.string.uploading_checkbox_key), false));
                setBluetoothSourceStatus(mPreferences.getBoolean(
                            getString(R.string.bluetooth_checkbox_key), false));
                setEthernetSourceStatus(mPreferences.getBoolean(
                            getString(R.string.ethernet_checkbox_key), false));
            } catch(VehicleServiceException e) {
                Log.w(TAG, "Unable to initialize vehicle service with stored "
                        + "preferences", e);
            }
        }

        public void onSharedPreferenceChanged(SharedPreferences preferences,
                String key) {
            try {
                if(key.equals(getString(R.string.recording_checkbox_key))) {
                    setFileRecordingStatus(preferences.getBoolean(key, false));
                } else if(key.equals(getString(R.string.native_gps_checkbox_key))) {
                    setNativeGpsStatus(preferences.getBoolean(key, false));
                } else if(key.equals(getString(R.string.gps_overwrite_checkbox_key))) {
                    setNativeGpsOverwriteStatus(preferences.getBoolean(key, false));
                } else if(key.equals(getString(R.string.uploading_checkbox_key))) {
                    setUploadingStatus(preferences.getBoolean(key, false));
                } else if(key.equals(getString(R.string.bluetooth_checkbox_key))
                            || key.equals(getString(R.string.bluetooth_mac_key))) {
                    setBluetoothSourceStatus(preferences.getBoolean(
                                getString(R.string.bluetooth_checkbox_key), false));
                } else if (key.equals(getString(R.string.ethernet_checkbox_key))
                        || key.equals(getString(R.string.ethernet_connection_key))) {
                    setEthernetSourceStatus(preferences.getBoolean(getString(R.string.ethernet_checkbox_key), false));
                }

            } catch(VehicleServiceException e) {
                Log.w(TAG, "Unable to update vehicle service when preference \""
                        + key + "\" changed", e);
            }
        }
    }
=======
>>>>>>> e1f1dd3bfb6284b81b1b288e3e6efb0dae734f25
}
Solution content
            mRemoteBoundLock.unlock();
        }
    }
}
File
VehicleManager.java
Developer's decision
Version 2
Kind of conflict
Class declaration