[FIX] StartingAlertService Wakelock (TouchWizCalendar.apk)

Search This thread

rodries

Senior Member
Jul 2, 2011
410
183
Alicante
Xiaomi Mi 10T / 10T Pro
@rodries.

After replacing the original TouchWizCalendar.apk by yours from the first post, I'm still getting wakelocks from Agenda (Dutch for Calendar). See the first picture. Batterylife is OK though (see the second picture). Also, I noticed that the APK's (my original and yours) differ almost 200 KB in size (see the third picture). Therefore my kind request: would you be so kind to modify my original TouchWizCalendar.apk (attached to this post)?

My current firmware versions are (Android 2.3.6):
- PDA : I9100XWKK2
- PHONE : I9100XXKI4
- CSC : I9100XENKJ1
Build Info : Fri Nov 11 18:05:58 KST 2011

Try to use this apk and comment
Remember to reset battery stats to be sure problem is fixed
The size is not important I've compressed the apk with 9
 

Attachments

  • TouchWizCalendar.apk
    783.2 KB · Views: 283
  • Like
Reactions: d451d and andrehj

andrehj

Member
Dec 9, 2007
37
1
Thanks! Just installed this apk successfully. Rebooted the S2 and charged it fully (is there a faster way to reset the wakelock counters?). At this moment the partial wakelock screen in BetterBatteryStats only shows sleep_broadcast and ActivityManager-Launch items, both with 1s.

Will keep you updated.
 

borrego

Senior Member
Feb 16, 2008
58
5
Hi rodries ,

Would you be so kind to patch my ZSXXKI3 TouchWizCalendar?
 

Attachments

  • TouchWizCalendar.rar
    589.8 KB · Views: 39

andrehj

Member
Dec 9, 2007
37
1
Calendar causes wakelocks without reminders?

After a promising start (this morning at 10 AM there were no wakelocks generated by Calendar), I just looked at my S2 and found out that StartingAlertService had caused 29minutes of wakelocks... :mad:

But the strange thing is: Because of the Christmas holidays I have no appointments with reminders in my calendar today.

To test this theory I made a test-appointment with a reminder. This reminder has been in the notification bar (on the top of the screen) for 80 minutes now, and the wakelocks counter has not increased since...

So it looks like there is not just one process in TouchWizCalendar.apk causing these wakelocks, but also a different (unfound and unfixed) process.
How do I find out which process?:confused:
 

borrego

Senior Member
Feb 16, 2008
58
5
I think the apk from post 41 will work fine. Test & comment. If it doesn't work I'll patch your apk.

Thank you. I tried and it works!

Just want to confirm again: It is right to remove the original TouchWizCalendar.odex file and leave the patched apk file in the /system/app directory?
 

rodries

Senior Member
Jul 2, 2011
410
183
Alicante
Xiaomi Mi 10T / 10T Pro
After a promising start (this morning at 10 AM there were no wakelocks generated by Calendar), I just looked at my S2 and found out that StartingAlertService had caused 29minutes of wakelocks... :mad:

But the strange thing is: Because of the Christmas holidays I have no appointments with reminders in my calendar today.

To test this theory I made a test-appointment with a reminder. This reminder has been in the notification bar (on the top of the screen) for 80 minutes now, and the wakelocks counter has not increased since...

So it looks like there is not just one process in TouchWizCalendar.apk causing these wakelocks, but also a different (unfound and unfixed) process.
How do I find out which process?:confused:
It's weird, I use calendar a lot and wakelock is fixed.
Try to clear dalvik & cache & batt stats from recovery mode.
I've checked android sources and I've found StartingAlertService in calendar only, maybe I'm wrong.
 

andrehj

Member
Dec 9, 2007
37
1
It's weird, I use calendar a lot and wakelock is fixed.
Try to clear dalvik & cache & batt stats from recovery mode.
I've checked android sources and I've found StartingAlertService in calendar only, maybe I'm wrong.

