|
When otg cable is plugged in kernel says "USB connector connected" !
How to enable switch inside app when kernel says above message?
or to detect only OTG cable when plugged in or out using android app ? When otg cable is detected inside app should be enabled switch or disabled when otg cable is plugged out?
or to detect when Android enters Host Mode using app?
modified 24-Jan-17 9:50am.
|
|
|
|
|
Then it is not a simple cable but has built-in resistors or something connected at the other end.
If you got a kernel message, you should be able to get an event using udev rules. But this requires root privileges to save the rules file.
|
|
|
|
|
My phone is rooted!!!How to get event using udev?
|
|
|
|
|
Sorry that I mentioned udev. It is not used by Android.
|
|
|
|
|
Than how to do any of this:
When otg cable is plugged in kernel says "USB connector connected" !
How to enable switch inside app when kernel says above message?
or to detect only OTG cable when plugged in or out using android app ? When otg cable is detected inside app should be enabled switch or disabled when otg cable is plugged out?
or to detect when Android enters Host Mode using app?
|
|
|
|
|
By inspecting the Android sources to find which module is generating the message (if the message is not prefixed with the module name). Once the module is known check if it provides some kind of notification that can be used.
Or trying to use the provided Android APIs like android.hardware.usb | Android Developers[^].
Or polling the /dev directory for changes.
The host mode is entered when an USB device is attached. That can be detected as described in my initial answer (if supported).
If you did not get a final answer here or searching the web, you can try to do it yourself. This requires some research and implementing one or more of the above.
|
|
|
|
|
How to find modules that send messages inside kernel source?
|
|
|
|
|
I have searched all files and I didn't find kernel message for USB !!!!
I ran android terminal on my phone, typed cat /proc/kmsg and when plugged in otg cable I got msm_otg f9a55000.usb : host on
I found that message inside msm_otg kernel source:
static void msm_otg_start_host(struct usb_otg *otg, int on)
{
struct msm_otg *motg = container_of(otg->phy, struct msm_otg, phy);
struct msm_otg_platform_data *pdata = motg->pdata;
struct usb_hcd *hcd;
if (!otg->host)
return;
#ifdef CONFIG_USB_HOST_NOTIFY
msm_otg_host_notify(motg, on);
#endif
hcd = bus_to_hcd(otg->host);
if (on) {
dev_dbg(otg->phy->dev, "host on\n");
if (pdata->otg_control == OTG_PHY_CONTROL)
ulpi_write(otg->phy, OTG_COMP_DISABLE,
ULPI_SET(ULPI_PWR_CLK_MNG_REG));
if (pdata->setup_gpio)
pdata->setup_gpio(OTG_STATE_A_HOST);
usb_add_hcd(hcd, hcd->irq, IRQF_SHARED);
} else {
dev_dbg(otg->phy->dev, "host off\n");
usb_remove_hcd(hcd);
writel_relaxed(0x80000000, USB_PORTSC);
if (pdata->setup_gpio)
pdata->setup_gpio(OTG_STATE_UNDEFINED);
if (pdata->otg_control == OTG_PHY_CONTROL)
ulpi_write(otg->phy, OTG_COMP_DISABLE,
ULPI_CLR(ULPI_PWR_CLK_MNG_REG));
}
}
and do I need to create something like this: As code goes by: UEvents in Android - from kernel events to notifications[^]
|
|
|
|
|
The above code seems to be executed when activating and deactivating the host mode and calls the msm_otg_host_notify function when enabled by build configuration. So it might be useful to inspect this function.
But please understand that I don't have the time and interest to dig into this further (especially because it would also require to get the sources first).
I pointed you to directions that might help to solve the problem. But I'm not going to do the research for you.
|
|
|
|
|
Can this be helpful.It's from sec-switch.c file!
#ifdef CONFIG_USB_HOST_NOTIFY
} else if (usb_mode == USB_OTGHOST_DETACHED
|| usb_mode == USB_OTGHOST_ATTACHED) {
if (usb_mode == USB_OTGHOST_DETACHED) {
pr_info("USB Host detached");
sec_otg_notify(HNOTIFY_ID_PULL);
} else {
pr_info("USB Host attached");
sec_otg_notify(HNOTIFY_ID);
}
} else if (usb_mode == USB_POWERED_HOST_DETACHED
|| usb_mode == USB_POWERED_HOST_ATTACHED) {
if (usb_mode == USB_POWERED_HOST_DETACHED){
pr_info("USB Host HNOTIFY_SMARTDOCK_OFF");
sec_otg_notify(HNOTIFY_SMARTDOCK_OFF);
}else{
pr_info("USB Host HNOTIFY_SMARTDOCK_ON");
sec_otg_notify(HNOTIFY_SMARTDOCK_ON);
}
#endif
}
}
or this file sm5502.c :
#if defined(CONFIG_USB_HOST_NOTIFY)
if (adc == 0x11 || adc == ADC_AUDIO_DOCK) {
val2 = DEV_AUDIO_DOCK;
val1 = 0;
}
#endif
dev_err(&client->dev,
"dev1: 0x%x,dev2: 0x%x,dev3: 0x%x,Carkit: 0x%x,ADC: 0x%x,Jig: %s\n",
val1, val2, val3, val4, adc,
(check_sm5502_jig_state() ? "ON" : "OFF"));
if (val1 & DEV_USB || val2 & DEV_T2_USB_MASK ||
val4 & DEV_CARKIT_CHARGER1_MASK) {
pr_info("[MUIC] USB Connected\n");
pdata->callback(CABLE_TYPE_USB, SM5502_ATTACHED);
} else if (val1 & DEV_USB_CHG) {
pr_info("[MUIC] CDP Connected\n");
pdata->callback(CABLE_TYPE_CDP, SM5502_ATTACHED);
} else if (val1 & DEV_T1_UART_MASK || val2 & DEV_T2_UART_MASK) {
uart_sm5502_connecting = 1;
pr_info("[MUIC] UART Connected\n");
i2c_smbus_write_byte_data(client, REG_MANUAL_SW1, SW_UART);
if(vbus & DEV_VBUSIN_VALID)
pdata->callback(CABLE_TYPE_JIG_UART_OFF_VB, SM5502_ATTACHED);
else
pdata->callback(CABLE_TYPE_UARTOFF, SM5502_ATTACHED);
#if (!defined(CONFIG_MACH_CT01) && !defined(CONFIG_MACH_CT01_CHN_CU))
flash_control(true);
#endif
} else if ((val1 & DEV_T1_CHARGER_MASK) ||
(val3 & DEV_T3_CHARGER_MASK)) {
pr_info("[MUIC] Charger Connected\n");
pdata->callback(CABLE_TYPE_AC, SM5502_ATTACHED);
#if defined(CONFIG_USB_HOST_NOTIFY)
} else if (val1 & DEV_USB_OTG && adc == ADC_OTG) {
pr_info("[MUIC] OTG Connected\n");
#if defined(CONFIG_MUIC_SM5502_SUPPORT_LANHUB_TA)
sm5502_enable_rawdataInterrupts(usbsw);
usbsw->dock_attached = SM5502_ATTACHED;
usbsw->previous_dock = ADC_OTG;
#endif
sm5502_set_otg(usbsw, SM5502_ATTACHED);
pdata->callback(CABLE_TYPE_OTG, SM5502_ATTACHED);
#endif
} else if (val2 & DEV_T2_JIG_MASK) {
pr_info("[MUIC] JIG Connected\n");
pdata->callback(CABLE_TYPE_JIG, SM5502_ATTACHED);
#if (!defined(CONFIG_MACH_CT01) && !defined(CONFIG_MACH_CT01_CHN_CU))
flash_control(true);
#endif
} else if ((val2 & DEV_AV) || (val3 & DEV_AV_VBUS)) {
pr_info("[MUIC] Deskdock Connected\n");
local_usbsw->dock_attached = SM5502_ATTACHED;
if(vbus & DEV_VBUSIN_VALID)
sm5502_dock_control(usbsw, CABLE_TYPE_DESK_DOCK,
SM5502_ATTACHED, SW_AUDIO);
else
sm5502_dock_control(usbsw, CABLE_TYPE_DESK_DOCK_NO_VB,
SM5502_ATTACHED, SW_AUDIO);
#if defined(CONFIG_VIDEO_MHL_V2)
} else if (val3 & DEV_MHL) {
pr_info("[MUIC] MHL Connected\n");
sm5502_disable_interrupt();
if (!poweroff_charging)
else
pr_info("LPM mode, skip MHL sequence\n");
sm5502_enable_interrupt();
#endif
} else if (val2 & DEV_JIG_UART_ON) {
pr_info("[MUIC] Cardock Connected\n");
#if defined(CONFIG_SEC_FACTORY)
local_usbsw->dock_attached = SM5502_ATTACHED;
sm5502_dock_control(usbsw, CABLE_TYPE_CARDOCK,
SM5502_ATTACHED, SW_AUDIO);
#endif
} else if (val2 & DEV_SMARTDOCK) {
pr_info("[MUIC] Smartdock Connected\n");
sm5502_dock_control(usbsw, CABLE_TYPE_SMART_DOCK,
SM5502_ATTACHED, SW_DHOST);
#if defined(CONFIG_VIDEO_MHL_V2)
#endif
#if defined(CONFIG_USB_HOST_NOTIFY)
} else if (val2 & DEV_AUDIO_DOCK) {
pr_info("[MUIC] Audiodock Connected\n");
sm5502_dock_control(usbsw, CABLE_TYPE_AUDIO_DOCK,
SM5502_ATTACHED, SW_DHOST);
#endif
#if defined(CONFIG_MUIC_SM5502_SUPPORT_LANHUB_TA)
} else if (val2 & DEV_LANHUB) {
if(usbsw->previous_dock == ADC_LANHUB &&
usbsw->lanhub_ta_status == 1 )
pr_info("[MUIC] Lanhub + TA is connected\n");
else {
sm5502_enable_rawdataInterrupts(usbsw);
sm5502_detect_lanhub(usbsw);
}
#endif
} else if (vbus & DEV_VBUSIN_VALID) {
pr_info("[MUIC] Incompatible Charger Connected\n");
pdata->callback(CABLE_TYPE_INCOMPATIBLE,
SM5502_ATTACHED);
}
#if defined(CONFIG_TOUCHSCREEN_MMS144)
else{
tsp_noti_ignore = 1;
printk("[TSP] attached, but don't noti \n");
}
if(!tsp_noti_ignore)
tsp_charger_infom(1);
#endif
usbsw->dev1 = val1;
usbsw->dev2 = val2;
usbsw->dev3 = val3;
usbsw->adc = adc;
usbsw->vbus = vbus;
usbsw->carkit_dev = val4;
return adc;
}
static int sm5502_detach_dev(struct sm5502_usbsw *usbsw)
{
struct sm5502_platform_data *pdata = usbsw->pdata;
#if defined(CONFIG_TOUCHSCREEN_MMS144)
int tsp_noti_ignore = 0;
#endif
if (usbsw->dev1 & DEV_USB ||
usbsw->dev2 & DEV_T2_USB_MASK ||
usbsw->carkit_dev & DEV_CARKIT_CHARGER1_MASK) {
pr_info("[MUIC] USB Disonnected\n");
pdata->callback(CABLE_TYPE_USB, SM5502_DETACHED);
} else if (usbsw->dev1 & DEV_USB_CHG) {
pdata->callback(CABLE_TYPE_CDP, SM5502_DETACHED);
} else if (usbsw->dev1 & DEV_T1_UART_MASK ||
usbsw->dev2 & DEV_T2_UART_MASK) {
pr_info("[MUIC] UART Disonnected\n");
if(usbsw->vbus & DEV_VBUSIN_VALID)
pdata->callback(CABLE_TYPE_JIG_UART_OFF_VB, SM5502_DETACHED);
else
pdata->callback(CABLE_TYPE_UARTOFF, SM5502_DETACHED);
uart_sm5502_connecting = 0;
#if (defined(CONFIG_MACH_MS01_EUR_3G) || defined(CONFIG_MACH_MS01_CHN_CMCC_3G) || defined(CONFIG_MACH_MS01_CHN_CU_3G))
flash_control(false);
#endif
} else if ((usbsw->dev1 & DEV_T1_CHARGER_MASK) ||
(usbsw->dev3 & DEV_T3_CHARGER_MASK)) {
pr_info("[MUIC] Charger Disonnected\n");
pdata->callback(CABLE_TYPE_AC, SM5502_DETACHED);
#if defined(CONFIG_USB_HOST_NOTIFY)
} else if (usbsw->dev1 & DEV_USB_OTG) {
pr_info("[MUIC] OTG Disonnected\n");
#if defined(CONFIG_MUIC_SM5502_SUPPORT_LANHUB_TA)
sm5502_disable_rawdataInterrupts(usbsw);
pr_info("%s:lanhub_ta_status(%d)\n",
__func__, usbsw->lanhub_ta_status);
lanhub_ta_case = false;
if (usbsw->lanhub_ta_status == 0) {
pdata->callback(CABLE_TYPE_OTG,SM5502_DETACHED);
sm5502_set_otg(usbsw, SM5502_DETACHED);
}
else if (pdata->lanhub_cb && usbsw->lanhub_ta_status == 1)
pdata->lanhub_cb(CABLE_TYPE_LANHUB,SM5502_DETACHED, LANHUB);
usbsw->dock_attached = SM5502_DETACHED;
usbsw->lanhub_ta_status=0;
#else
sm5502_set_otg(usbsw, SM5502_DETACHED);
pdata->callback(CABLE_TYPE_OTG, SM5502_DETACHED);
#endif
#endif
} else if (usbsw->dev2 & DEV_T2_JIG_MASK) {
pr_info("[MUIC] JIG Disonnected\n");
pdata->callback(CABLE_TYPE_JIG, SM5502_DETACHED);
#if (defined(CONFIG_MACH_MS01_EUR_3G) || defined(CONFIG_MACH_MS01_CHN_CMCC_3G) || defined(CONFIG_MACH_MS01_CHN_CU_3G))
flash_control(false);
#endif
} else if ((usbsw->dev2 & DEV_AV) ||
(usbsw->dev3 & DEV_AV_VBUS)) {
pr_info("[MUIC] Deskdock Disonnected\n");
local_usbsw->dock_attached = SM5502_DETACHED;
if(usbsw->vbus & DEV_VBUSIN_VALID)
sm5502_dock_control(usbsw, CABLE_TYPE_DESK_DOCK,
SM5502_DETACHED, SW_ALL_OPEN);
else
sm5502_dock_control(usbsw, CABLE_TYPE_DESK_DOCK_NO_VB,
SM5502_DETACHED, SW_ALL_OPEN);
#if defined(CONFIG_MHL_D3_SUPPORT)
} else if (usbsw->dev3 & DEV_MHL) {
pr_info("[MUIC] MHL Disonnected\n");
detached_sm5502_status = 1;
#endif
} else if (usbsw->dev2 & DEV_JIG_UART_ON) {
pr_info("[MUIC] Cardock Disonnected\n");
#if defined(CONFIG_SEC_FACTORY)
local_usbsw->dock_attached = SM5502_DETACHED;
sm5502_dock_control(usbsw, CABLE_TYPE_CARDOCK,
SM5502_DETACHED, SW_ALL_OPEN);
#endif
} else if (usbsw->dev2 == DEV_SMARTDOCK) {
pr_info("[MUIC] Smartdock Disonnected\n");
sm5502_dock_control(usbsw, CABLE_TYPE_SMART_DOCK,
SM5502_DETACHED, SW_ALL_OPEN);
#if defined(CONFIG_VIDEO_MHL_V2)
#endif
#if defined(CONFIG_USB_HOST_NOTIFY)
} else if (usbsw->dev2 == DEV_AUDIO_DOCK) {
pr_info("[MUIC] Audiodock Disonnected\n");
sm5502_dock_control(usbsw, CABLE_TYPE_AUDIO_DOCK,
SM5502_DETACHED, SW_ALL_OPEN);
#endif
#if defined(CONFIG_MUIC_SM5502_SUPPORT_LANHUB_TA)
} else if (usbsw->adc == ADC_LANHUB) {
pr_info("[MUIC] Lanhub disconnected\n");
sm5502_disable_rawdataInterrupts(usbsw);
lanhub_ta_case = false;
usbsw->dock_attached = SM5502_DETACHED;
sm5502_set_lanhub(usbsw,SM5502_DETACHED);
sm5502_mask_vbus_detect(usbsw, SM5502_DETACHED);
pr_info("%s:lanhub_ta_status(%d)\n",__func__, usbsw->lanhub_ta_status);
if (pdata->lanhub_cb && usbsw->lanhub_ta_status==1)
pdata->lanhub_cb(CABLE_TYPE_LANHUB, SM5502_DETACHED, LANHUB);
else if (usbsw->lanhub_ta_status == 0) {
pdata->callback(CABLE_TYPE_OTG, SM5502_DETACHED);
sm5502_set_otg(usbsw, SM5502_DETACHED);
}
usbsw->lanhub_ta_status=0;
usbsw->dock_attached = SM5502_DETACHED;
#endif
} else if (usbsw->vbus & DEV_VBUSIN_VALID) {
pr_info("[MUIC] Incompatible Charger Disonnected\n");
pdata->callback(CABLE_TYPE_INCOMPATIBLE,
SM5502_DETACHED);
}
|
|
|
|
|
How to use app to detect when otg cable is plugged in and when it's plugged out? Is there intent for otg cable like this for usb devices: "android.hardware.usb.action.USB_DEVICE_ATTACHED"
I have created app like this but I only detects flash drive not otg cable:
public class MainActivity extends AppCompatActivity
{
private TextView mInfo;
private Logger mLogger;
private HashMap<UsbDevice, UsbDataBinder> mHashMap = new HashMap<UsbDevice, UsbDataBinder>();
private UsbManager mUsbManager;
private PendingIntent mPermissionIntent;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mInfo = (TextView)findViewById(R.id.log);
mLogger = new Logger(this);
mLogger.setMode(Logger.MODE_TOAST);
mUsbManager = (UsbManager) getSystemService(Context.USB_SERVICE);
usbConnection();
}
private void usbConnection() {
IntentFilter filter = new IntentFilter(UsbManager.ACTION_USB_DEVICE_ATTACHED);
registerReceiver(mUsbAttachReceiver , filter);
filter = new IntentFilter(UsbManager.ACTION_USB_DEVICE_DETACHED);
registerReceiver(mUsbDetachReceiver , filter);
mPermissionIntent = PendingIntent.getBroadcast(this, 0, new Intent(ACTION_USB_PERMISSION), 0);
filter = new IntentFilter(ACTION_USB_PERMISSION);
registerReceiver(mUsbReceiver, filter);
showDevices();
}
protected void onDestroy() {
super.onDestroy();
unregisterReceiver(mUsbDetachReceiver);
unregisterReceiver(mUsbAttachReceiver);
unregisterReceiver(mUsbReceiver);
};
BroadcastReceiver mUsbDetachReceiver = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (UsbManager.ACTION_USB_DEVICE_DETACHED.equals(action)) {
UsbDevice device = (UsbDevice)intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);
if (device != null) {
UsbDataBinder binder = mHashMap.get(device);
if (binder != null) {
binder.onDestroy();
mHashMap.remove(device);
Toast.makeText(MainActivity.this, "Attached!", Toast.LENGTH_SHORT).show();
}
}
}
}
};
BroadcastReceiver mUsbAttachReceiver = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (UsbManager.ACTION_USB_DEVICE_ATTACHED.equals(action)) {
showDevices();
Toast.makeText(MainActivity.this, "Detached!", Toast.LENGTH_SHORT).show();
}
}
};
private static final String ACTION_USB_PERMISSION = "com.android.example.USB_PERMISSION";
private final BroadcastReceiver mUsbReceiver = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (ACTION_USB_PERMISSION.equals(action)) {
synchronized (this) {
UsbDevice device = (UsbDevice) intent
.getParcelableExtra(UsbManager.EXTRA_DEVICE);
if (intent.getBooleanExtra(
UsbManager.EXTRA_PERMISSION_GRANTED, false)) {
if (device != null) {
UsbDataBinder binder = new UsbDataBinder(mUsbManager, device);
mHashMap.put(device, binder);
Toast.makeText(MainActivity.this, "Permission Granted!", Toast.LENGTH_SHORT).show();
}
} else {
}
}
}
}
};
private void showDevices() {
HashMap<String, UsbDevice> deviceList = mUsbManager.getDeviceList();
Iterator<UsbDevice> deviceIterator = deviceList.values().iterator();
while(deviceIterator.hasNext()){
UsbDevice device = deviceIterator.next();
mUsbManager.requestPermission(device, mPermissionIntent);
mLogger.log("usb", "name: " + device.getDeviceName() + ", " +
"ID: " + device.getDeviceId());
mInfo.append(device.getDeviceName() + "\n");
mInfo.append(device.getDeviceId() + "\n");
mInfo.append(device.getDeviceProtocol() + "\n");
mInfo.append(device.getProductId() + "\n");
mInfo.append(device.getVendorId() + "\n");
}
}
@Override
protected void onResume() {
super.onResume();
}
}
|
|
|
|
|
Have you tried creating a BroadcastReceiver and registering it with a ACTION_USB_DEVICE_ATTACHED filter?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
Yes I tried but it only work when I plug in otg cable with usb device attached to it and enable manually otg inside app and enter app that detects it.Without usb device on otg cable it won't detect it!!!I used ACTION_USB_DEVICE_ATTACED with this app: How to Monitor USB Events on Android[^]
|
|
|
|
|
How to find modules that send messages inside kernel source?
I have found file called host_notifier.c inside /drivers/usb/otg/ inside kernel source!
There is also file called Kconfig which contains this:
#
# USB Host notify configuration
#
config USB_HOST_NOTIFY
boolean "USB Host notify Driver"
depends on USB
help
Android framework needs uevents for usb host operation.
Host notify Driver serves uevent format
that is used by usb host or otg.
config USB_DEBUG_DETEAILED_LOG
boolean "USB detailed log for debugging"
depends on USB
help
Add detailed log for debugging.
modified 24-Jan-17 10:53am.
|
|
|
|
|
That is the kernel config file which defines what has to be compiled. If you have also a Makefile, you can check which sources are compiled when USB_HOST_NOTIFY is set.
But it already contains a hint: It uses uevent .
But again, these might only occur when a device is attached. To know when the cable message is generated, you have to find the message string in the sources.
|
|
|
|
|
I am searching inside /drivers/usb
Which of these folders could contain message:
atm
c67x00
class
core
dwc3
early
gadget
host
image
misc
mon
musb
otg
renesas_usbhs
serial
storage
wusbcore
|
|
|
|
|
Any of them, you need to do some searching.
|
|
|
|
|
I have searched all files and I didn't find kernel message for USB !!!!
|
|
|
|
|
I have searched all files and I didn't find kernel message for USB !!!!
|
|
|
|
|
I have searched all files and I didn't find kernel message for USB !!!!
I ran android terminal on my phone, typed cat /proc/kmsg and when plugged in otg cable I got msm_otg f9a55000.usb : host on
I found that message inside msm_otg kernel source:
static void msm_otg_start_host(struct usb_otg *otg, int on)
{
struct msm_otg *motg = container_of(otg->phy, struct msm_otg, phy);
struct msm_otg_platform_data *pdata = motg->pdata;
struct usb_hcd *hcd;
if (!otg->host)
return;
#ifdef CONFIG_USB_HOST_NOTIFY
msm_otg_host_notify(motg, on);
#endif
hcd = bus_to_hcd(otg->host);
if (on) {
dev_dbg(otg->phy->dev, "host on\n");
if (pdata->otg_control == OTG_PHY_CONTROL)
ulpi_write(otg->phy, OTG_COMP_DISABLE,
ULPI_SET(ULPI_PWR_CLK_MNG_REG));
if (pdata->setup_gpio)
pdata->setup_gpio(OTG_STATE_A_HOST);
usb_add_hcd(hcd, hcd->irq, IRQF_SHARED);
} else {
dev_dbg(otg->phy->dev, "host off\n");
usb_remove_hcd(hcd);
writel_relaxed(0x80000000, USB_PORTSC);
if (pdata->setup_gpio)
pdata->setup_gpio(OTG_STATE_UNDEFINED);
if (pdata->otg_control == OTG_PHY_CONTROL)
ulpi_write(otg->phy, OTG_COMP_DISABLE,
ULPI_CLR(ULPI_PWR_CLK_MNG_REG));
}
}
and do I need to create something like this: As code goes by: UEvents in Android - from kernel events to notifications[^]
modified 24-Jan-17 18:02pm.
|
|
|
|
|
Go to ParentHow to use app to detect when otg cable is plugged in and when it's plugged out? Is there intent for otg cable like this for usb devices: "android.hardware.usb.action.USB_DEVICE_ATTACHED"
I have created app like this but I only detects flash drive not otg cable:
public class MainActivity extends AppCompatActivity
{
private TextView mInfo;
private Logger mLogger;
private HashMap<UsbDevice, UsbDataBinder> mHashMap = new HashMap<UsbDevice, UsbDataBinder>();
private UsbManager mUsbManager;
private PendingIntent mPermissionIntent;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mInfo = (TextView)findViewById(R.id.log);
mLogger = new Logger(this);
mLogger.setMode(Logger.MODE_TOAST);
mUsbManager = (UsbManager) getSystemService(Context.USB_SERVICE);
usbConnection();
}
private void usbConnection() {
IntentFilter filter = new IntentFilter(UsbManager.ACTION_USB_DEVICE_ATTACHED);
registerReceiver(mUsbAttachReceiver , filter);
filter = new IntentFilter(UsbManager.ACTION_USB_DEVICE_DETACHED);
registerReceiver(mUsbDetachReceiver , filter);
mPermissionIntent = PendingIntent.getBroadcast(this, 0, new Intent(ACTION_USB_PERMISSION), 0);
filter = new IntentFilter(ACTION_USB_PERMISSION);
registerReceiver(mUsbReceiver, filter);
showDevices();
}
protected void onDestroy() {
super.onDestroy();
unregisterReceiver(mUsbDetachReceiver);
unregisterReceiver(mUsbAttachReceiver);
unregisterReceiver(mUsbReceiver);
};
BroadcastReceiver mUsbDetachReceiver = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (UsbManager.ACTION_USB_DEVICE_DETACHED.equals(action)) {
UsbDevice device = (UsbDevice)intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);
if (device != null) {
UsbDataBinder binder = mHashMap.get(device);
if (binder != null) {
binder.onDestroy();
mHashMap.remove(device);
Toast.makeText(MainActivity.this, "Attached!", Toast.LENGTH_SHORT).show();
}
}
}
}
};
BroadcastReceiver mUsbAttachReceiver = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (UsbManager.ACTION_USB_DEVICE_ATTACHED.equals(action)) {
showDevices();
Toast.makeText(MainActivity.this, "Detached!", Toast.LENGTH_SHORT).show();
}
}
};
private static final String ACTION_USB_PERMISSION = "com.android.example.USB_PERMISSION";
private final BroadcastReceiver mUsbReceiver = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (ACTION_USB_PERMISSION.equals(action)) {
synchronized (this) {
UsbDevice device = (UsbDevice) intent
.getParcelableExtra(UsbManager.EXTRA_DEVICE);
if (intent.getBooleanExtra(
UsbManager.EXTRA_PERMISSION_GRANTED, false)) {
if (device != null) {
UsbDataBinder binder = new UsbDataBinder(mUsbManager, device);
mHashMap.put(device, binder);
Toast.makeText(MainActivity.this, "Permission Granted!", Toast.LENGTH_SHORT).show();
}
} else {
}
}
}
}
};
private void showDevices() {
HashMap<String, UsbDevice> deviceList = mUsbManager.getDeviceList();
Iterator<UsbDevice> deviceIterator = deviceList.values().iterator();
while(deviceIterator.hasNext()){
UsbDevice device = deviceIterator.next();
mUsbManager.requestPermission(device, mPermissionIntent);
mLogger.log("usb", "name: " + device.getDeviceName() + ", " +
"ID: " + device.getDeviceId());
mInfo.append(device.getDeviceName() + "\n");
mInfo.append(device.getDeviceId() + "\n");
mInfo.append(device.getDeviceProtocol() + "\n");
mInfo.append(device.getProductId() + "\n");
mInfo.append(device.getVendorId() + "\n");
}
}
@Override
protected void onResume() {
super.onResume();
}
}
|
|
|
|
|
i need a remote android source code for make a project. i want to view my frnds android phn using my phne and i need to contol his phn. its my android project like remodroid. but i can't make such like app in android eclips. pllz help me to create such lyk app.. please provide the souce code for it
|
|
|
|
|
|
Samsung has disabled OTG support on my S3 Neo I9301I and I have program that enables it.When I plug in otg cable inside phone and open app and enable switch,app writes "1" inside /sys/kernel/debug/regulator/8226_smbbp_otg/enable/ file and writes "0" inside it when I disable switch!When "1" otg is enabled,when "0" otg is disabled!
How to make that app automatically enables switch to write "1" when I plug in cable without going inside app and manually turning on switch?
|
|
|
|
|
This sounds like illegal hacking and we do not condone it, let alone help you to do it.
|
|
|
|
|