yashsingh1/xdaforums huggingface dataset:
[Nexus 4 Original Android Development] ziddey:
2013.05.23 2119ET: ziddey-otg-05232119.zip Start charging immediately when entering host mode. This resolves issues with proprietary chargers.

I hacked up a cable to provide raw voltage on the data pins (kind of simulate a proprietary charger). I had been assuming that the usb host will retry forever. Turns out it goes through 3 sets of 32 before giving up and suspending the host. That's acceptable in my opinion, so I changed the code to start charging right when it enters host mode. The original code blocks charging until after enumeration. The idea is that if the phone draws too much current, the usb devices may starve. This is obviously dependent on the power source, but considering the devices we're using, this hopefully won't be a problem. Besides, there was already a 500mA limit in host mode anyway which I had long overridden.
[Nexus 4 Original Android Development] sga999:
Works perfectly with both of my power banks! I like this better than the echo command. Thanks very much.
[Nexus 4 Original Android Development] sga999:
ziddey, I don't know if this is interesting to you, but I looked at dmesg for one of the power banks right when it was plugged in. There are 16 (not 3) of those sequences of 32 errors over a 3 second period. Obviously, I'd never know about it if I didn't look at the log.

EDIT: Same exact thing for the 2nd power bank.
[Nexus 4 Original Android Development] wangtang:
anyone can connect computer?

i can't connect with computer. i am using cm10.1 nightly build

when i connect computer, nexus 4 pop up message that " unfortunatly, android.media.process has stop".

even i tried with stock, aokp, paranoid, EOS, etc... also i clean up(format) nexus4 memory and flash stock rom image.

of course, otg funtion and external battery charging works well.

here is my dmesg file.

anyway, thank you ziddey
[Nexus 4 Original Android Development] sga999:
You're right....I had not tried that. Connecting to laptop does not seem to work.

EDIT: Sorry! False alarm, connecting to laptop is fine.
[Nexus 4 Original Android Development] wangtang:
i read ID:Russian Bear have same problem with me.

i tried March and April kernel have no problem with connecting computer. also otg funtion works well.

just recently kernel (external battery charging function) has problem.

i tried with my desktop and laptop also my office computer and my bro's computer.
[Nexus 4 Original Android Development] sga999:
It's working for me with stock 4.2.2. I think RussianBear was running AOKP?
[Nexus 4 Original Android Development] tyea:
Is it possible to flash, via custom recovery, the factory USB firmware, because I can no longer connect to a PC via USB?

I get a USB device not recognized on two PCs that I used to be able to use adb, fastboot, and MTP file transfers on. I also can only charge at USB rate on chargers that used to charge at ac rate.

LG-E960
[Nexus 4 Original Android Development] ziddey:
That log from start to finish only shows your usb disk activity.

Which nightly are you on? I've been updating every few nightlies (using Cyandelta/TWRP) and haven't run into this issue. I just tested hooking up a usb drive first, and changing the language. Works fine over here (current 5/23 nightly).

If you revert the framework to the backup, does it work (it did for RussianBear)?

# cp /system/framework/framework-res.apk.1 /system/framework/framework-res.apk

Issue the command in recovery through adb (will need to mount /system).

I'm going to take another look at my approach to the framework mods.
[Nexus 4 Original Android Development] ziddey:
Are you using the same usb cable? If so, it might be defective. Which version of the mod are you using?

Fastboot will absolutely not be affected.
[Nexus 4 Original Android Development] wangtang:
thanks ziddey! now it works!

i did your code and than i can connecting computer, otg function(usb memory, mouse) external battery charging well.

but i can't see "usb storage" and "remove usb storage" in storage system menu and prepare usb storage or remove usb storage on notification.

i am satisfied. thanks again ziddey! i gonna diy otg y cable :)
[Nexus 4 Original Android Development] RussianBear:
Lol that's the trade-off, man. That framework apk adds the usb storage options.
[Nexus 4 Original Android Development] thebrainkafka:
Can you pls explain how to do this cable mod to get host mode working without power supply?

Thx

---------- Post added at 04:06 PM ---------- Previous post was at 04:04 PM ----------

Really looking forward to this host mode enabling!

Please keep me in the loop.

Thx
[Nexus 4 Original Android Development] sga999:
Either RussianBear or Wangtang, I wonder if you can put your "good" and "bad" framework-res.apk files on a server for me. I really doubt it, but I'd like to see if it somehow got patched incorrectly. Thanks.
[Nexus 4 Original Android Development] RussianBear:
Don't have the "bad" one anymore, but here's the one that works: http://db.tt/qj9cojhp
[Nexus 4 Original Android Development] ziddey:
Oh wow. I just noticed a huge discrepancy depending on which shell (sh vs bash) is used. Which recovery are you using / what version?

