Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 package org.ros.android.android_acm_serial;
00018
00019 import android.content.BroadcastReceiver;
00020 import android.content.Context;
00021 import android.content.Intent;
00022 import android.hardware.usb.UsbDevice;
00023 import android.hardware.usb.UsbManager;
00024 import org.apache.commons.logging.Log;
00025 import org.apache.commons.logging.LogFactory;
00026 import org.ros.exception.RosRuntimeException;
00027
00028 import java.util.Map;
00029
00033 final class UsbDeviceDetachedReceiver extends BroadcastReceiver {
00034
00035 private static final boolean DEBUG = true;
00036 private static final Log log = LogFactory.getLog(UsbDeviceDetachedReceiver.class);
00037
00038 private final Map<String, AcmDevice> acmDevices;
00039
00040 public UsbDeviceDetachedReceiver(Map<String, AcmDevice> acmDevices) {
00041 this.acmDevices = acmDevices;
00042 }
00043
00044 @Override
00045 public void onReceive(Context context, Intent intent) {
00046 UsbDevice usbDevice = (UsbDevice) intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);
00047 String deviceName = usbDevice.getDeviceName();
00048 AcmDevice acmDevice = acmDevices.remove(deviceName);
00049 if (acmDevice != null) {
00050 try {
00051 acmDevice.close();
00052 } catch (RosRuntimeException e) {
00053
00054 }
00055 }
00056 if (DEBUG) {
00057 log.info("USB device removed: " + deviceName);
00058 }
00059 }
00060 }