You're not wrong, according to BetterBatteryStats the StartingAlertService came from Calendar.
Throught Google I've found that I can get in recovery mode when I press Home, Vol Up and Power simultaneously. This worked. However, then I only have these options:
- Reboot (want to do that later)
- Apply update from SD-card (don't want that)
- Wipe data / Factory reset (definitely don't want that)
- Wipe cache partition

Is this last option the cache you are mentioning? But what about Dalvik? What is that?

Edit: Did some googling and found a directory /data/dalvik-cache. Can I simply delete all files in this directory and reboot?
 
Last edited:

rodries

Senior Member
Jul 2, 2011
410
183
Alicante
Xiaomi Mi 10T / 10T Pro
You're not wrong, according to BetterBatteryStats the StartingAlertService came from Calendar.
Throught Google I've found that I can get in recovery mode when I press Home, Vol Up and Power simultaneously. This worked. However, then I only have these options:
- Reboot (want to do that later)
- Apply update from SD-card (don't want that)
- Wipe data / Factory reset (definitely don't want that)
- Wipe cache partition

Is this last option the cache you are mentioning? But what about Dalvik? What is that?

Edit: Did some googling and found a directory /data/dalvik-cache. Can I simply delete all files in this directory and reboot?
Try this
In recovery mode
-wipe cache partition (you are not going to loose anything)
-goto advanced
--Wipe Dalvik cache
--Wipe Battery Stats
Go back and reboot system now
This time the boot will be longer maybe 2 or 3 minutes because dalvik cache will be regenerated.
In theory you only need to "Wipe Battery Stats" to be sure the log is clean.
Now test and comment.
 

blk15

Member
Aug 31, 2011
39
2
Melbourne
Sadly the issue has returned for me after a few days without the wakelock appearing...

Would there be any issues to attempt to reflash this again if it is pre-existing?
 

rodries

Senior Member
Jul 2, 2011
410
183
Alicante
Xiaomi Mi 10T / 10T Pro
Sadly the issue has returned for me after a few days without the wakelock appearing...

do you have the wakelock again?

Maybe you have updated your rom or installed the apk again without notice.

I had that problem when I installed an update, and thougth there was another bug, but after check my apk I noticed that I was using an old version. After reinstall the apk the wakelock is fixed for 2 weeks, and I'm using calendar a lot.
 

planetf1

Senior Member
Jan 25, 2010
825
92
Hi,
Great discovery figuring out the cause of the wakelock - a real shame samsung hasn't patched this yet,

I have the KL1 rom (based off Intratech's frankenstein modem/csc combo) - the .apk is below.

I am a developer -- but not on android. As of yet I've not pulled apart/rebuild apks. Is there any chance you could patch - or failing that do you have a quick cheat-list of what to do to rebuild?

The odex file is effectively just precompilation to speed dalvik loading right? So just for a single apk no real benefit to rebuilding with a modified calendar - just may as well delete. right?

Many thanks
 

Attachments

  • TouchWizCalendar.apk
    962.1 KB · Views: 15

rodries

Senior Member
Jul 2, 2011
410
183
Alicante
Xiaomi Mi 10T / 10T Pro
You're not wrong, according to BetterBatteryStats the StartingAlertService came from Calendar.
Throught Google I've found that I can get in recovery mode when I press Home, Vol Up and Power simultaneously. This worked. However, then I only have these options:
- Reboot (want to do that later)
- Apply update from SD-card (don't want that)
- Wipe data / Factory reset (definitely don't want that)
- Wipe cache partition

Is this last option the cache you are mentioning? But what about Dalvik? What is that?

Edit: Did some googling and found a directory /data/dalvik-cache. Can I simply delete all files in this directory and reboot?
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.
 
Last edited:

rodries

Senior Member
Jul 2, 2011
410
183
Alicante
Xiaomi Mi 10T / 10T Pro
Hi,
Great discovery figuring out the cause of the wakelock - a real shame samsung hasn't patched this yet,

I have the KL1 rom (based off Intratech's frankenstein modem/csc combo) - the .apk is below.

I am a developer -- but not on android. As of yet I've not pulled apart/rebuild apks. Is there any chance you could patch - or failing that do you have a quick cheat-list of what to do to rebuild?

The odex file is effectively just precompilation to speed dalvik loading right? So just for a single apk no real benefit to rebuilding with a modified calendar - just may as well delete. right?

Many thanks

You have uploaded odexed apk so there is no classes.dex inside apk
I can't fix it this apk, I need the classes.dex file (I think the odex will be com.android.calendar.odex)
Anyway try the apk from post 41
http://xdaforums.com/showpost.php?p=20735943&postcount=41
KL1 & KK5 are very very similar so must work
Remember to rename/backup original com.android.calendar.odex & TouchWizCalendar.apk. 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.
 
Last edited:

crypticc

Senior Member
Aug 22, 2009
1,249
174
London
You have uploaded odexed apk so there is no classes.dex inside apk
I can't fix it this apk, I need the classes.dex file (I think the odex will be com.android.calendar.odex)
Anyway try the apk from post 41
http://xdaforums.com/showpost.php?p=20735943&postcount=41
KL1 & KK5 are very very similar so must work
Remember to rename/backup original com.android.calendar.odex & TouchWizCalendar.apk. 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.

here you go, unedited KL1 from Intratech. both APK and ODEX file. I hope this helps us all ????

In meantime I am using the one you linked.

:)

Cheers
 

Attachments

  • Samsung.zip
    758.7 KB · Views: 22

Top Liked Posts

  • There are no posts matching your filters.
  • 33
    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
    2
    Hello rodies

    i uploaded the whole cmw file from the GingerMod Rom. I didn't extract the apk because there is another file in it. The dev. didn't named it TouchWizCalender.apk but Calendar.apk.

    I think it's the same Programm though because i get the same Wakelock and also battery drain with it.

    Many thanks in advance. :):):)
    Sure thing. Perhaps when rodies agrees, we can give the mod to the GingerMod dev.

    I hope rodies can fix the nasty Bug for us.

    I'm a bit busy now, I'll patch your calendar tomorrow.
    Also I think there is more bugs in calendar code I'll try to fix them also.
    Samsung is using an old and bugged calendar version, S is not upgrading his modified apks with last android version.

    About Maps I'm not using it so I don't know nothing about maps wakelocks, tell me the wakelock name and I'll try to find the problem, but maps is a big apk, so it will be very hard to find the problem, and how to reproduce the problem.
    In calendar I know how to reproduce the problem so I can debug it and find the bug.

    The calendar fix is public so any dev can use it freely.
    If I find more bugs I'll publish how to fix them.
    2
    @rodries.

    After replacing the original TouchWizCalendar.apk by yours from the first post, I'm still getting wakelocks from Agenda (Dutch for Calendar). See the first picture. Batterylife is OK though (see the second picture). Also, I noticed that the APK's (my original and yours) differ almost 200 KB in size (see the third picture). Therefore my kind request: would you be so kind to modify my original TouchWizCalendar.apk (attached to this post)?

    My current firmware versions are (Android 2.3.6):
    - PDA : I9100XWKK2
    - PHONE : I9100XXKI4
    - CSC : I9100XENKJ1
    Build Info : Fri Nov 11 18:05:58 KST 2011

    Try to use this apk and comment
    Remember to reset battery stats to be sure problem is fixed
    The size is not important I've compressed the apk with 9
    1
    hi
    it will work on xwkk5 stock rom odexed?
    1
    I've attached my calendar. Thanks.

    Your apk is fixed
    You haven't the wakelock problem
    If you have the problem try to clean cache & dalvik-cache from recovery, then reboot, the first time you will have to wait a lot (about 5 mins), because you have to wait to recreate cache.