Wednesday, March 23, 2016

[GUIDE][MOD]Full USB-OTG Support on Media Players in Marshmallow

It's my first relevant post in here so please be benevolent and friendly to me :).
Hello everyone,
After long hours of roaming around on the internet, Moto forums, PowerAMP forums (you wouldn't believe how many people posted this problem in there), huge exchange of emails and debugs to the Nexus Media Importer dev, and checking out many many topics here on XDA, I finally came across the only way to use an USB-OTG pendrive as a music library, and having Android detect it (through the Media Service) and build the music library for other media apps to use.

tl dr; Problem: You wanted loads of music without wasting precious internal memory. You tried using an USB pen but no mp3 apps were able to find the files, nor stickmount, nor whatever.

This is so far the only way to do this on android Marshmallow.

Believe me, I've tried almost everything one can do, including using the Nexus Media Importer, Stickmount, OTG Helper, etc (spoiler alert, none of these worked).

Why is this happening, you ask? Well, Google changed things on Android 6.x.x so much regarding filesystems and USB support that full read/write on USB OTG with other apps no longer works, although I've never tested on previous versions of Android. But I finally managed to find a way to do it, and here I intend to share it with you guys.

Requirements - Rooted phone and permissive SELinux (what is that and how do I do it? don't worry, it's easy and I'll explain a bit later)

1st step - Verify that your phone is capable of using USB-OTG. If it is not, check on play store for other apps that supposedly can enable USB Host support on your phone, although I've never tried them because I never needed, so I can't say anything. My phone is a Moto X 2014 and it comes with OTG support embedded.

2nd step - Format your pendrive as NTFS. This is very important because...
If you use your pendrive as Fat32, Android will mount it to a folder in /data/media_rw/blablabla with GID and UID 1023 (media_rw), which most apps don't have permissions to access, thus they won't be able to find your pendrive and build a music library. Why? Well, glad you asked...
...Since Fat32 doesn't support the linux permissions system, Android mounts the pendrive with the FUSE fs wrapper, which cloaks a permission system hard-coded into some file in the Android system that I wasn't able to tell how could I modify it in order to set the pen permissions as 777 root root.
You can do so by plugging your pen on a Windows PC and right clicking -> Format. Remember to backup your data, otherwise you will lose everything. Your pen will still be able to be used on Windows pcs and Macs. You could also use other fileformats...
... like EXT4 or f2fs or exFAT or whatever, but do it at your own risk. I have no idea if those would work, despite them being able to use the linux permission system.


3rd step - Install the wonderful app Paragon HFS and NTFS mounter from appstore or whatever. They say it isn't compatible with marshmallow but it is, the only issue is that it can't mount a pendrive automatically but it's very easy to do it manually. In the settings menu, you can set SELinux as permissive. Since I'm not an android dev, only an ambicious amateur, I can't really explain what it does or what happens when you do that. So far, neither me or my phone died because of that, so. ;)
Oh by the way, whenever you insert the pen , Android will say it's corrupted and ask you to format it. DO NOT DO IT! That happens because Android doesn't natively support NTFS (hence using an external app to solve that). Oh, and since we're talking about that, there is a way for Android to natively support NTFS...
..., just search it up on XDA. Beware that it's outdated and it won't work on Marshmallow either, unless you edit the copymodulecrc script, but that goes beyond my knowledge. For now, stick to the plan.


4th step - You need to choose the folder which you want to mount the pen to, which will be a folder in the root Android folder (I chose /pen so that I wouldn't forget)
You are now probably thinking, "That's insane! You need to edit init.rc in order to do that!" Well, you're kinda right, but there is a workaround for that. Why do I do this? Well...
... if you mount the pen in another random folder such as /storage/emulated/0/pen it won't work because all the folders underlying that one have certain permission issues that don't let other media apps be able to search for music files.
So here I'll show you two ways of accomplishing this.

4.1 Editing init.rc - This is very complex and NOT RECOMMENDED unless you're very comfortable with messing with boot files. PLEASE DO NOT DO THIS if you aren't sure of what you're doing, don't tell me I didn't warn you.
So in order to do this, well, I won't explain it to you. Search it up on the internet, it's very complex and too big for me to post here. But in the end what you want to do is edit the init.rc file, adding two lines:
"mkdir /pen" and "chmod 777 /pen".

4.2 Creating a script that runs on boot - This is the one method I recommend since it's harmless, but you have to install yet another app, that allows you to run scripts at boot. I used script manager. Then create a script that mounts the / folder as rw, creates the folder /pen, chmods it to 777. I used the following:
#!/system/bin/sh
su -c mount -o rw,remount /proc /
su -c mkdir /pen
su -c chmod /pen 777

I tried other mount -o commands with rootfs instead of /proc but they didn't work. I don't know the difference but I hope it's harmless. Anyways, let's move on.
Run the script to see if it works, and to create the folder. Use a rooted file explorer to verify if the folder was created.

5th step - Reboot your phone if you had to set SELinux as permissive, and type on the Terminal "su -c getenforce" to confirm that your SELinux is permissive.
VERY IMPORTANT - On the Paragon app, open settings and disable FS access rights, otherwise it's the same as mounting a Fat32 pendrive - not what we want.
On the Paragon app, choose the folder we created before as the folder to mount the pen to, and mount the pendrive. If you followed all the previous steps correctly, the app won't have any issues mounting the pen.

6th step - Find a way to enforce Android building a media library with the new files in the USB OTG pendrive. There are many ways to do this and I recomment the one I used, but I will tell you other ways.
I used the app jetAudio which is a media player that can also forceably build a media library. On jetAudio settings menu, press "Rebuild media library" and point to the /pen folder. It will start reading all the files and Android now detects your pendrive as a media library.
Another way would be to use an app called FolderMount, and creat a symlink from the /pen to another folder in your emulated SD storage (you know, the only folder you have access to if you're not rooted), and wait for some time until hopefully Android detects your new music.
Another way would be to create a symlink manually in the terminal, similar to the way I described with the Foldermount thing, but with one less app.

Hurray! Congrats for reaching this part of the post. If you did everything correctly, all media apps will finally be able to find the files. I posted some screenies to orientate you.
Feel free to ask anything and I will try to answer or explain. Remember that I'm no Android dev so my knowledge is limited. Feel free to thank me, if you want too.

Attached Thumbnails
Click image for larger version Name: Screenshot_20160313-180006.png Views: N/A Size: 115.1 KB ID: 3694029   Click image for larger version Name: Screenshot_20160313-180012.png Views: N/A Size: 152.0 KB ID: 3694030   Click image for larger version Name: Screenshot_20160324-003814.jpg Views: N/A Size: 128.0 KB ID: 3694031   Click image for larger version Name: Screenshot_20160324-003837.png Views: N/A Size: 81.0 KB ID: 3694032   Click image for larger version Name: Screenshot_20160324-003851.png Views: N/A Size: 138.7 KB ID: 3694033   Click image for larger version Name: Screenshot_20160324-003856.png Views: N/A Size: 137.1 KB ID: 3694034   Click image for larger version Name: Screenshot_20160324-003917.png Views: N/A Size: 166.8 KB ID: 3694035   Click image for larger version Name: Screenshot_20160324-003924.png Views: N/A Size: 99.2 KB ID: 3694036   Click image for larger version Name: Screenshot_20160324-004011.png Views: N/A Size: 145.3 KB ID: 3694037   Click image for larger version Name: Screenshot_20160324-004020.png Views: N/A Size: 52.9 KB ID: 3694038   Click image for larger version Name: Screenshot_20160324-004056.png Views: N/A Size: 132.1 KB ID: 3694039   Click image for larger version Name: Screenshot_20160324-004127.jpg Views: N/A Size: 217.7 KB ID: 3694040  


from xda-developers http://ift.tt/1WJXklY
via IFTTT

No comments:

Post a Comment