Thanks for uploading.

edit: I know it's a pain in the ass but if you wouldn't mind, could you run the patch again and post the broken framework-res.apk or extract it and post just res/xml/storage_list.xml? I noticed it doesn't work properly with sh in ubuntu, but does with bash. Works fine with sh in twrp 2.5.0.0. Maybe I need to include my own busybox (sh) if that's the issue.

edit2: With the "bad" framework, did it show "USB STORAGE" or was it something else? If it did show properly, I'm probably barking up the wrong tree.

edit3: Disregard above. I tested a bad storage_list.xml and somehow trashed my phone. Either that's not it or it's a TERRIBLE idea to mod framework-res.apk while Android is running :p
[Nexus 4 Original Android Development] RussianBear:
i could post it, if you wanted it still :) i *think* it still showed usb storage in setting, but had no detection of mtp in windows (except for mount/unmount sounds).
[Nexus 4 Original Android Development] ziddey:
I'm guessing the file was patched "properly" but there's something I'm overlooking. Right now I'm trying to figure out how to fix my phone lmao
[Nexus 4 Original Android Development] RussianBear:
Can you get it into download mode? I take it, it's not booting into recovery or bootloader.
[Nexus 4 Original Android Development] ziddey:
Nah, nothing that serious. It trashed something in /data/system. I'm trying to figure out what it is instead of just wiping it. Guess I'll go back and edit my previous post to say not to mod the framework while Android is running :p
[Nexus 4 Original Android Development] sga999:
RussianBear, "just for fun", I'd love to see the "bad" framework, if it's not too much trouble. I may even want to install the rom you're running, just so I can see this myself. This kind of problem really bugs me, so I'd love to help ziddey get to the bottom of it. Exactly what rom/version are you on so I can be sure I'll be identical? Thanks a lot.
[Nexus 4 Original Android Development] RussianBear:
It's aokp 5/24 Nightly. I'll post it here in a bit.
[Nexus 4 Original Android Development] ziddey:
The thing is wangtang had the same issue and he said he's on cm nightlies, which I've been using since day 1. That's why I was originally leaning on the recovery. What recovery are you using?

edit: heh, completely trashed my /data mucking around with it. Going to give PA a quick whirl
[Nexus 4 Original Android Development] sga999:
Thanks, RussianBear. Did this patching of framework work for "a while" and then go bad? Sorry, I should look back and see what you said, but I'll be lazy. It seems like you mentioned this problem about a week ago. Was there anything "new"? As ziddey is questioning, is it a different recovery or another version of the same recovery that you had been using when it worked?
[Nexus 4 Original Android Development] RussianBear:
Nah, just never had any need to hook it up to my pc before. Here's the "bad" one: http://db.tt/79YvBRQS

I'm on cwm. One of the older ones.
[Nexus 4 Original Android Development] ziddey:
orig:

$ hexdump -C storage_list.xml | grep "08 00 00 01"
00000140 ff ff ff ff 08 00 00 01 [color=red]f9 04[/color] 04 01 04 00 00 00 |................|

mod:

$ hexdump -C storage_list.xml | grep "08 00 00 01"
00000190 00 00 00 00 ff ff ff ff 08 00 00 01 [color=red]5c 78[/color] 04 01 |............\x..|
00000220 ff ff ff ff 08 00 00 01 [color=red]02 00[/color] 04 01 07 00 00 00 |................|

Well that sure is broken. Will have to check but I'm assuming I'll have to include a compatible version of busybox (for sh), since it looks like the output of printf "\x____" isn't working as expected.

The 5c 78 should be f9 04, and the 02 00 should be fb 04.

Good to know it's not something else. This should be easily fixable. Let me get my phone running so I can flash CWM and do some testing.
[Nexus 4 Original Android Development] sga999:
ziddey, I was just ready to post saying that I saw the same bad values! Good. Does RussianBear have some older version of Busybox? I just issued the busybox command in adb, and it says 1.21.0.git.
[Nexus 4 Original Android Development] RussianBear:
I probably did.just updated to the same version as yours.
[Nexus 4 Original Android Development] sga999:
Okay, RussianBear, I'm curious to know whether your mtp problem goes away now. Try ziddey's latest .zip and your new busybox and see what happens!
[Nexus 4 Original Android Development] RussianBear:
You guys killing me lol I'll try it in a few hours.
[Nexus 4 Original Android Development] sga999:
No hurry, RussianBear! Thanks for posting your "bad" file so that we could see the wrong values.

