FORUMS
Remove All Ads from XDA
H10 Turbo

[HOW TO] Fix the USB OTG Unmount Wakelock in Samsung ROMs

843 posts
Thanks Meter: 3,270
 
By jazzk, Senior Member on 24th October 2012, 11:35 PM
Post Reply Email Thread
As you may know, in stock Samsung ICS ROMs, if you unmount a USB disk connected via USB OTG cable through the unmount notification in the notifications area, you'll be greeted with a UsbStorageUnmountter wakelock, which can only be killed with a reboot. It's a pain in the ass, but here's the fix.

Background of what's happening
  • When you click unmount, SystemUI calls the com/android/internal/app/UsbStorageUnmountActivity activity
  • UsbStorageUnmountActivity invokes the intent com.android.internal.os.storage.USB_STORAGE_UNMOUN T which is defined in com/android/internal/os/storage/UsbStorageUnmountter
  • The UsbStorageUnmountter service is where the wakelock is acquired (and supposed to be released onDestroy(), but never is.

Fix/hack

UsbStorageUnmountter is located in /system/framework/framework2.jar under com/android/internal/os/storage. Open it up.

Remove the wakelock acqusition

Remove the lines in red:

Code:
.method public onCreate()V

...

:cond_20
const-string v0, "power"

invoke-virtual {p0, v0}, Lcom/android/internal/os/storage/UsbStorageUnmountter;->getSystemService(Ljava/lang/String;)Ljava/lang/Object;

move-result-object v0

check-cast v0, Landroid/os/PowerManager;

const/4 v1, 0x1

const-string v2, "UsbStorageUnmountter"

invoke-virtual {v0, v1, v2}, Landroid/os/PowerManager;->newWakeLock(ILjava/lang/String;)Landroid/os/PowerManager$WakeLock;

move-result-object v0

iput-object v0, p0, Lcom/android/internal/os/storage/UsbStorageUnmountter;->mWakeLock:Landroid/os/PowerManager$WakeLock;

.line 74
iget-object v0, p0, Lcom/android/internal/os/storage/UsbStorageUnmountter;->mWakeLock:Landroid/os/PowerManager$WakeLock;

invoke-virtual {v0}, Landroid/os/PowerManager$WakeLock;->acquire()V

.line 75
return-void
Remove the redundant wakelock release (probably don't need to do this since it's never called anyway)

Remove the lines in red:

Code:
.method public onDestroy()V

...

.line 91
iget-object v0, p0, Lcom/android/internal/os/storage/UsbStorageUnmountter;->mWakeLock:Landroid/os/PowerManager$WakeLock;

invoke-virtual {v0}, Landroid/os/PowerManager$WakeLock;->release()V

.line 92
invoke-super {p0}, Landroid/app/Service;->onDestroy()V

.line 93
return-void
Attached is an XWLPX framework2.jar with the above mods. Testing so far has been n=1 (just myself at the moment) so interested in feedback.
Attached Files
File Type: jar framework2.jar - [Click for QR Code] (422.5 KB, 733 views)
The Following 24 Users Say Thank You to jazzk For This Useful Post: [ View ] Gift jazzk Ad-Free
 
 
29th November 2012, 11:13 PM |#2  
Senior Member
Thanks Meter: 99
 
More
Quote:
Originally Posted by jazzk

As you may know, in stock Samsung ICS ROMs, if you unmount a USB disk connected via USB OTG cable through the unmount notification in the notifications area, you'll be greeted with a UsbStorageUnmountter wakelock, which can only be killed with a reboot. It's a pain in the ass, but here's the fix.

Background of what's happening

  • When you click unmount, SystemUI calls the com/android/internal/app/UsbStorageUnmountActivity activity
  • UsbStorageUnmountActivity invokes the intent com.android.internal.os.storage.USB_STORAGE_UNMOUN T which is defined in com/android/internal/os/storage/UsbStorageUnmountter
  • The UsbStorageUnmountter service is where the wakelock is acquired (and supposed to be released onDestroy(), but never is.

Fix/hack

UsbStorageUnmountter is located in /system/framework/framework2.jar under com/android/internal/os/storage. Open it up.

Remove the wakelock acqusition

Remove the lines in red:

Code:
.method public onCreate()V

...

:cond_20
const-string v0, "power"

invoke-virtual {p0, v0}, Lcom/android/internal/os/storage/UsbStorageUnmountter;->getSystemService(Ljava/lang/String;)Ljava/lang/Object;

move-result-object v0

check-cast v0, Landroid/os/PowerManager;

const/4 v1, 0x1

const-string v2, "UsbStorageUnmountter"

invoke-virtual {v0, v1, v2}, Landroid/os/PowerManager;->newWakeLock(ILjava/lang/String;)Landroid/os/PowerManager$WakeLock;

move-result-object v0

iput-object v0, p0, Lcom/android/internal/os/storage/UsbStorageUnmountter;->mWakeLock:Landroid/os/PowerManager$WakeLock;

.line 74
iget-object v0, p0, Lcom/android/internal/os/storage/UsbStorageUnmountter;->mWakeLock:Landroid/os/PowerManager$WakeLock;

invoke-virtual {v0}, Landroid/os/PowerManager$WakeLock;->acquire()V

.line 75
return-void
Remove the redundant wakelock release (probably don't need to do this since it's never called anyway)

Remove the lines in red:

Code:
.method public onDestroy()V

...

.line 91
iget-object v0, p0, Lcom/android/internal/os/storage/UsbStorageUnmountter;->mWakeLock:Landroid/os/PowerManager$WakeLock;

invoke-virtual {v0}, Landroid/os/PowerManager$WakeLock;->release()V

.line 92
invoke-super {p0}, Landroid/app/Service;->onDestroy()V

.line 93
return-void
Attached is an XWLPX framework2.jar with the above mods. Testing so far has been n=1 (just myself at the moment) so interested in feedback.

I recently purchased a note ,y first samsung and discovered this issue. please explain in more noob details how to make these changes and i will test it. ie do i need root? what software do i make the edits with?
The Following User Says Thank You to boufa For This Useful Post: [ View ] Gift boufa Ad-Free
30th November 2012, 12:40 AM |#3  
Senior Member
Thanks Meter: 141
 
More
I can't thank you enough, as a regular OTG user this has always annoyed me beyond belief. I will get right to testing this on the JB leak.


Edit:

I have tested this on Jelly Bean XXLSJ and it works. I have attached my file for anyone on the same version.
Attached Files
File Type: jar framework2.jar - [Click for QR Code] (2.00 MB, 297 views)
The Following 3 Users Say Thank You to shadowofdarkness For This Useful Post: [ View ] Gift shadowofdarkness Ad-Free
2nd December 2012, 10:31 PM |#4  
OP Senior Member
Flag London
Thanks Meter: 3,270
 
More
Quote:
Originally Posted by shadowofdarkness

I can't thank you enough, as a regular OTG user this has always annoyed me beyond belief. I will get right to testing this on the JB leak.


Edit:

I have tested this on Jelly Bean XXLSJ and it works. I have attached my file for anyone on the same version.

It's
a) sad to hear that the issue is still present in the JB build but
b) good to hear that the fix works in JB too

