Attend XDA's Second Annual Developer Conference, XDA:DevCon 2014!
5,769,165 Members 37,488 Now Online
XDA Developers Android and Mobile Development Forum

[FIX] StartingAlertService Wakelock (TouchWizCalendar.apk)

Tip us?
 
rodries
Old
(Last edited by rodries; 7th January 2012 at 11:30 AM.)
#1  
Senior Member - OP
Thanks Meter 133
Posts: 243
Join Date: Jul 2011
Location: Alicante

 
DONATE TO ME
Default [FIX] StartingAlertService Wakelock (TouchWizCalendar.apk)

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, 1307 views)
The Following 33 Users Say Thank You to rodries For This Useful Post: [ Click to Expand ]
 
pissyhun
Old
#2  
pissyhun's Avatar
Senior Member
Thanks Meter 96
Posts: 496
Join Date: Nov 2011
Location: Iasi
hi
it will work on xwkk5 stock rom odexed?
The Following User Says Thank You to pissyhun For This Useful Post: [ Click to Expand ]
 
starbase64
Old
#3  
starbase64's Avatar
Senior Member
Thanks Meter 516
Posts: 2,935
Join Date: Apr 2007
Location: Lennestadt

 
DONATE TO ME
Hi,

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

with friendly greet

starbase64
Starbase64 YouTube Channel | Stabase64 Blog | Starbase64 Flickr Stream


Device: HTC One m8ul
ROM: InsertCoin
Kernel: Stock is the best
S-OFF: Yes
SuperCID: Yes
MID: 0P6B10000
PVS: 1

Device: Samsung Galaxy Tab 2 7''
ROM: CM 10.2
Kernel: stock
Recovery: TWRP
Baseband: stock
 
rodries
Old
(Last edited by rodries; 9th December 2011 at 07:37 PM.)
#4  
Senior Member - OP
Thanks Meter 133
Posts: 243
Join Date: Jul 2011
Location: Alicante

 
DONATE TO ME
Quote:
Originally Posted by pissyhun View Post
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)
 
pissyhun
Old
#5  
pissyhun's Avatar
Senior Member
Thanks Meter 96
Posts: 496
Join Date: Nov 2011
Location: Iasi
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.
 
rodries
Old
#6  
Senior Member - OP
Thanks Meter 133
Posts: 243
Join Date: Jul 2011
Location: Alicante

 
DONATE TO ME
Quote:
Originally Posted by pissyhun View Post
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
 
eybee1970
Old
#7  
eybee1970's Avatar
Recognized Contributor
Thanks Meter 13285
Posts: 4,920
Join Date: Jan 2010
Great. Will implement this in my Note ROM
 
hugoxboss
Old
#8  
Junior Member
Thanks Meter 0
Posts: 19
Join Date: Mar 2008
Location: Leeuwarden
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.
Samsung Galaxy S2, currently with NEAT ROM 1.5
HTC Leo (HD2) Collecting dust

HTC Blackstone (HD1)
SOLD
 
rodries
Old
#9  
Senior Member - OP
Thanks Meter 133
Posts: 243
Join Date: Jul 2011
Location: Alicante

 
DONATE TO ME
Quote:
Originally Posted by hugoxboss View Post
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
 
ATN24
Old
#10  
ATN24's Avatar
Senior Member
Thanks Meter 47
Posts: 362
Join Date: Jun 2011
just to make sure, if my wakelocks are in seconds in betterbatterystats, i'm good right?
SG4 Omega rom addicted \m/

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes