r/jailbreak • u/ThePantsThief Developer • Jan 29 '20
Discussion [Discussion] [Tutorial] Why your battery screen won't load in Settings, and how to fix it (powerlogHelperd crash)
powerlogHelperd is the daemon that provides the data for the Battery section of Settings. If you're not on iOS 13, this post likely doesn't apply to you because the same problem likely doesn't exit in iOS 12.
Scroll to the bottom if you just want to know how to fix the crash.
Background
SubstrateLoader—the program that decides which tweaks to load into a given process—reads the plist files for each tweak to determine whether a tweak should be loaded. Tweaks can tell Substrate which processes they want to load into by either listing executable names (like mediaserverd or MobileSMS) or by passing one or more bundle identifiers, which can identify an app or process or a framework. These are all called "filters"
The types of filters Substrate supports are very limiting. For example, you cannot exclude yourself from certain processes if your tweak breaks a daemon or some app but works fine everywhere else. Substrate also doesn't provide a filter that means "I want my tweak to load into apps only." The closest way tweak developers can achieve this is by using the com.apple.UIKit filter, which is the one framework shared among nearly all apps.
Unfortunately, it's not just apps that link against UIKit. Some daemons and other non-app processes link against it, which means tweaks that probably don't want to be there get loaded.
A quick note about memory: jetsam is the mechanism used by the kernel to restrict the resources different processes can use before they are terminated. By default, all daemons have a hard memory limit of 6 MB (and some daemons are fine-tuned to have a higher limit). If a process goes over its memory limit, the kernel kills it.
The problem
Beginning in iOS 13, one of powerlogHelperd's dependencies links UIKit. This means that any tweaks which use the com.apple.UIKit filter will get loaded into it. powerlogHelperd has the default memory limit of 6 MB, so when too many UIKit tweaks get loaded into it, it gets killed. This happens endlessly on repeat, and it's probably hurting your battery life a little too. You can test this by looking for it in CocoaTop or by plugging in your phone and opening Console.app and searching for exceeded mem limit.
TLDR: powerlogHelperd is not crashing because of any one tweak in particular, it's just running out of memory because daemons don't get a lot of memory.
Proposed solution: a plead to Saurik
I have no direct line of contact with Saurik myself, so I can only hope he sees this and agrees: Substrate needs to special-case the com.apple.UIKit filter so that it only applies to apps. 99.999% of the time when a developer uses this filter, they don't expect or want their tweak to load into non-UI processes. Substrate could add an override flag elsewhere in that plist to enable the old behavior for the rare cases where that is exactly what is desired. In short, there is a disconnect between what developers think this filter does, and what it actually does.
Substrate could enforce this filter by checking whether the new process resides in /Applications or the user apps directory, /var/mobile/Containers/Bundles. If the tweak is using com.apple.UIKit and the executable is not in either of those folders, don't load the tweak unless they're using the override flag.
I know Saurik is busy and probably won't be able to find the time to implement this change, but this would be a huge quality of life improvement for the jailbreak community. Saurik, if you do see this, I ask that you talk to me or Kirb about this.
Alternatives considered
- Make a new filter that matches apps only, like
com.substrate.apps, and leave the behavior ofcom.apple.UIKitthe way it is! The problem with this is it means everyone has to update their tweaks to use this new filter, and new developers probably won't even be aware of this new filter because all online material about tweak development says to usecom.apple.UIKit. This also leaves abandoned-but-working tweaks hanging high and dry: the SwipeExpander dev has been MIA for years now, for example. Old tweaks cannot adopt an opt-in fix. - Fix it in Theos / Logos, not substrate! The problem at hand cannot be completely fixed at that level. Sam Binger has suggested that Logos be given a new
%init(appsonly=YES)sort of syntax that would prevent the tweak's init code from executing if the process is not an app. This solution has the same problems as above: doesn't fix existing tweaks without an update, etc. It also doesn't fix the real problem, which is the overhead associated with loading dozens of tweaks into a process they don't belong in. And if a tweak which is loaded has more dependencies that don't already exist in the process, those get dragged in too.
In short, this new behavior must be opt-out. Making it opt-in doesn't solve much of anything since there are a plethora of old tweaks using the com.apple.UIKit filter and since new developers aren't savvy to the implications of using it.
Temporary solution
In the meantime, you can just raise the jetsam memory limit for any processes that are affected by this. In my case, it was just powerlogHelperd and PowerUIAgent. The files that state the memory limits are located in /System/Library/LaunchDaemons/com.apple.jetsamproperties.DXXX.plist, where XXX is something like 22 or 221. Only one of them is the one used for your device, and I'm not sure how to tell which one it is at the moment without doing this, but you can just edit all of those files and it'll be fine. You can find your device's codename on this page by clicking on your device name at the top of it's section. The codename is then listed on a page like this in the format XXXAP. If you click on XXXAP it will tell you which model it's associated with, like iPhone10,6 (different models = GSM / CDMA / Global). Or, you can just edit them all and that's fine too.
Edit: as someone has pointed out, you can also just exclude these processes from Substrate with something like Choicy. I personally don't want to install another tweak just to do this, though. The Choicy method is not guaranteed to work.
Fire up your favorite plist editor. If the process is a daemon—like my two were—then look for it's bundle identifier under Version4/Daemon/Override and edit/add these keys:
ActiveSoftMemoryLimit: 25
InactiveHardMemoryLimit: 25
Screenshot of where to look for the daemon, and screenshot of the final entry
Then reboot and re-jailbreak. 25 MB seems like a good number to me. No crashes on my device. If it's still crashing, you may need to raise this number.
I really hate that this is necessary, but it's all we've got until Saurik acknowledges the issue. Substrate desperately needs com.apple.UIKit to only apply to actual apps. This also all applies to Substitute of course, but those guys are pretty good about this sort of thing and I'm sure they'd be happy to make such a change. Unfortunately Substrate needs to make this change too. Anyway, I don't know pwn's handle, can someone tag him?
Edit: shameless plug for my twitter, NSExceptional
11
u/ThePantsThief Developer Jan 29 '20
cc'ing those who may find this update interesting: /u/OxycodonIV, /u/Samg_is_a_Ninja, /u/CoBrA2168
23
u/xxthepersonx iPhone 15, 17.1| Jan 29 '20 edited Jan 29 '20
Instead of raising the memory limit, I just disable substrate in those processes using choicy. None of my installed tweaks hook either one of your mentioned daemons.
Also, nice write up. Thanks for the info
3
u/OxycodonIV iPhone X, iOS 13.3.1 Jan 31 '20
Any news on Saurik?
5
u/vibrants iPhone X, 13.4.1 | Jan 30 '20
Thank you for your research, this answers a lot of questions and I hope Saurik can add this to his todo list for the Jailbreak community users of substrate.
5
u/[deleted] May 26 '20
Thanks, It is working, did as you said. in Filza there was no InactiveHardMemoryLimit along with ActiveSoftMemoryLimit
So I added InactiveHardMemoryLimit as number in it.
Reboot -> Re jailbreak
Working perfectly
4
u/OxycodonIV iPhone X, iOS 13.3.1 Jan 29 '20
I honestly think making the substrate app filter might be the best Solution for now, until Saurik can correct it
Most older tweaks don’t work unfortunately, and most tweaks now concentrate on iOS 12 & 13 with active developers
Soo I think this might be the way to go, unless Saurik is able to at least provide a reply if this filter implementation is even possible and if he will be willing to look into it
1
u/c33v33 iPhone 13 Mini, 16.6 Feb 10 '20 edited Feb 10 '20
Thanks for this. I performed the changes on an iPhone X.
However, PowerUIAgent does not exist (powerlogHelperd does) on an iPad Pro 10.5 wifi iOS 13.3.1. Is this expected? Should I create the key?
1
u/Rishabhmittal iPhone X, 14.4.2 | May 16 '20
Did find the powerloghelperd but only the active soft memory, it doesn’t show the inactive hard memory. So changed it. Is reboot and rejailbreak necessary? Can LDRestart do the trick?
1
u/MobbinOnEm iPhone X, 13.5 | May 25 '20
I’m a bit late to the party but when I found powerUIagent this is what it looks like. Do I just change that value to 25? I don’t see active soft or inactive hard
1
u/rafael_mfr iPhone X, 14.3 | Jun 02 '20
Mine is already 25 as image shows (https://i.imgur.com/OosGykE.png)
I installed powerloghelperdfix and it used to works, after a little time battery informations doesn’t show anymore.
If I reboot and rejailbreak again with checkra1n it works and then after a few time it doesn’t work anymore.
When battery information doesn’t work if I open CocoaTop I can see the daemon launching (green color) and then crashing (red color).
Any workaround for it?
1
u/[deleted] Jun 20 '20
Thank you, this fix worked. This will also stop any battery drain from powerloghelperd right?
1
u/imraan1992hk iPhone 14 Pro Max, 16.3| Jul 06 '22
Would this work on iOS 14.2, taurine, iPhone X?
3
u/free_refil iPhone 14 Pro, 16.0.3 May 26 '20
Set the limits to 100 for these daemons as per your guide on 13.5 on my X and I feel like it’s a whole new phone! THANK YOU!!!!
3
u/galjha Jul 09 '20
Thanks!
working perfect on my iphone 8 plus (ios 13.5.1 - checkrain)
1
u/unaffected2 iPhone X, 14.3 | May 21 '20
I ain’t a dev or something but I managed to get the power section to show without installing anything or performing any modification to the system whatsoever, all you have to do is to go to power section in settings , wait for about 5 seconds in the spinning wheel and then press back , wait for 2 seconds or so and then go to the power section again , it should work, if it doesn’t then just repeat the same thing until it works, note that When The power section is displayed the powerlog daemon stops crashing (I checked in CocoaTop) . Also I tried choicy and the powerlogfix and I can say they help increasing the chance for the power section to be displayed comparing to the method I mentioned
2
u/Kaori_Miyazono_ iPhone 11 Pro Max, 13.5 | Jan 30 '20
Thank you for the write-up. My battery settings load perfectly every time. 😊
2
u/abushahd8 Mar 16 '20
I did all possible solutions but It didn’t work with me.
2
u/Stoned-Apeman iPhone X, 13.5.1 | Jun 27 '20
Thank you so much for this, powerloghelperd and choicy didn’t work but your tutorial did!
6
u/ogchris99 iPhone X, iOS 13.3.1 Jan 29 '20
Just download powerloghelperfix
3
u/[deleted] Jan 29 '20
Or perhaps in the meanwhile, an option can be added in [[Choicy]] to bulk stop injection in all daemons with blacklist/whitelist ofcourse (Because I know some tweaks inject into mediaserverd).
Currently it's possible to disable injection in daemons via Choicy, but it's very inefficient as you have to do it per daemon basis which is next to impossible! /u/opa334/
1
u/taurine_bitch iPhone 12 Pro, 15.1.1 Feb 07 '20
Thank you for this. Edited/Added the keys and it worked for me.
1
u/OddyAte iPhone X, 14.5 Mar 03 '20
Thanks a lot, today I randomly searched for battery related topics as I had a huge battery drain issue caused by a daemon. Since checkra1n exists, I did not find a fix for the Battery stats not showing up. I did what you suggested and now it works!!! I had to set it to 50MB tho, and I don't even have a lot of tweaks so I am not sure what is using it so heavily. When I last updated my phone and had to reinstall all tweaks, I noticed that as soons as I install a tweak that uses PreferenceLoader, the battery usage stats disappear. Hope that there will be a fix from Saurik for this. Thanks again!
1
u/50sweet35ice May 29 '20
Can you please help me too? What should I do now?
1
u/Anantich Jul 11 '20
Thanks, it works!
1
u/xDraker iPhone 16, 18.1 Jul 12 '20
This worked, thanks!
2
u/[deleted] Jun 07 '20
[removed] — view removed comment
1
u/[deleted] Jun 19 '20
[removed] — view removed comment