public VehicleInterfaceDescriptor(VehicleInterface vi) { this(vi.getClass(), vi.isConnected()); }
@Override public boolean send(VehicleMessage command) { command.untimestamp(); boolean sent = false; synchronized(VehicleService.this) { if(mVehicleInterface != null && mVehicleInterface.isConnected()) { try { mVehicleInterface.receive(command); Log.d(TAG, "Sent " + command + " using interface " + mVehicleInterface); sent = true; } catch(DataSinkException e) { Log.w(TAG, mVehicleInterface + " unable to send command", e); } } else { Log.w(TAG, "No connected VI available to send command"); } } return sent; }
@Override public void onPipelineDeactivated() { if(!mUserPipelineActive) { mWakeLocker.releaseWakeLock(); removeFromForeground(); synchronized(this) { if(mVehicleInterface == null || !mVehicleInterface.isConnected()) { synchronized(mViConnectionListeners) { int i = mViConnectionListeners.beginBroadcast(); while(i > 0) { i--; try { mViConnectionListeners.getBroadcastItem(i).onDisconnected(); } catch(RemoteException e) { Log.w(TAG, "Couldn't notify VI connection " + "listener -- did it crash?", e); } } mViConnectionListeners.finishBroadcast(); } } } } } }
@Override public synchronized void onPipelineActivated() { mWakeLocker.acquireWakeLock(); moveToForeground(); if(mVehicleInterface != null && mVehicleInterface.isConnected()) { VehicleInterfaceDescriptor descriptor = new VehicleInterfaceDescriptor(mVehicleInterface); synchronized(mViConnectionListeners) { int i = mViConnectionListeners.beginBroadcast(); while(i > 0) { i--; try { mViConnectionListeners.getBroadcastItem(i).onConnected(descriptor); } catch(RemoteException e) { Log.w(TAG, "Couldn't notify VI connection " + "listener -- did it crash?", e); } } mViConnectionListeners.finishBroadcast(); } } }