Post Reply

[FIX] StartingAlertService Wakelock (TouchWizCalendar.apk)

9th December 2011, 03:57 PM   |  #1  
OP Senior Member
Flag Alicante
Thanks Meter: 134
 
243 posts
Join Date:Joined: Jul 2011
Donate to Me
Hi

This is the solution to fix the StartingAlertService Wakelock
To reproduce the problem (or the fix) modify calendar settings to notify events in status bar, create a an event and add a reminder inmediatly, so a notificantion is triggered and you can see it in status bar, open BetterBatteryStats and you can check in partial wakelocks if you have the StartingAlertService Wakelock. You will see that the wakelock is always working, you only need to refresh data and the wakelock time is increased, the wakelock is not released until you close to notification.

The problem is in TouchWizCalendar.apk not releasing the wakelock properly in class ServiceHandler inside class AlertService
The actual code is:
Code:
private final class ServiceHandler extends Handler {
        public ServiceHandler(Looper looper) {
            super(looper);
        }

        @Override
        public void handleMessage(Message msg) {
            processMessage(msg);
            AlertService.this.stopSelf();
        }
    }
If you check the new android sources you can see the next code:
Code:
 private final class ServiceHandler extends Handler {
        public ServiceHandler(Looper looper) {
            super(looper);
        }

        @Override
        public void handleMessage(Message msg) {
            processMessage(msg);
            // NOTE: We MUST not call stopSelf() directly, since we need to
            // make sure the wake lock acquired by AlertReceiver is released.
            AlertReceiver.finishStartingService(AlertService.this, msg.arg1);
        }
    }
So the next change will fix the problem. You have to decompile TouchWizCalendar.apk locate com/android/calendar/AlertService$ServiceHandler.smali and search & replace next code.
Search (the last method):
Code:
# virtual methods
.method public handleMessage(Landroid/os/Message;)V
    .registers 3
    .parameter "msg"

    .prologue
    .line 594
    iget-object v0, p0, Lcom/android/calendar/AlertService$ServiceHandler;->this$0:Lcom/android/calendar/AlertService;

    invoke-virtual {v0, p1}, Lcom/android/calendar/AlertService;->processMessage(Landroid/os/Message;)V

    .line 598
    iget-object v0, p0, Lcom/android/calendar/AlertService$ServiceHandler;->this$0:Lcom/android/calendar/AlertService;

    invoke-virtual {v0}, Lcom/android/calendar/AlertService;->stopSelf()V

    .line 601
    return-void
.end method
Replace by:
Code:
# virtual methods
.method public handleMessage(Landroid/os/Message;)V
    .registers 4
    .parameter "msg"

    .prologue

    iget-object v0, p0, Lcom/android/calendar/AlertService$ServiceHandler;->this$0:Lcom/android/calendar/AlertService;

    invoke-virtual {v0, p1}, Lcom/android/calendar/AlertService;->processMessage(Landroid/os/Message;)V

    iget-object v0, p0, Lcom/android/calendar/AlertService$ServiceHandler;->this$0:Lcom/android/calendar/AlertService;

    iget v1, p1, Landroid/os/Message;->arg1:I

    invoke-static {v0, v1}, Lcom/android/calendar/AlertReceiver;->finishStartingService(Landroid/app/Service;I)V

    return-void
.end method
Now recompile TouchWizCalendar.apk and replace it.

I've attached a cwm zip file to create a backup (TouchWizCalendar.apk.bak), replace the apk, and clear battery stats to reset wakelocks counters (reset battery stats doesn't affect to SGS2 battery, the battery chip doesn't need that info). The apk is based on kk5 rom.
If you don't want to use the cwm file you can extract TouchWizCalendar.apk from the zip and use root explorer (or similar) to replace the file, don't forget to make a backup of your original apk.

Edit:
If you get:

Code:
# virtual methods
.method public handleMessage(Landroid/os/Message;)V
    .locals 1
    .parameter "msg"
...
...
...
when decompile then replace with
Code:
# virtual methods
.method public handleMessage(Landroid/os/Message;)V
    .locals 2
    .parameter "msg"