---------- Post added at 04:10 PM ---------- Previous post was at 03:43 PM ----------

Wangtang, when you get a chance, can you update your Busybox and see if your problem is fixed also? See the last few posts for what has been learned by looking at RussianBear's "bad" framework.
[Nexus 4 Original Android Development] RussianBear:
Negative. See another "bad" one here: http://db.tt/dX818w6n
[Nexus 4 Original Android Development] ziddey:
Same as the last one. You said you updated to TWRP 2.5.0.0?

a ha:

busybox (same results as bash):

$ busybox printf "\x12\x04" | od -t x1
0000000 12 04
0000002

sh:

$ printf "\xf9\x04" | od -t x1
0000000 5c 78 66 39 5c 78 30 34
0000010

That doesn't explain the 02 00 (since 5c 78 is simply the hex values for \x), but I'm sure it's related. Maybe something caught in the buffer?

Anyway, since the script uses /sbin/sh, that might be independent and not symlinked to busybox. It looks like busybox's printf does fine. Adding busybox in front of printf in the script should fix it.
[Nexus 4 Original Android Development] sga999:
It looks just like the last bad one. ziddey mentioned something about bash vs. sh scripts. I don't know anything about what the differences are...I'm not that familiar with these scripts, but I can plod my way through them.

So if you issue busybox (either in terminal emulator or adb), does it now say 1.21.0.git? If so, I guess busybox is not the issue because this version is working for me, so it should be working for you also. It must be something to do with these scripts running differently in your recovery...or some other variable that I don't know about. ziddey, maybe you have more ideas

EDIT: Sorry, ziddey, I was posting at the same time as you

---------- Post added at 06:08 PM ---------- Previous post was at 06:05 PM ----------

EDIT2: By the way, I don't see how either INTERNAL STORAGE or USB STORAGE could be displaying correctly with these bad values.
[Nexus 4 Original Android Development] RussianBear:
Nope, still on cwm. I guess, I could update, but I'm a little on the lazy side tonight :)
[Nexus 4 Original Android Development] ziddey:
Nah, stay on CWM.

I got a few minutes to kill before I have to head out. I'll switch to CWM and do some testing. Will let you know.

edit: hmm. So I am able to reproduce it on CWM 6.0.3.1. However, dinking around in recovery (adb shell), everything seems fine. Will have to take a look tomorrow. But I guess the answer for now is TWRP.
[Nexus 4 Original Android Development] wangtang:
twrp works well

hello! i was busy

here is my bad? framework-res.apk and here is after did ziddey's code.

i am using cm10.1 nightly build 23,24/05 version and cwm.

today, flashed twrp 2.5.0 recovery and than everything woking perfectly!

otg function, external battery charging, connecting computer also system menu show usb storage, unmount storage, prepare usb storage on notification etc... everything working perfect.

oh! my time (flash roms, stock kernel and clean up all of memories ....) why i never think about recovery....

anyway, thanks everyone! i hope this kernel can flash on cwm recovery soon! :good:
[Nexus 4 Original Android Development] RussianBear:
Yup, works on twrp :)
[Nexus 4 Original Android Development] sga999:
wangtang, your "bad" one is the same as RussianBear's. This seems to be a problem with CWM, not with TWRP, as you have also seen after trying TWRP. Don't feel bad! I don't think you should have thought about CWM recovery being the problem. That doesn't make much sense to me at all! But I must admit that I don't know enough about recovery or scripts within recovery to have any insight into this.

As far as the "after did ziddey's code" framework that you put out there, it doesn't seem to have a usbdisk part at all, so I'm confused about what that is. It doesn't really matter much, but if you want to, you could put the one that is now working out on a server. Maybe that's what you were trying to do, but it just doesn't look right to me. I could be crazy though!

ziddey, this problem occurs with CWM 6.0.3.1 for me while running stock 4.2.2 (and your latest .zip file). I've been using TWRP for quite a while, so I had not seen this. I wonder why all of those who have been using CWM haven't seen it. Maybe they aren't trying mtp...or maybe the resulting problem isn't always the same. Ah, in fact, you're one of those, right?

Like you said, just issuing these printf's within adb shell during CWM does not seem to fail. So I'm at a loss as to what's causing this....and I don't know enough about sh or bash, though maybe you're ruling that out by now? Maybe going back to doing the printf one byte at a time would work? I'd try that, but if I change your script and try to create an update.zip file, it doesn't seem to be good, so I guess I'll just wait for you.

