I am trying to check if USB Debugging is turned on or off through NPM/Node. As soon as an android phone is connected to my system and USB Debugging is turned off, then i need to show a prompt to user to enable usb debugging on his phone.
According to my research, every device (Scanner/Phones/USB) connected to my system has a unique GUID which helps me to distinguish which device is connected. Further, i'm not able to fetch the usb debugging details. Please help!
Code which i have written so far is on the basis of iSerialNumber but i want to distinguish it on the basis of BUS-TYPE GUID.
var usb = require('usb');
usb.on('attach', function(device) {
var devices = usb.getDeviceList();
var check = devices[0].deviceDescriptor;
if(check.iSerialNumber == '3')
{
console.log("Please enable USB Debugging");
}
else
{
console.log("Connect an Android device");
}
});
iSerialNumber is not actual Serial Number but it is just Index of Serial Number String Descriptor Stored in device. You can check further details about USB Device Descriptor on this link. GUID is not used by USB devices but may be used by OS itself as mentioned here. Serial Numbers are unique across every non-telephony Android devices as mentioned here so it is inadvisable to use Serial Number for flagging device as Android. The best way I found is to check against device vendor id and product id which are stored in device descriptor as idVendor and idProduct respectively. I found a list of vendor ids but did not find any list of product ids of each vendor.
Android device exposes several interfaces for different purposes like MTP, PTP, Mass Storage and USB Debugging etc. We want to find out the status of USB Debugging interface which has Interface Class 255, Interface Sub Class 66 and Interface Protocol 1. I found these numbers here.
Program first test if newly connected device is Android or not if it is Android then it checks for USB Debugging. I am not regular node.js user so my code is not good.
main.js
usb_vendor_ids.js