整理记录在Android系统的一些功能设置,主要是中上层的实现。

系统设置功能

控制焦点移动

// 直接指定上下左右移动的View
view.setId(...);
view.setNextLeftView(...)
...

// 手动控制焦点变化
public void OnKeyDown(int keyCode, KeyEvent event){
    if( event.KEYCODE_DROP_UP== keyCode ){
            view.requestFocus();
    }
    ...
}

USB设备类型

  • USB类型定义
include/uapi/linux/usb/ch9.h

/* 
 * Device and/or Interface Class codes 
 * as found in bDeviceClass or bInterfaceClass 
 * and defined by www.usb.org documents 
 */  
#define USB_CLASS_PER_INTERFACE     0   /* for DeviceClass */  
#define USB_CLASS_AUDIO         1  
#define USB_CLASS_COMM          2  
#define USB_CLASS_HID           3  
#define USB_CLASS_PHYSICAL      5  
#define USB_CLASS_STILL_IMAGE       6  
#define USB_CLASS_PRINTER       7  
#define USB_CLASS_MASS_STORAGE      8  
#define USB_CLASS_HUB           9  
#define USB_CLASS_CDC_DATA      0x0a  
#define USB_CLASS_CSCID         0x0b    /* chip+ smart card */  
#define USB_CLASS_CONTENT_SEC       0x0d    /* content security */  
#define USB_CLASS_VIDEO         0x0e  
#define USB_CLASS_WIRELESS_CONTROLLER   0xe0  
#define USB_CLASS_MISC          0xef  
#define USB_CLASS_APP_SPEC      0xfe  
#define USB_CLASS_VENDOR_SPEC       0xff  
  • 应用层检测
UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE);
HashMap<String, UsbDevice> deviceList = manager.getDeviceList();
Iterator<UsbDevice> deviceIterator = deviceList.values().iterator();
StringBuilder sb = new StringBuilder();
while (deviceIterator.hasNext()){
    UsbDevice usbDevice = deviceIterator.next();
    sb.append("DeviceName="+usbDevice.getDeviceName()+"\n");
    sb.append("DeviceId="+usbDevice.getDeviceId()+"\n");
    sb.append("VendorId="+usbDevice.getVendorId()+"\n");
    sb.append("ProductId="+usbDevice.getProductId()+"\n");
    sb.append("DeviceClass="+usbDevice.getDeviceClass()+"\n");
    int deviceClass = usbDevice.getDeviceClass();
    if(deviceClass==0) {
        UsbInterface anInterface = usbDevice.getInterface(0);
        int interfaceClass = anInterface.getInterfaceClass();
        sb.append("device Class is 0-------------\n");  
        sb.append("Interface.describeContents()="+anInterface.describeContents()+"\n");
        sb.append("Interface.getEndpointCount()="+anInterface.getEndpointCount()+"\n");
        sb.append("Interface.getId()="+anInterface.getId()+"\n");
        sb.append("Interface.getInterfaceClass()="+anInterface.getInterfaceClass()+"\n");
        sb.append("anInterface.getInterfaceProtocol()="+anInterface.getInterfaceProtocol()+"\n");
        sb.append("anInterface.getInterfaceSubclass()="+anInterface.getInterfaceSubclass()+"\n");
        sb.append("device Class is 0------end-------\n");
    }

    sb.append("DeviceProtocol="+usbDevice.getDeviceProtocol()+"\n");
    sb.append("DeviceSubclass="+usbDevice.getDeviceSubclass()+"\n");
    sb.append("+++++++++++++++++++++++++++\n");
    sb.append("                           \n");
}

HDMI连接状态

// 广播监听
// 但是当程序初启,无法知道当前插入状态
if (action.equals("android.intent.action.HDMI_PLUGGED")) {
    boolean hdmiConnected = receivedIt.getBooleanExtra("state", false);
}

// 系统配置
// 但是频繁查询,会出现读取异常
// path: /sys/devices/virtual/switch/hdmi/state

参考