• Introducing XDA Computing: Discussion zones for Hardware, Software, and more!    Check it out!
  • Fill out your device list and let everyone know which phones you have!    Edit Your Device Inventory

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

Search This thread

jazzk

Senior Member
Mar 27, 2010
843
3,263
London
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_UNMOUNT 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
[COLOR="Red"]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[/COLOR]

.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

...

[COLOR="Red"].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[/COLOR]

.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.
 

Attachments

  • framework2.jar
    422.5 KB · Views: 806

boufa

Senior Member
Mar 5, 2007
333
118
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_UNMOUNT 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
[COLOR="Red"]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[/COLOR]

.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

...

[COLOR="Red"].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[/COLOR]

.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?
 
  • Like
Reactions: danben7

shadowofdarkness

Senior Member
Jun 11, 2010
554
139
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.
 

Attachments

  • framework2.jar
    2 MB · Views: 330
Last edited:

jazzk

Senior Member
Mar 27, 2010
843
3,263
London
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
 
Last edited:

Rushing

Senior Member
Jan 13, 2012
2,295
2,893
Los Angeles
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:D

Sent from my Transformer Prime TF201 using xda premium
 
  • Like
Reactions: wanerza77

abelle_abelle

Senior Member
Sep 28, 2012
309
20
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
 
Last edited:

InfX

Senior Member
May 1, 2008
886
216
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.
 

Attachments

  • OTGWakeLockPatch.zip
    1.5 MB · Views: 701

InfX

Senior Member
May 1, 2008
886
216
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 ;)
 

debernardis

Senior Member
Jun 30, 2011
532
149
Acireale, Sicily
www.debernardis.it
R: [HOW TO] Fix the USB OTG Unmount Wakelock in Samsung ROMs

Of course it's simple for you but might be complicated for others, not that smart, including myself. Xposed is an apk working on several rooted devices, including the sgs3 afaik, and mods are apk too, noob-friendly.

Sent from my GT-N7100 using xda premium
 

skingg

Senior Member
Dec 25, 2011
257
56
Does this work for anyone with GS3 I9300? Quite frankly, my battery started draining like mad last night for reasons I couldnt spot on my GSam Battery Monitor that prompted me to purchase Better Battery Stats to only notice I have usb mount/unmount wakelocks and true enough, I unmounted an USB OTG early in the day and a google search let me here! Anyone?
 

nickthorley

New member
Mar 19, 2013
1
0
Avoiding the wakelock

Hi all

I am using a stock samsung galaxy tab 2 tablet and I dont intend on rooting the device or installing a custom rom. I have found the dreded wakelock issue and I read that if the usb device is unmounted by going into settings and devices that the wakelock doesnt happen but if its unmounted via the widget in the dock that it would occur. The article said it would be best to disable the usb notification system but I cant see a way of doing this in a stock build.

Please could you confirm if there is anything I can change or do I just have to reboot every time I use a usb device to avoid the wakelock taking hold?

Thanks

Nick
 

kakatoock

New member
Mar 21, 2013
1
0
reverting back to m250s from gt-i9100

i have a problem when reverting my sgs ii.it stuck on T logo when reboot after flashed with odin
please help me what should i do :crying: and thanks before
 

mhossein_khamesian

Senior Member
Mar 31, 2013
77
6
babol
Only solution I found so far is the one detailed above with Xposed. But it needs root so maybe you better turn your device of after otg.

Sent from my GT-N7100 using xda premium

i just downloaded xposed usbun..apk and wondering if it works on note 10.1 with a rom based on xxcmc5 android revelution hd v6 would you please help me?
i just don't want to mess up with my system and flash the rom again:confused:
 

Top Liked Posts

  • There are no posts matching your filters.
  • 24
    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_UNMOUNT 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
    [COLOR="Red"]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[/COLOR]
    
    .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
    
    ...
    
    [COLOR="Red"].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[/COLOR]
    
    .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.
    6
    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
    3
    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.
    2
    By now the quickest way to get the result with minimal hacking is through the Xposed Framework http://forum.xda-developers.com/showthread.php?t=1574401 and the following mod http://www.villainrom.co.uk/forum/threads/usbstorageunmountter-wakelock-instant-releaser.5494/

    Only apk's to install, no fiddling :fingers-crossed:
    1
    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_UNMOUNT 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
    [COLOR="Red"]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[/COLOR]
    
    .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
    
    ...
    
    [COLOR="Red"].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[/COLOR]
    
    .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?