EDIT: Oh!!!! It seems to be using Busybox 1.21.0-jb, and I'm getting errors on that first 'internal=$(od -x....' line. The error is 'unknown option -- 1'. That makes everything else after it go bad. So I think the printf's with 2 bytes are still fine....it's just some part of that long line with all the pipes. That busybox is newer (2/26/2013) than the one I'm using.

EDIT2: That busybox isn't liking the 'head -1' part of that long line. 'head -n 1' seems to work for both versions of busybox. In an earlier post, you said you probably didn't need that at all because there would only be one occurrence. So I guess you could either omit it or change it to 'head -n 1'. It does seem to work, but since I don't know much about 'head', you should make sure that's what you want.

Just so everyone knows what all that means! ziddey will be able to make a minor change to his script, and CWM and TWRP will work fine, i.e. no more mtp problems will occur after his patch. I don't know what other recoveries people may use and what busybox those recoveries may use, but maybe this 'head -n 1' will work for all of them.
[Nexus 4 Original Android Development] ritchea:
Aaahh. Forgot to mention that when I mentioned my rom: TWRP 2.5--and all was/is working correctly.
[Nexus 4 Original Android Development] ziddey:
2013.05.25 0749ET: ziddey-otg-05250749.zip Fix compatibility issue with CWM (MTP crashes).

Thanks sga999. Nice to come home and see the problem's already been identified :).

Absolutely no reason to flash this if using TWRP. For CWM users, this fixes MTP.
[Nexus 4 Original Android Development] eran1243:
Any news regarding the not discovered DSLRs (also when using manual OTG)?

Keep up the great work!
[Nexus 4 Original Android Development] ziddey:
I've been trying to manually set the portsc register to support self-powered devices but haven't had any luck so far.

Franco's r143 has some nice updates so I'll make a new build tomorrow.
[Nexus 4 Original Android Development] drshafi:
I'm on xenon hd rom with franco kernel, can i flash this patch to enable Usb Otg?
[Nexus 4 Original Android Development] ziddey:
2013.05.28 2243ET: ziddey-otg-05282243.zip Maintenance build-- update sources to Franco r143.
[Nexus 4 Original Android Development] StyleUkno:
has a way to connect an Xbox 360 controller been discovered?
[Nexus 4 Original Android Development] wangtang:
thanks ziddey! works well even on cwm!
[Nexus 4 Original Android Development] ziddey:
http://xdaforums.com/showpost.php?p=41125238&postcount=285

I haven't been keeping track of whether the modules still work (compiled for r134..). If not, I may end up making a script to automate everything on my end (kernel, ramdisk, update.zip, modules, etc).
[Nexus 4 Original Android Development] StyleUkno:
I wasnt able to install that .zip file via twrp
[Nexus 4 Original Android Development] ziddey:
Zip simply includes the modules. Refer to http://xdaforums.com/showthread.php?t=1584850
[Nexus 4 Original Android Development] thebrainkafka:
Dont give up..... There must be a way
[Nexus 4 Original Android Development] prateek80:
Can anyone please explain if the slimport on nexus 4 can supply enough voltage to power up an hdmi adaptor....

then why it can not supply same voltage to USB devices????
[Nexus 4 Original Android Development] freddysam:
http://www.anandtech.com/show/6499/...ix-slimport-microusb-to-hdmi-and-vga-adapters

It must get its power from the HDMI side, right?
[Nexus 4 Original Android Development] prateek80:
So that means it can never be done without providing the external power???

---------- Post added 31st May 2013 at 12:03 AM ---------- Previous post was 30th May 2013 at 11:41 PM ----------

So that means it can never be done without providing the external power???
[Nexus 4 Original Android Development] info.brandenburg:
The phone provides the power not the TV or Display.

But not the necessary 5v for usbOTG.
[Nexus 4 Original Android Development] thebrainkafka:
Couldnt this be brigded/hacked?
[Nexus 4 Original Android Development] sszz:
Does someone know what current the phone can output for slimport / whatever? Even if the output voltage is lower than the required 5V if there is sufficient current a boost converter could potentially solve this issue.
[Nexus 4 Original Android Development] Monolithus:
Hmm.. it seems that I'm neewbie or I can't read. I have PA3+ + newest Franco kernel. I downloaded and patched zip in this topic... and nothing. Any pendrive are not visible for N4, keyboard or mouse neither.
[Nexus 4 Original Android Development] cantevencode:
Are you using an otg y cable with external power?
[Nexus 4 Original Android Development] prateek80:
okey.. i do not have so much knowledge about this stuff but..

here http://www.analogix.com/products/7808.html on the power requirements it says

1.0V, 1.8V and 3.3V power supplies...

does this means the slimport on nexus 4 can not supply more than 3.3 v or its just the power it requires to work...???
[Nexus 4 Original Android Development] sszz:
I would say it's just the requirements...
[Nexus 4 Original Android Development] davebuk:
Ziddey has done some work on this. See: http://xdaforums.com/showpost.php?p=40203602&postcount=213

A converter can be made to go from 3.3 to 5VDC but I don't think there is enough current available. I think the min requirements for USB is something like 5VDC @ 100mA. If the slimport can only output 40mA at 3.3VDC the loss to up convert the voltage would reduce this further.

Why LG/Google can't make a battery powered OTG adapter I don't know. I would be more than happy with a sleeve/battery pack with a USB host port. In fact I have all the bits to make my own at some point. :)
[Nexus 4 Original Android Development] sam razzy:
Is this works perfectly normal ?
[Nexus 4 Original Android Development] RussianBear:
Nope, broken beyond repair.
[Nexus 4 Original Android Development] ziddey:
How do you have 2,367 posts?
[Nexus 4 Original Android Development] sam razzy:
Sorry for been just like a noob, reading whole thread will make me an insane. But almost read 25% of this thread, but got some complicated review about this thread. As you can see some comment as this works and some says it doesn't or as some bugs to be cleaned up.. So i just got my new nexus four in my hand yesterday with stock build, rooted unlocked and flashed franco kernel. Before i was a nexus user, Gnex. But after been onto new device,First week i don wanna mess up. Thats the reason i throw question just like a spoon feeded kid... Sorry Guyz
[Nexus 4 Original Android Development] Monolithus:
Nope, it's a Micro-B type. So thats the problem? In Xperia Sola that cable works perfectly with any kind of stuff (pendrive, mouse, keyboard, even x360 controller ;P)
[Nexus 4 Original Android Development] cantevencode:
You need external power. The port can't provide enough power for USB devices by itself
[Nexus 4 Original Android Development] RussianBear:
Everything works, man. You will need a powered otg y cable.
[Nexus 4 Original Android Development] thebrainkafka:
The thing i dont understand is why devices with inbuild power supply (external SD, dsrl) dont work in simple otg mode. The dont need power from the phone....

