package com.DeviceTest;
|
import java.io.File;
|
|
import com.DeviceTest.helper.ControlButtonUtil;
|
import com.DeviceTest.helper.SystemInfoUtil;
|
|
import android.app.Activity;
|
import android.content.Context;
|
import android.content.DialogInterface;
|
import android.os.Bundle;
|
import android.os.Environment;
|
import android.os.Handler;
|
import android.os.Message;
|
import android.os.StatFs;
|
import android.os.storage.StorageManager;
|
import android.os.storage.StorageVolume;
|
import android.os.SystemProperties;
|
import android.os.storage.StorageEventListener;
|
import android.text.format.Formatter;
|
import android.util.Log;
|
import android.widget.Button;
|
import android.widget.TextView;
|
import android.view.KeyEvent;
|
import android.view.View;
|
import android.hardware.input.InputManager;
|
import android.view.MotionEvent;
|
import android.view.InputDevice;
|
import java.io.File;
|
import android.content.ComponentName;
|
import com.DeviceTest.helper.ControlButtonUtil;
|
import com.DeviceTest.helper.SystemInfoUtil;
|
import android.os.Build;
|
import android.app.Activity;
|
import android.content.Context;
|
import android.content.DialogInterface;
|
import android.os.Bundle;
|
import android.os.Environment;
|
import android.os.Handler;
|
import android.os.Message;
|
import android.os.StatFs;
|
import android.os.storage.StorageManager;
|
import android.os.storage.StorageVolume;
|
import android.os.SystemProperties;
|
import android.os.storage.StorageEventListener;
|
import android.text.format.Formatter;
|
import android.util.Log;
|
import android.widget.Button;
|
import android.widget.TextView;
|
import android.hardware.usb.UsbDevice;
|
import android.hardware.usb.UsbManager;
|
import java.util.Iterator;
|
import java.util.HashMap;
|
import android.content.Intent;
|
import android.content.pm.PackageManager;
|
import android.widget.Toast;
|
|
public class USBDeviceTestActivity extends Activity {
|
private final static String TAG = "USBDeviceTestActivity";
|
private final static int MSG_OK=0;
|
|
// 创建定时器循环
|
public Handler USBhandler;
|
|
public void onCreate(Bundle paramBundle) {
|
super.onCreate(paramBundle);
|
setContentView(R.layout.usbdevicetest);
|
|
System.out.println("rpdzkj usb test");
|
|
// 创建定时器循环
|
USBhandler=new Handler();
|
USBhandler.postDelayed(runnable, 500);
|
|
|
ControlButtonUtil.initControlButtonView(this);
|
// 自动通过测试
|
//handler.sendEmptyMessageDelayed(MSG_OK, 2500);
|
}
|
|
private Handler handler=new Handler(){
|
@Override
|
public void handleMessage(Message msg) {
|
switch(msg.what){
|
case MSG_OK:
|
((Button) findViewById(R.id.btn_Pass)).performClick();
|
}
|
}
|
};
|
|
// 定时器循环代码
|
Runnable runnable=new Runnable(){
|
public void run() {
|
TextView usbHostView = (TextView) findViewById(R.id.USBNum);
|
usbHostView.setText("USB设备数量 : " + USBhostDeviceCheck());
|
USBhandler.postDelayed(this, 1000);// 每1000毫秒循环一次
|
}
|
};
|
|
|
// 获取当前USB设备数量
|
public int USBhostDeviceCheck(){
|
int usbNum = 0;
|
UsbManager usbManager = (UsbManager) getSystemService(Context.USB_SERVICE);
|
HashMap<String, UsbDevice> devs;
|
devs = usbManager.getDeviceList();
|
StringBuilder sb = new StringBuilder();
|
if(!devs.isEmpty()){
|
Iterator<UsbDevice> usbs = devs.values().iterator();
|
while(usbs.hasNext()){
|
UsbDevice dev = usbs.next();
|
int vid = dev.getVendorId();
|
int pid = dev.getProductId();
|
if (vid == 1507 && pid == 1544) {
|
// skip usb hub gl850g
|
} else if (vid == 3034 && pid == 46880) {
|
// skip usb wifi rtl
|
} else if (vid == 4292 && pid == 60000) {
|
// skip usb wifi rtl
|
} else if (vid == 11388 && pid == 293) {
|
// skip EC20
|
} else if (vid == 11388 && pid == 24578) {
|
// skip EC200s
|
} else if (vid == 0x2c7c && pid == 0x0801) {
|
// RM520N
|
} else if (vid == 0x2c7c && pid == 0x0800) {
|
// RM500Q
|
} else if (vid == 0x2c7c && pid == 0x0900) {
|
// RM500U
|
} else {
|
usbNum++;
|
}
|
String name = dev.getDeviceName();
|
sb.append("-----------------------------------"+"\n");
|
sb.append("vid = "+Integer.toHexString(vid)+ " ,pid = "+ Integer.toHexString(pid) + "\n");
|
sb.append("name = "+name+"\n");
|
android.util.Log.d("RRRRRRRR", sb.toString());
|
}
|
}
|
|
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.O_MR1) return usbNum;
|
|
InputManager inputManager = (InputManager) getSystemService(Context.INPUT_SERVICE);
|
int[] deviceIds = inputManager.getInputDeviceIds();
|
for (int deviceId : deviceIds) {
|
InputDevice device = inputManager.getInputDevice(deviceId);
|
if (device != null) {
|
int srcid = device.getSources();
|
if ((srcid & InputDevice.SOURCE_MOUSE) == InputDevice.SOURCE_MOUSE) {
|
usbNum ++;
|
}
|
}
|
}
|
|
|
return usbNum;
|
}
|
|
public void onGoOtgModeSetBtnClick(View view) {
|
goOTGModeSetting();
|
}
|
|
public void goOTGModeSetting() {
|
Intent intent = new Intent();
|
intent.setComponent(new ComponentName("com.android.settings", "com.android.settings.Settings$UsbHostDeviceSettingsActivity"));
|
if (intent.resolveActivityInfo(getPackageManager(), PackageManager.MATCH_DEFAULT_ONLY) != null) {
|
startActivity(intent);
|
}
|
}
|
|
@Override
|
protected void onResume() {
|
super.onResume();
|
}
|
|
public void onCancel(DialogInterface dialog) {
|
finish();
|
}
|
|
public boolean dispatchKeyEvent(KeyEvent event) {
|
if (event.getKeyCode() == KeyEvent.KEYCODE_BACK) {
|
return false;
|
}
|
return super.dispatchKeyEvent(event);
|
}
|
|
}
|