public class VehicleManager extends android.app.Service implements DataPipeline.Operator
get(Class)
method. Asynchronous measurements are
obtained by defining a Measurement.Listener or VehicleMessage.Listener object
and passing it to the service via the addListener method.
There are three major components in the VehicleManager:
VehicleDataSource
,
VehicleDataSink
and
VehicleInterface
.
The instance of a VehicleInterface
is perhaps the
most important. This represents the actual physical connection to the
vehicle, and is bi-directional - it can both provide data to an
application and send data back to the vehicle. In most cases,
this should not be instantiated by applications; the
setVehicleInterface(Class, String)
method takes enough metadata for
the remote VehicleService
to instantiate the
interface in a remote process. That way a single USB or
Bluetooth connection can be shared among many applications.
The VehicleManager also supports custom user-defined data sources, which can
be controlled with addSource(VehicleDataSource)
and
removeSource(VehicleDataSource)
methods. Even though data sources are
instantiated by the application, their data is still shared among all OpenXC
applications using the same remove process VehicleService
In addition to applications registered to receive updates as a Measurement
or VehicleMessage listener, the VehicleManager supports custom data sinks (e.g.
FileRecorderSink
) that be controlled with the
addSink(VehicleDataSink)
and removeSink(VehicleDataSink)
methods.
When a message is received from a
VehicleDataSource
, it is passed to every active
VehicleDataSink
. There will always be at
least one sink that stores the latest messages and handles passing on data to
users of this service.Modifier and Type | Class and Description |
---|---|
class |
VehicleManager.VehicleBinder
Binder to connect IBinder in a ServiceConnection with the VehicleManager.
|
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
ADDING_LISTENER_S_TO_S |
static java.lang.String |
UNABLE_TO_SEND_MESSAGE_TO_REMOTE_SERVICE |
static java.lang.String |
VEHICLE_LOCATION_PROVIDER |
START_CONTINUATION_MASK, START_FLAG_REDELIVERY, START_FLAG_RETRY, START_NOT_STICKY, START_REDELIVER_INTENT, START_STICKY, START_STICKY_COMPATIBILITY, STOP_FOREGROUND_DETACH, STOP_FOREGROUND_REMOVE
ACCESSIBILITY_SERVICE, ACCOUNT_SERVICE, ACTIVITY_SERVICE, ALARM_SERVICE, APP_OPS_SERVICE, APPWIDGET_SERVICE, AUDIO_SERVICE, BATTERY_SERVICE, BIND_ABOVE_CLIENT, BIND_ADJUST_WITH_ACTIVITY, BIND_ALLOW_OOM_MANAGEMENT, BIND_AUTO_CREATE, BIND_DEBUG_UNBIND, BIND_EXTERNAL_SERVICE, BIND_IMPORTANT, BIND_NOT_FOREGROUND, BIND_WAIVE_PRIORITY, BLUETOOTH_SERVICE, CAMERA_SERVICE, CAPTIONING_SERVICE, CARRIER_CONFIG_SERVICE, CLIPBOARD_SERVICE, COMPANION_DEVICE_SERVICE, CONNECTIVITY_SERVICE, CONSUMER_IR_SERVICE, CONTEXT_IGNORE_SECURITY, CONTEXT_INCLUDE_CODE, CONTEXT_RESTRICTED, CROSS_PROFILE_APPS_SERVICE, DEVICE_POLICY_SERVICE, DISPLAY_SERVICE, DOWNLOAD_SERVICE, DROPBOX_SERVICE, EUICC_SERVICE, FINGERPRINT_SERVICE, HARDWARE_PROPERTIES_SERVICE, INPUT_METHOD_SERVICE, INPUT_SERVICE, IPSEC_SERVICE, JOB_SCHEDULER_SERVICE, KEYGUARD_SERVICE, LAUNCHER_APPS_SERVICE, LAYOUT_INFLATER_SERVICE, LOCATION_SERVICE, MEDIA_PROJECTION_SERVICE, MEDIA_ROUTER_SERVICE, MEDIA_SESSION_SERVICE, MIDI_SERVICE, MODE_APPEND, MODE_ENABLE_WRITE_AHEAD_LOGGING, MODE_MULTI_PROCESS, MODE_NO_LOCALIZED_COLLATORS, MODE_PRIVATE, MODE_WORLD_READABLE, MODE_WORLD_WRITEABLE, NETWORK_STATS_SERVICE, NFC_SERVICE, NOTIFICATION_SERVICE, NSD_SERVICE, POWER_SERVICE, PRINT_SERVICE, RECEIVER_VISIBLE_TO_INSTANT_APPS, RESTRICTIONS_SERVICE, SEARCH_SERVICE, SENSOR_SERVICE, SHORTCUT_SERVICE, STORAGE_SERVICE, STORAGE_STATS_SERVICE, SYSTEM_HEALTH_SERVICE, TELECOM_SERVICE, TELEPHONY_SERVICE, TELEPHONY_SUBSCRIPTION_SERVICE, TEXT_CLASSIFICATION_SERVICE, TEXT_SERVICES_MANAGER_SERVICE, TV_INPUT_SERVICE, UI_MODE_SERVICE, USAGE_STATS_SERVICE, USB_SERVICE, USER_SERVICE, VIBRATOR_SERVICE, WALLPAPER_SERVICE, WIFI_AWARE_SERVICE, WIFI_P2P_SERVICE, WIFI_RTT_RANGING_SERVICE, WIFI_SERVICE, WINDOW_SERVICE
Constructor and Description |
---|
VehicleManager() |
Modifier and Type | Method and Description |
---|---|
void |
addListener(java.lang.Class<? extends Measurement> measurementType,
Measurement.Listener listener)
Register to receive asynchronous updates for a specific Measurement type.
|
void |
addListener(java.lang.Class<? extends VehicleMessage> messageType,
VehicleMessage.Listener listener)
Register to receive asynchronous updates for a specific VehicleMessage
type.
|
void |
addListener(KeyedMessage keyedMessage,
VehicleMessage.Listener listener)
Register to receive a callback when a message with same key as the given
KeyedMessage is received.
|
void |
addListener(KeyMatcher matcher,
VehicleMessage.Listener listener)
Register to receive a callback when a message with key matching the given
KeyMatcher is received.
|
void |
addListener(MessageKey key,
VehicleMessage.Listener listener)
Register to receive a callback when a message with the given key is
received.
|
void |
addOnVehicleInterfaceConnectedListener(ViConnectionListener listener)
Register a listener to receive a callback when the selected VI is
connected.
|
void |
addSink(VehicleDataSink sink)
Add a new data sink to the vehicle service.
|
void |
addSource(VehicleDataSource source)
Add a new data source to the vehicle service.
|
Measurement |
get(java.lang.Class<? extends Measurement> measurementType)
Retrieve the most current value of a measurement.
|
VehicleMessage |
get(MessageKey key)
Retrieve the most current value of a keyed message.
|
VehicleInterfaceDescriptor |
getActiveVehicleInterface()
Returns a descriptor of the active vehicle interface.
|
int |
getMessageCount()
Read the number of messages received by the vehicle service.
|
SourceCallback |
getRemoteCallback() |
SourceCallback |
getUserCallback() |
java.lang.String |
getVehicleInterfaceDeviceId()
Query for the unique device ID of the active VI.
|
java.lang.String |
getVehicleInterfacePlatform()
Query for the platform of the active VI.
|
java.lang.String |
getVehicleInterfaceVersion()
Query for the firmware version of the active VI.
|
boolean |
isViConnected()
Return the connection status of the selected VI.
|
android.os.IBinder |
onBind(android.content.Intent intent) |
void |
onCreate() |
void |
onDestroy() |
void |
onPipelineActivated() |
void |
onPipelineDeactivated() |
boolean |
onUnbind(android.content.Intent intent) |
void |
removeListener(java.lang.Class<? extends Measurement> measurementType,
Measurement.Listener listener)
Unregister a previously registered Measurement.Listener instance.
|
void |
removeListener(java.lang.Class<? extends VehicleMessage> messageType,
VehicleMessage.Listener listener)
Unregister a previously registered message type listener.
|
void |
removeListener(KeyedMessage message,
VehicleMessage.Listener listener)
Unregister a previously registered keyed message listener.
|
void |
removeListener(KeyMatcher matcher,
VehicleMessage.Listener listener)
Unregister a previously registered key matcher listener.
|
void |
removeListener(MessageKey key,
VehicleMessage.Listener listener)
Unregister a previously registered key listener.
|
void |
removeSink(VehicleDataSink sink)
Remove a previously registered sink from the data pipeline.
|
void |
removeSource(VehicleDataSource source)
Remove a previously registered source from the data pipeline.
|
VehicleMessage |
request(KeyedMessage message)
Send a message to the VehicleInterface and wait up to 2 seconds to
receive a response.
|
void |
request(KeyedMessage message,
VehicleMessage.Listener listener)
Send a message to the VehicleInterface and register the given listener to
receive the first response matching the message's key.
|
java.lang.String |
requestCommandMessage(Command.CommandType type)
Send a command request to the vehicle that does not require any metadata.
|
boolean |
send(Measurement message)
Convert a Measurement to a SimpleVehicleMessage and send it through the
active VehicleInterface.
|
boolean |
send(VehicleMessage message)
Send a message to the vehicle through the active
VehicleInterface without waiting for
a response. |
void |
setBluetoothPollingStatus(boolean enabled)
Control whether polling is used to connect to a Bluetooth device or not.
|
void |
setNativeGpsStatus(boolean enabled)
Control whether the device's built-in GPS is used to provide location.
|
void |
setVehicleInterface(java.lang.Class<? extends VehicleInterface> vehicleInterfaceType)
Change the active vehicle interface to a new type using its default
resource identifier.
|
void |
setVehicleInterface(java.lang.Class<? extends VehicleInterface> vehicleInterfaceType,
java.lang.String resource)
Change the active vehicle interface to a new type using the given
resource.
|
java.lang.String |
toString() |
void |
waitUntilBound()
Block until the VehicleManager is alive and can return measurements.
|
dump, getApplication, onConfigurationChanged, onLowMemory, onRebind, onStart, onStartCommand, onTaskRemoved, onTrimMemory, startForeground, stopForeground, stopForeground, stopSelf, stopSelf, stopSelfResult
attachBaseContext, bindService, checkCallingOrSelfPermission, checkCallingOrSelfUriPermission, checkCallingPermission, checkCallingUriPermission, checkPermission, checkSelfPermission, checkUriPermission, checkUriPermission, clearWallpaper, createConfigurationContext, createContextForSplit, createDeviceProtectedStorageContext, createDisplayContext, createPackageContext, databaseList, deleteDatabase, deleteFile, deleteSharedPreferences, enforceCallingOrSelfPermission, enforceCallingOrSelfUriPermission, enforceCallingPermission, enforceCallingUriPermission, enforcePermission, enforceUriPermission, enforceUriPermission, fileList, getApplicationContext, getApplicationInfo, getAssets, getBaseContext, getCacheDir, getClassLoader, getCodeCacheDir, getContentResolver, getDatabasePath, getDataDir, getDir, getExternalCacheDir, getExternalCacheDirs, getExternalFilesDir, getExternalFilesDirs, getExternalMediaDirs, getFilesDir, getFileStreamPath, getMainExecutor, getMainLooper, getNoBackupFilesDir, getObbDir, getObbDirs, getPackageCodePath, getPackageManager, getPackageName, getPackageResourcePath, getResources, getSharedPreferences, getSystemService, getSystemServiceName, getTheme, getWallpaper, getWallpaperDesiredMinimumHeight, getWallpaperDesiredMinimumWidth, grantUriPermission, isDeviceProtectedStorage, isRestricted, moveDatabaseFrom, moveSharedPreferencesFrom, openFileInput, openFileOutput, openOrCreateDatabase, openOrCreateDatabase, peekWallpaper, registerReceiver, registerReceiver, registerReceiver, registerReceiver, removeStickyBroadcast, removeStickyBroadcastAsUser, revokeUriPermission, revokeUriPermission, sendBroadcast, sendBroadcast, sendBroadcastAsUser, sendBroadcastAsUser, sendOrderedBroadcast, sendOrderedBroadcast, sendOrderedBroadcastAsUser, sendStickyBroadcast, sendStickyBroadcastAsUser, sendStickyOrderedBroadcast, sendStickyOrderedBroadcastAsUser, setTheme, setWallpaper, setWallpaper, startActivities, startActivities, startActivity, startActivity, startForegroundService, startInstrumentation, startIntentSender, startIntentSender, startService, stopService, unbindService, unregisterReceiver
public static final java.lang.String VEHICLE_LOCATION_PROVIDER
public static final java.lang.String ADDING_LISTENER_S_TO_S
public static final java.lang.String UNABLE_TO_SEND_MESSAGE_TO_REMOTE_SERVICE
public void onCreate()
onCreate
in class android.app.Service
public void onDestroy()
onDestroy
in class android.app.Service
public android.os.IBinder onBind(android.content.Intent intent)
onBind
in class android.app.Service
public boolean onUnbind(android.content.Intent intent)
onUnbind
in class android.app.Service
public void waitUntilBound() throws VehicleServiceException
VehicleServiceException
public Measurement get(java.lang.Class<? extends Measurement> measurementType) throws UnrecognizedMeasurementTypeException, NoValueException
measurementType
- The class of the requested Measurement
(e.g. VehicleSpeed.class)UnrecognizedMeasurementTypeException
- if passed a measurementType
that does not extend MeasurementNoValueException
- if no value has yet been received for this
measurementTypeBaseMeasurement
public VehicleMessage get(MessageKey key) throws NoValueException
key
- The key of the requested Measurement
(e.g. VehicleSpeed.class)NoValueException
- if no value has yet been received for this
measurementTypeBaseMeasurement
public boolean send(VehicleMessage message)
VehicleInterface
without waiting for
a response.message
- The desired message to send to the vehicle.public boolean send(Measurement message)
message
- The desired message to send to the vehicle.public void request(KeyedMessage message, VehicleMessage.Listener listener)
message
- The desired message to send to the vehicle.listener
- The message listener that should receive a callback when
a response matching the outgoing message's key is received from the
VI.public VehicleMessage request(KeyedMessage message)
public void addListener(java.lang.Class<? extends Measurement> measurementType, Measurement.Listener listener)
measurementType
- The class of the Measurement
(e.g. VehicleSpeed.class) the listener was listening forlistener
- An listener instance to receive the callback.public void addListener(java.lang.Class<? extends VehicleMessage> messageType, VehicleMessage.Listener listener)
messageType
- The class of the VehicleMessage
(e.g. SimpleVehicleMessage.class) the listener is listening forlistener
- An listener instance to receive the callback.public void addListener(KeyedMessage keyedMessage, VehicleMessage.Listener listener)
keyedMessage
- A message with the key you want to receive updates
for - the response to a command typically has the same key as the
request, so you can use the outgoing message's KeyedMessage to
register to receive a response.listener
- An listener instance to receive the callback.public void addListener(MessageKey key, VehicleMessage.Listener listener)
key
- The key you want to receive updates.listener
- An listener instance to receive the callback.public void addListener(KeyMatcher matcher, VehicleMessage.Listener listener)
matcher
- A KeyMatcher implement the desired filtering logic.listener
- An listener instance to receive the callback.public void removeListener(java.lang.Class<? extends Measurement> measurementType, Measurement.Listener listener)
measurementType
- The class of the requested Measurement
(e.g. VehicleSpeed.class)listener
- The listener to remove.public void removeListener(java.lang.Class<? extends VehicleMessage> messageType, VehicleMessage.Listener listener)
messageType
- The class of the VehicleMessage this listener was
registered to receive. A listener can be registered to receive
multiple message types, which is why this must be specified when
removing a listener.listener
- The listener to remove.public void removeListener(KeyedMessage message, VehicleMessage.Listener listener)
message
- The message with the key this listener was previously
registered to receive.listener
- The listener to remove.public void removeListener(KeyMatcher matcher, VehicleMessage.Listener listener)
matcher
- The KeyMatcher this listener was previously registered
to receive matches from.listener
- The listener to remove.public void removeListener(MessageKey key, VehicleMessage.Listener listener)
key
- The key this listener was previously registered to
receive updates on.listener
- The listener to remove.public void addSource(VehicleDataSource source)
source
- an instance of a VehicleDataSourcepublic void removeSource(VehicleDataSource source)
public void addSink(VehicleDataSink sink)
sink
- an instance of a VehicleDataSinkpublic void removeSink(VehicleDataSink sink)
public java.lang.String requestCommandMessage(Command.CommandType type)
type
- The command request type to send to the VI.public java.lang.String getVehicleInterfaceDeviceId()
public java.lang.String getVehicleInterfaceVersion()
public java.lang.String getVehicleInterfacePlatform()
public void addOnVehicleInterfaceConnectedListener(ViConnectionListener listener) throws VehicleServiceException
listener
- The listener that should receive the callback.VehicleServiceException
public void setVehicleInterface(java.lang.Class<? extends VehicleInterface> vehicleInterfaceType) throws VehicleServiceException
vehicleInterfaceType
- the VI type to activate or null to disable
all VIs.VehicleServiceException
public void setVehicleInterface(java.lang.Class<? extends VehicleInterface> vehicleInterfaceType, java.lang.String resource) throws VehicleServiceException
vehicleInterfaceType
- A class implementing VehicleInterface that is
included in the OpenXC libraryresource
- A descriptor or a resource necessary to initialize the
interface. See the specific implementation of VehicleService
to find the required format of this parameter.VehicleServiceException
public void setNativeGpsStatus(boolean enabled)
enabled
- True if GPS should be read from the Android device and
injected as vehicle data whenever a vehicle interface is connected.public void setBluetoothPollingStatus(boolean enabled)
enabled
- True if polling should be used to connect to a Bluetooth
device.public VehicleInterfaceDescriptor getActiveVehicleInterface()
public int getMessageCount() throws VehicleServiceException
VehicleServiceException
- if the listener is unable to be
unregistered with the library internals - an exceptional situation
that shouldn't occur.public boolean isViConnected()
public java.lang.String toString()
toString
in class java.lang.Object
public void onPipelineActivated()
onPipelineActivated
in interface DataPipeline.Operator
public void onPipelineDeactivated()
onPipelineDeactivated
in interface DataPipeline.Operator
public SourceCallback getRemoteCallback()
public SourceCallback getUserCallback()