Thx
[Nexus 4 Original Android Development] ColdSphinX:
[MENTION=3946376]thebrainkafka[/MENTION]: as you can read in the 1st post...

[MENTION=535343]all[/MENTION]:

Anyway...does anyone know if it's posible to also enable OTG in recovery mode? For example TWRP? Because I'd love to do my backups directly to the usbdrive and not have to worry if internal Storage get's to low.

And as the recovery needs to have it's own kernel to also work after faulty kernel upgrades...I don't think, just using this patched kernel in regular mode will help here ;)
[Nexus 4 Original Android Development] ritchea:
USB OTG has never been available to me on the Nexus 4.
[Nexus 4 Original Android Development] sszz:
Yes, but as I understand, no one knows the exact current the phone outputs, these are just assumptions. I was wondering whether someone with proper tools could measure what current the phone can actually deliver for slimport...
[Nexus 4 Original Android Development] fasolka:
So as I understand it is not program issue, it is hardware issue.

But I used to use galaxy note and galaxy nexus. They charge much faster about 1200mA, but my nexus 4 charge from computer about 300mA and 600mA from wall charger.

As for my wife, she don't net otg, but I work with dslr cameras and I extra memory support.

Google whyyyy? You did it to us?
[Nexus 4 Original Android Development] thebrainkafka:
Which Hardware do i need exactly. Please link. ID like the cheapest way to get otg.

THX.
[Nexus 4 Original Android Development] ziddey:
Itt's been a while since I tested using slimport power, but I wasn't able to maintain access to the data pins with slimport on. That said, I did make a cable to isolate the data and power pins to separate plugs, and kept tripping the overcurrent protection no matter what device I tried. I jumped the 5v-3.3v stepdown for a microsd usb adapter, but it still didn't provide enough current. The specs say 40mA is the max @ 3.3v. I measured 3.1V (within tolerance..).

Again, read the OP.
[Nexus 4 Original Android Development] thebrainkafka:
Damn. I cant believe there is no way to override this to make external powered USB devices work...... Its a pitty
[Nexus 4 Original Android Development] cenwesi:
i am sure there is a way, it is just a mater of time.