...
...
...
Edit2:
If you use odexed rom delete or rename the odex file (maybe com.android.calendar.odex or TouchWizCalendar.odex, I'm not sure) to be sure classes.dex is used from deodexed apk

Edit3:
I've updated the zip to be sure odex file is not used in odexed roms
Attached Files
File Type: zip calendar_wakelock_fix_CWM.zip - [Click for QR Code] (834.9 KB, 1309 views)
Last edited by rodries; 7th January 2012 at 11:30 AM.
The Following 33 Users Say Thank You to rodries For This Useful Post: [ View ]
9th December 2011, 06:13 PM   |  #2  
pissyhun's Avatar
Senior Member
Flag Iasi
Thanks Meter: 96
 
496 posts
Join Date:Joined: Nov 2011
More
hi
it will work on xwkk5 stock rom odexed?
The Following User Says Thank You to pissyhun For This Useful Post: [ View ]
9th December 2011, 07:29 PM   |  #3  
starbase64's Avatar
Senior Member
Flag Lennestadt
Thanks Meter: 536
 
2,971 posts
Join Date:Joined: Apr 2007
Donate to Me
More
Thumbs up
Hi,

this works fine on CheckRom v4, StartingAlertService now 0,3%.

with friendly greet

starbase64
9th December 2011, 07:33 PM   |  #4  
OP Senior Member
Flag Alicante
Thanks Meter: 134
 
243 posts
Join Date:Joined: Jul 2011
Donate to Me
Quote:
Originally Posted by pissyhun

hi
it will work on xwkk5 stock rom odexed?

I think so, but I'm not sure. To be sure that you can revert the changes make a backup (or rename) of the apk(TouchWizCalendar.apk.bak) and the odex calendar files, then delete the odex (I think the odex will be com.android.calendar.odex) and install the zip.
You can always to reodex (http://forum.xda-developers.com/show....php?t=1208320)
Last edited by rodries; 9th December 2011 at 07:37 PM.
9th December 2011, 08:12 PM   |  #5  
pissyhun's Avatar
Senior Member
Flag Iasi
Thanks Meter: 96
 
496 posts
Join Date:Joined: Nov 2011
More
hi
thx for the answer but i am not a developer or an expert in android commands. i read the post u link but gave me headache)))
i will save the file and use it with a deodexed rom.
11th December 2011, 07:27 AM   |  #6  
OP Senior Member
Flag Alicante
Thanks Meter: 134
 
243 posts
Join Date:Joined: Jul 2011
Donate to Me
Quote:
Originally Posted by pissyhun

hi
thx for the answer but i am not a developer or an expert in android commands. i read the post u link but gave me headache)))
i will save the file and use it with a deodexed rom.

Wise decision
11th December 2011, 11:28 AM   |  #7  
eybee1970's Avatar
Recognized Contributor
Thanks Meter: 13,285
 
4,920 posts
Join Date:Joined: Jan 2010
Great. Will implement this in my Note ROM
12th December 2011, 05:36 PM   |  #8  
Junior Member
Flag Leeuwarden
Thanks Meter: 0
 
19 posts
Join Date:Joined: Mar 2008
More
Red face Love your fix
Yesterday I've installed your fix, and my wake locks for startingalertservice are gone. For your information I'm running a rooted version of the standard i9100XWKK2. Thanks again for your work, my battery time increased quit a bit.
12th December 2011, 08:58 PM   |  #9  
OP Senior Member
Flag Alicante
Thanks Meter: 134
 
243 posts
Join Date:Joined: Jul 2011
Donate to Me
Quote:
Originally Posted by hugoxboss

Yesterday I've installed your fix, and my wake locks for startingalertservice are gone. For your information I'm running a rooted version of the standard i9100XWKK2. Thanks again for your work, my battery time increased quit a bit.

Glad to hear it
13th December 2011, 02:47 AM   |  #10  
ATN24's Avatar
Senior Member
Thanks Meter: 47
 
362 posts
Join Date:Joined: Jun 2011
just to make sure, if my wakelocks are in seconds in betterbatterystats, i'm good right?

Post Reply Subscribe to Thread
Previous Thread Next Thread
Thread Tools
Display Modes


Top Threads in Galaxy S II Themes and Apps by ThreadRank