Devs
Please feel free to incorporate the fix in your ROMS

Mods
I posted this in the Original Development section. For whatever reason it was moved to the General Section. This is an original code fix to resolve a pretty serious issue present in all Samsung ROMs. When I posted this, as far as I could see, the issue had never been resolved at a code level (hence the post in the Original Development section). At the very least please move it to the Development Section or it's at risk of being drowned out and missed amongst the more general posts in the General section
The Following 6 Users Say Thank You to jazzk For This Useful Post: [ View ] Gift jazzk Ad-Free
3rd December 2012, 04:26 AM |#5  
Senior Member
Thanks Meter: 141
 
More
Quote:
Originally Posted by jazzk

It's
a) sad to hear that the issue is still present in the JB build but
b) good to hear that the fix works in JB too

I know, I lost faith in Samsung fixing this when a family member got a S III and my test showed it had the same wakelock issue.
28th December 2012, 09:24 PM |#6  
Rushing's Avatar
Senior Member
Flag Los Angeles
Thanks Meter: 2,957
 
Donate to Me
More
Quote:
Originally Posted by jazzk

It's
a) sad to hear that the issue is still present in the JB build but
b) good to hear that the fix works in JB too

Devs
Please feel free to incorporate the fix in your ROMS

Mods
I posted this in the Original Development section. For whatever reason it was moved to the General Section. This is an original code fix to resolve a pretty serious issue present in all Samsung ROMs. When I posted this, as far as I could see, the issue had never been resolved at a code level (hence the post in the Original Development section). At the very least please move it to the Development Section or it's at risk of being drowned out and missed amongst the more general posts in the General section

Thanks for sharing your work

Sent from my Transformer Prime TF201 using xda premium
The Following User Says Thank You to Rushing For This Useful Post: [ View ] Gift Rushing Ad-Free
15th January 2013, 09:28 PM |#7  
Senior Member
Thanks Meter: 20
 
More
so this will fix Galaxy s3 not showing up in my computer when connected whereas it is detected by another software?

Sent from my GT-I9300 using xda premium
16th January 2013, 12:59 PM |#8  
bigmo7's Avatar
Senior Member
Flag London
Thanks Meter: 216
 
Donate to Me
More
Fantastic work It's such an annoyance on my SGS3. indie has incorporated this in his ROMs now!


18th January 2013, 05:42 PM |#9  
InfX's Avatar
Senior Member
Thanks Meter: 215
 
More
Thumbs up
Thanks for the post, i didn't know there is actually a fix for this. BTW, any idea why is the wakelock acquisition there? I am sure, whoever put it in place had something in mind. I am asking because i am trying to think what possible side effects we may get by removing it.

Also, attaching a windows scripting host .js i've made to automate the patch application, i can easily imagine it being useful for someone. See the js text for more info, it is well-commented.

Thanks again for the post.
Attached Files
File Type: zip OTGWakeLockPatch.zip - [Click for QR Code] (1.46 MB, 653 views)
18th January 2013, 05:54 PM |#10  
debernardis's Avatar
Senior Member
Flag Acireale, Sicily
Thanks Meter: 152
 
More
By now the quickest way to get the result with minimal hacking is through the Xposed Framework http://forum.xda-developers.com/show....php?t=1574401 and the following mod http://www.villainrom.co.uk/forum/th...releaser.5494/

Only apk's to install, no fiddling
The Following 2 Users Say Thank You to debernardis For This Useful Post: [ View ] Gift debernardis Ad-Free
18th January 2013, 07:31 PM |#11  
InfX's Avatar
Senior Member
Thanks Meter: 215
 
More
Re: [HOW TO] Fix the USB OTG Unmount Wakelock in Samsung ROMs
Are SGS3 ROM generally tend to include this framework? I seriously doubt it. Anyway, as you can see from my previous post, decompiling java or even automating the patching process isn't exactly a big deal for me
Post Reply Subscribe to Thread

Guest Quick Reply (no urls or BBcode)
Message:
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes