yashsingh1/xdaforums huggingface dataset:
[Nexus 4 Original Android Development] ziddey:
Yes, your cable does the same thing as the one shown in the picture (one in the picture plugs into a mini-usb device (like a lot of usb hubs. picture is just an example showing the extra plug for power).. which is exactly the same as what your "special" cable does. The fact that it causes the phone to switch to host mode means that power and data are being detected. Check your logs to see what's going on with the charging. From an electrical standpoint, that's identical to your "special" cable. Otherwise, it simply wouldn't switch to host mode to begin with.

As far as the results being "the same" with or without Stickmount, /sdcard/usbStorage is ONLY created and used by Stickmount. What happens there is solely on Stickmount. Perhaps there's an issue mounting /dev/sda1 if the drive is already vold mounted. I don't know. But I am more concerned about proper native support, and that's what's achieved. It has nothing to do with achieving host mode through /sys/kernel/debug/msm_otg/mode. You should see the same results anyway. If anything, this issue would be something to take up with Chainfire in the Stickmount thread. It's really a non-issue when using just one usb drive, since there is native support for it, and therefore no need for Stickmount in the first place. But if you wanted to use multiple usb drives for some reason...
[Nexus 4 Original Android Development] jcnbama:
Re: [OTG] [19MAR13] [DIRTY HACKS] Externally Powered USB OTG (Seeking Devs)

So, I wanted to ask a question and I hope I don't sound like a idiot. I stumbled across this thread and by looking at it it seems like it's a patch that allows the Nexus 4 to have usb otg support. Is that right? I downloaded the zip from the download link on the op. Flashed it using TWRP, plugged in a USB OTG cable and a 32gb SanDisk drive and nothing happened.. I'm on PA 3+ with the Franco Kernel MS1. Am I doing something wrong or do I have a total misconception as to what this mod does.?
[Nexus 4 Original Android Development] ziddey:
Sounds like you're not supplying external power.
[Nexus 4 Original Android Development] sga999:
ziddey, I did more tests. This is the last time I'll mention the /sdcard/usbStorage way since that's not what you're concerned with. Neither am I! But I had gotten the impression that you were saying that method would still work, as well as your /storage/usbdisk0 way. Since the only way I could see usbStorage was with stickmount, that's what I continued to try with your kernel, just as I had done with CaptainMuon's. (When I said it didn't work without stickmount, I should have just said that usbStorage didn't show, so obviously, that would not work). Results for usbStorage are that the files show on the drive, but they all have 0 size, so they obviously will not work. I don't really care to deal with Chainfire about this issue at this time. I'm happy with using your usbdisk0.

As far as the charging, the only cable that works for me is my "special" Y-cable. I'd love to see why it doesn't charge with my OTG with "standard" Y-cable, but I'm not familiar with the logs. Can you tell me which log to check and what specific "events" to look for in that log?
[Nexus 4 Original Android Development] Flynny75:
It will probably be because power is not supplied back up to the host, only to the device. You can check it with a multimeter or something
[Nexus 4 Original Android Development] sga999:
Sorry to say I don't have any such equipment as a multimeter. Since ziddey said I could look at the logs, I'm hoping he or someone else will tell me which log and what events to search for.
[Nexus 4 Original Android Development] ziddey:
The current implementation won't trigger host mode unless power is detected.

Compare dmesg. You can view live: cat /proc/kmsg
[Nexus 4 Original Android Development] sga999:
ziddey, I'm not sure if that is directed to me or not. I have the phone connected to the OTG cable, which is connected to the Y-cable. I have the flash drive plugged in to the Y-cable, and the Y-cable is plugged into the laptop for power. /sdcard/usbdisk0 works perfectly. No charge is occurring. If I pull out the power part of the Y-cable from the computer, I get the nofication "USB storage unexpectedly removed". If I plug it back in, everything works perfectly again.

I don't know if that addresses your comment at all...maybe it was not even to me! May I ask again about how to see "charge events" in some log?
[Nexus 4 Original Android Development] ziddey:
Yes, the comment was towards both of you. Host mode will NOT be automatically enabled unless it detects power. The mechanism for both your OTG setups is exactly the same (there is only ONE mechanism for enabling host mode automatically, and it is based on the "CHARGER" detected), so if it charges with one, it can charge with the other.

How are you supplying power for the OTG Y-cable? Also plugging into your laptop for power?
[Nexus 4 Original Android Development] sga999:
Sorry about asking again for the log info....I hadn't seen your prior response. I'll look at dmesg and /proc/kmsg, but I'm not sure what I'm comparing or looking for.

As far as supplying power, I guess I'm not understanding something again!. I have an OTG/Y-cable that I mentioned earlier that DOES allow charging to work. But now, I'm describing the situation where it does NOT charge. That's with 2 separate cables hooked together, an OTG and a Y-cable. The only power that I know about is part of the Y-cable, and I'm plugging that into the laptop. So when you said "Also plugging into your laptop for power", I don't know what the "Also" means....just one power part, plugged into the laptop.

I believe this is exactly how CaptainMuon described the setup. Here's what he said:

Connect everything as follows (should be obvious):

- Y cable power plug (typically red) to the PC or adapter

- Other Y cable plug into the OTG cable

- OTG cable into the phone

- USB device into the Y cable socket
[Nexus 4 Original Android Development] ziddey:
Also plugging into your laptop for power?

What I've been trying to say is that both of your setups theoretically produce an electrically IDENTICAL scenario. If one works and not the other, then it's mostly something you are overlooking (connecting to laptop for power vs wall for example) or a defect in one of your components (far less likely since host mode is being activated). I'm not saying it's impossible that there's a problem with the code, just that it is treating both of your setups in exactly the same way. Again, if it's not detecting power, it would not be able to switch to host mode (and it also sets the charger type at the same time).
[Nexus 4 Original Android Development] baltac:
Your lasts update, works for me as well, but it didn't create the backup of the framework-res thing...

Manually executed the script otgmod.sh in recovery with adb shell and in verbose mode (-x flag did the trick), and the result is the seguent:

(i've previously manually mounted the /system folder)
[...]
[B]/tmp/otgmod # chmod 775 zip[/B]
[I]chmod 775 zip[/I]
[B]/tmp/otgmod # chmod 775 otgmod.sh[/B]
[I]chmod 775 otgmod.sh[/I]
[B]/tmp/otgmod # chmod 644 res/xml/storage_list.xml[/B]
[I]chmod 644 res/xml/storage_list.xml[/I]
[B]/tmp/otgmod # sh -x otgmod.sh[/B]
[I]sh -x otgmod.sh
+ cd /system
+ cat build.prop
+ grep ro.usb.host=1
ro.usb.host=1
+ cd /tmp/otgmod
+ cp /system/framework/framework-res.apk .
+ ./zip -rf framework-res.apk res
freshening: res/xml/storage_list.xml (deflated 51%)
+ cp /system/framework/framework-res.apk /system/framework/framework-res.apk.1
+ cp framework-res.apk /system/framework/framework-res.apk
+ cd ..
+ rm -rf otgmod[/I]
sh: getcwd: No such file or directory
[B](unknown) #[/B]

so the script itself works normally. Dunno if the last "error" is significant. I had to exit the shell and reenter to do anything. Next time I'll try with CWM 6.0.2.3 or TWRP...

Apart this, as said before, the host work automatically for me. No need to "echo" anything, and no need of thirdy part apps. Only things I have to do is (if you want, after I'll post some photo):

- Attach OTG USB Adapter to Nexus (exit with female USB plug).

- Attach Y cable (like the one posted by ziddey before): the thinner part of the Y (male USB plug) to the front USB on the PC.

- the other part (female USB plug) will be attached to an USB hub, where I've connected an 4Gb USB key, an USB mouse and an USB Keyboard.

- the common plug of the Y cable, obviously to the USB OTG adapter.

Magically I have: phone charging, mouse and keyboard control, I can see normally the files in the /usbdisk/ folder and all the media files are shown automatically in Gallery and in Google Play Music.
[Nexus 4 Original Android Development] sga999:
Yes, the "special" cable (the one that allows charging to work) is plugged into the laptop for power.

However, I've gotten into some situation now where I can't get the OTG with the "standard" Y-cable to work at all. I mean, not only does it not charge (which I expected), but it's not causing your /storage/usbdisk0 to mount. I don't know if I've messed up the cables now or what! I'll write again when I'm clear about what's going on here. All I can say is that less than an hour ago, the same setup (with OTG and "standard") allowed me to view the flash drive and play a movie, it was not charging, and the power part of the cable was plugged into the laptop.
[Nexus 4 Original Android Development] ziddey:
Oh yikes. I forgot that the script is in the directory that gets deleted. Haha. Hopefully it doesn't cause any real problems, but I'll resolve it for the next release. I wonder if otgmod.sh is even running at all when called from updater-script?

Perhaps using the output of the zip command to determine if an update was performed isn't a great idea. Got any other ideas? I'm hesitant to simply check if /system/framework/framework-res.apk.1 exists since I'm afraid a user might update the rom, causing framework-res.apk to be updated, but framework-res.apk.1 to persist.

See baltac's post before yours. It's a problem on your end. If it doesn't detect power, it WILL NOT automatically enable host mode. Simple as that. And in the current implementation, if it detects loss of power, it will switch out of host mode.
[Nexus 4 Original Android Development] sga999:
ziddey, I do see baltac's post, and it's great that the OTG and Y-cable combo are working well for him. There must be some difference in mine....I'm going to give up on it for now, but I'll try to look at some logs if I get this setup functioning again. Right now, it won't work at all, i.e. nothing gets mounted. Thanks for all of your help. With my "special" cable, all is well, so I'm very happy.
[Nexus 4 Original Android Development] baltac:
This is the recovery.log output for your file, pulled out before the manual execution of the script. Maybe you will understand if something was broken. (Ah! My recovery was adapted for my language. I'd translated back to english the log output, so some term may differs from standard CWM).

-- Installing: /sdcard/0/ziddey-otg-03192013.zip
Update package found...
I:update location: /sdcard/0/ziddey-otg-03192013.zip
I:used /data/media for /sdcard/0/ziddey-otg-03192013.zip.
Opening update package...
Installing update...
minzip: Extracted file "/tmp/otgmod/otgmod.sh"
minzip: Extracted file "/tmp/otgmod/res/xml/storage_list.xml"
minzip: Extracted file "/tmp/otgmod/zip"
about to run program [/tmp/otgmod/otgmod.sh] with 1 args
script result was [t]
[Nexus 4 Original Android Development] ziddey:
I did some research on fast charge and can confirm that it does still work. It must be enabled on every boot (by design). I'm assuming Franco's app was doing this for you, and I'm not sure why the option has now disappeared. It does still work when manually enabled: echo 1 > /sys/kernel/fast_charge/force_fast_charge

<7>[ 9505.974483] msm_otg msm_otg: chg detection work
<7>[ 9505.974666] msm_otg msm_otg: chg_type = USB_SDP_CHARGER
<7>[ 9505.974697] b_idle work
<7>[ 9505.974727] b_sess_vld
<6>[ 9505.974758] USB fast charging is ON - 1000mA.
<6>[ 9505.975002] msm_otg msm_otg: Avail curr from USB = 1000
<6>[ 9505.975460] msm_otg msm_otg: current: 0 -> 1000 (mA)
<6>[ 9505.975673] pm_power_set_property_usb: usb_target_ma 1000
[Nexus 4 Original Android Development] sszz:
Okay, thanks. Is there a chance to enable it in franco's app as well? I know it is doable, but would be much more convenient that way...
[Nexus 4 Original Android Development] ziddey:
This is purely speculation on my part, but it's possible Franco's app is checking the build number for the kernel to decide whether to enable that option or not. Unfortunately, I have no idea what's going on when working with git, so I ended up starting from scratch and reapplying my mods. As a result, the build number is now back to 1.

I'm going to see if I can artificially bump the number up / how Franco's app would respond.
[Nexus 4 Original Android Development] sga999:
Okay, ziddey, I know you may not be interested in this since baltac has his working properly. I think it must be something about my OTG and separate Y-cable that are different. So I'm just putting this here in case others end up having my same problems. I don't expect you to find anything in your code to fix this.

With CaptainMuon's kernel, I can connect phone to OTG cable, OTG cable to Y-cable, Y-cable USB female to flash drive, and Y-cable USB male to laptop for power. Then I must do the echo command and stickmount in order to see /sdcard/usbStorage. It works well. But it is not charging.

But! With your kernel, NOTHING happens when I set the cables up exactly the same. I mean, lsusb in terminal emulator shows 2 devices, not 3 or 4. Nothing is mounted at all. However, if I do the echo command (and not stickmount), your /storage/usbdisk0 can be seen and works well. /sdcard/usbStorage shows files, but they cannot be opened successfully. It is not charging.

If I unplug the USB plug to the laptop, the Storage - USB STORAGE information goes away, and obviously, I can no longer see files on usbdisk0. But if I plug back in to the laptop, the USB STORAGE information comes back, and again I can read and play files on ubdisk0.

So again, I don't expect an answer, but it is peculiar to me that your kernel won't work with my OTG and Y-cable...UNLESS I go ahead with the echo command (and not stickmount). And another peculiarity is that this combination of cables never allows charging with either CaptainMuon's or your kernel.

Okay, at least I've documented it here in hopes that someone else might benefit.

Baltac, can you tell me where you got your Y-cable? I'm happy with my other "special" cable that works well with ziddey's kernel and does charge (using laptop for power). But if my curiosity gets the better of me, I might want to try another Y-cable. I have 2 OTG cables, and I'm guessing they are not the problem.

EDIT: Changed in 2 places to indicate that only the echo command is needed, not stickmount, in order to get /storage/usbdisk0 to work.
[Nexus 4 Original Android Development] Wis76:
Actually a "complete unistall" tutorial for removing Ziddey/Franco modifications could be helpful. To install the 4.3 update without losing data I almost bricked the phone (and ended up needing to flash the complete JWR66V, losing data anyway). ^___^U
[Nexus 4 Original Android Development] daniel578:
I didn't understand, it's possible or not?
[Nexus 4 Original Android Development] Wis76:
Is it possible... what?

To uninstall? Yes, by reflashing the rom. But to maintain the data I think you should not flash the user data .img.

I'm asking here, anyway, I'm noobish. ^^
[Nexus 4 Original Android Development] daniel578:
To uninstall zip file, I flashed the otg zip file, and It's not working with Franco r176, so I want to uninstall it
[Nexus 4 Original Android Development] Wis76:
Yep, I edited the reply, sorry.
[Nexus 4 Original Android Development] marhensa:
works flawlessly on 4.3 + Franco 176 + this mod.

even with 4 usb, 2 of them are external harddisk.

thank you... :)

---

Sent from Android Device
[Nexus 4 Original Android Development] RussianBear:
All you have to do is install a stock kernel.
[Nexus 4 Original Android Development] Wis76:
No. This kernel makes some modifications to system files that cannot be undone this easily, from what I've learnt.
[Nexus 4 Original Android Development] ziddey:
Danger, danger!

In 4.3, file system mounting has been unified-- instead of a file on the ROM-side for usbdisk mounting (/system/etc/vold.fstab), everything is done in fstab.mako (RAMDISK!) now. As a result, you will get an error on boot and FC when going into settings->storage if you don't revert the ROM-side change(s).

I wrote a little script to revert ROM-side changes:

sed '/ro.usb.host=1/d' -i /system/build.prop
mv /system/etc/permissions/platform.xml.1 /system/etc/permissions/platform.xml
mv /system/framework/framework-res.apk.1 /system/framework/framework-res.apk
rm /system/etc/permissions/android.hardware.usb.host.xml
rm -rf /system/lib/modules

This makes the assumption that you don't have any other modules in /system/lib/modules, so if for whatever reason you do, make changes accordingly. If you don't understand what this means, don't worry about it--- there's a 99.99% chance it doesn't affect you.

Here's the zip: ziddey-otg-unmod.zip

Flash the kernel of your choice afterwards.
[Nexus 4 Original Android Development] Wis76:
I think that Ponury's Touch Control uses some proprietary modules. In this case is it better to unload those before using the "unmod"?
[Nexus 4 Original Android Development] RussianBear:
Gotcha. Thanks for correcting me.
[Nexus 4 Original Android Development] ritchea:
4.3 on N4 seems to have created a militant mutant! So many new lessons to learn with this creation--and I'm still trying to grasp the old stuff. Galaxy Nexus and original N7 don't have any of the woes I've encountered with N4 --although flashing franco kernel then ziddey's version did go smoothly.
[Nexus 4 Original Android Development] punitthereddevil:
Can u please elaborate the circuit diagram...? As in what goes where...

*****Save your fingers the work and hit "Thanks" instead of typing it...!!*****

NEXUS⁴ Stock Android 4.3

---------- Post added at 08:15 AM ---------- Previous post was at 08:06 AM ----------

Hi there...first off all, ur doing an awesome job with this thread...so thanks for all your work...

I just needed to know if this mod is safe to use for a noob like me...I won't be trying out anything big...just a flash drive for my extra data...can I safely use this mod with deodexed stock 4.3 with cwm recovery...?

Thank you...

*****Save your fingers the work and hit "Thanks" instead of typing it...!!*****

NEXUS⁴ Stock Android 4.3
[Nexus 4 Original Android Development] marhensa:
i dont know, it just cheap chinese dc powered usb hub sold here.

i'm sure you can get it too on your local computer / pc accessories store.

---

Sent from Android Device
[Nexus 4 Original Android Development] punitthereddevil:
I dint mean the internal circuit of the hub...just the cables u used to connect the phone, power,etc...just where each of those cables in the pictures went...

*****Save your fingers the work and hit "Thanks" instead of typing it...!!*****

NEXUS⁴ Stock Android 4.3
[Nexus 4 Original Android Development] marhensa:
here..

USB IN goes to Nexus 4.

DC 5V goes to power adapter.

USB 1 2 3 4 goes to usb flash drive or external harddisk.

---

Sent from Android Device
[Nexus 4 Original Android Development] punitthereddevil:
Right...thats what i wanted...thanks...working perfectly right...? Coz I'm planning on doing the same...
[Nexus 4 Original Android Development] marhensa:
yes it works flawlessly.

and with powered usb on Nexus 4 it much faster than i use on Galaxy Nexus without powered usb.

---

Sent from Android Device
[Nexus 4 Original Android Development] punitthereddevil:
That's good...I'll go look for a hub around my place...hope they have it in my country...thanks...
[Nexus 4 Original Android Development] bruce7373:
So, to clarify, you're plugging your N4 into the powered hub directly with an OTG cable?
[Nexus 4 Original Android Development] dunghnguyen:
[MENTION=3337302]marhensa[/MENTION]: what rom you are using ? also kernel franco r176? Tks
[Nexus 4 Original Android Development] 4L3xN3t:
Hi. Is there any way to format a usb pen from the phone? It doesn't really recognize it like a storage device....

From my Nexus4 with love
[Nexus 4 Original Android Development] Javier.D:
Hi Ziddey, Could you add Kexec Support to this kernel for run ubuntu in MultiRom? Thanks ;)

Enviado desde mi Nexus 4 usando Tapatalk 4
[Nexus 4 Original Android Development] StephenSpig:
The cable that goes from the hub, into the phone is your OEM charger cable?

If I understood correctly, your setup is getting the necessary 5V... Shouldn't you be able to plug right in...? [MENTION=584916]ziddey[/MENTION]
[Nexus 4 Original Android Development] punitthereddevil:
I've made the connections using a y cable and an otg cable...and I've flashed ziddeys kernel too...but I don't get any notification when I connect the flash drive...nothing at all...!!

I wonder if its a problem with the cables...I've verified the otg cable with my friends phone and it works fine...

But I don't know how to verify if the y cable is working of not...this is what I tried but I'm not sure if its a definite way to diagnose the cable problem...I just connected the power source at one end and an optic mouse to the other...the red light in the mouse lit up, indicating that there is current flowing through the cable...a small light on the drive also lights up when I use it...but there's absolutely nothing on the phone screen...no notification of any sort...

Is there anything I'm missing here...? Can u please help me out...? [MENTION=584916]ziddey[/MENTION]

---------- Post added at 10:47 PM ---------- Previous post was at 10:33 PM ----------

Are u using stock 4.3...? I mean the "absolute stock"...
[Nexus 4 Original Android Development] :
Just dropping by to say thanks for this awesome mod, enjoying it.
[Nexus 4 Original Android Development] xanthrax:
hi [MENTION=584916]ziddey[/MENTION] !

maybe you can give a hand to to oblikas ?

http://xdaforums.com/showpost.php?p=44798586&postcount=236

:highfive:
[Nexus 4 Original Android Development] dunghnguyen:
I tried with hdd dock as it has power but failed...do not understand why. I am on 4.3 Cataclysm rom jwr66v + kernel franco r176 + simple usb otg

---------- Post added at 08:44 PM ---------- Previous post was at 08:41 PM ----------

@marhensa: can u advise me what brand of your usb hub? it has only 1 usb out you use to plug it in N4, is it correct? Tks for advice.
[Nexus 4 Original Android Development] ritchea:
You possibly are experiencing the same issue I had when I first tried with a powered hub. ziddey explained what seemed to be happening in post #52.
[Nexus 4 Original Android Development] lordlad:
I've just discovered this thread and so pardon me if this had been asked.

Since this is a kernel patch, I will assume that nandroid backup to USB-OTG won't work on TWRP for the nexus 4?

I've been using this function to do nandroid backup to my usb stick on my nexus 7 and as such just asking, i can't test it since i don't have a USB-OTG Y-cable (only had the normal USB-OTG cable)..

Thanks in advance.
[Nexus 4 Original Android Development] aoaleman:
In this thread, I think I saw it was working IN TWRP 2.5.
[Nexus 4 Original Android Development] nikkpap:
try this please and report ... http://xdaforums.com/showthread.php?t=2412689
[Nexus 4 Original Android Development] ritchea:
Solved! Congratulations on making your own cable that DOES work.

---------- Post added at 01:28 PM ---------- Previous post was at 01:01 PM ----------

Works great! The N4 just keeps getting better. Thanks, nikkpap for the heads-up.

EDIT: I was not able to restore from the usb otg drive. I was able to "mount" is but the file never showed up. It's still an easy way to have a backup separate from internal memory.
[Nexus 4 Original Android Development] punitthereddevil:
Yeah...thanks to you for all the help...:)

And thanks to ziddey too...he's doing an awesome job here...:)