Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add function to configure battery optimizations on iOS? #35

Open
baltpeter opened this issue Mar 6, 2023 · 9 comments
Open

Add function to configure battery optimizations on iOS? #35

baltpeter opened this issue Mar 6, 2023 · 9 comments
Assignees
Labels
feature New feature or request help wanted Extra attention is needed

Comments

@baltpeter
Copy link
Member

I'm not familiar with iOS, so I don't know whether this concept also applies there, but with #34, we're adding a function to control battery optimizations on Android, so we might need that on iOS as well.

I did find a "Background App Refresh" setting under "General" that seems relevant:

image

@baltpeter baltpeter added the feature New feature or request label Mar 6, 2023
@baltpeter baltpeter changed the title Add function to disable battery optimizations on iOS? Add function to configure battery optimizations on iOS? Mar 6, 2023
@baltpeter baltpeter self-assigned this Mar 14, 2023
@baltpeter
Copy link
Member Author

@baltpeter
Copy link
Member Author

baltpeter commented Mar 14, 2023

Doesn't seem to be stored in an SQLite database.

NEEDLE="background|bart|bgtask|bgapp|bgprocessing"

find / -name '*.db' -o -name '*.sqlite*' -print0 2>/dev/null | while IFS= read -r -d '' file; do
    for X in $(sqlite3 -readonly "$file" .tables 2>/dev/null); do
        sqlite3 -readonly "$file" "SELECT * FROM \"$X\";" 2>/dev/null | grep -iE >/dev/null $NEEDLE && echo "Found in file '$file', table '$X'";
    done
done

This yields only false positives:

Found in file '/System/Library/PrivateFrameworks/DialogEngine.framework/holidayNames.sqlite3', table 'holidayNames'
Found in file '/System/Library/PrivateFrameworks/SiriInference.framework/holidays.sqlite3', table 'calendars'
Found in file '/System/Library/PrivateFrameworks/SiriInference.framework/holidays.sqlite3', table 'holidays'
Found in file '/System/Library/PrivateFrameworks/SiriInference.framework/hypocorisms.sqlite3', table 'names'
Found in file '/private/var/mobile/Library/Photos/Libraries/Syndication.photoslibrary/database/Photos.sqlite', table 'ATRANSACTIONSTRING'
Found in file '/private/var/mobile/Library/Sileo/sileo.sqlite3', table 'Packages'
Found in file '/private/var/db/analyticsd/config.sqlite', table 'eligible_transform_view'
Found in file '/private/var/db/analyticsd/config.sqlite', table 'enabled_event_names_view'
Found in file '/private/var/db/analyticsd/config.sqlite', table 'enabled_tranforms_by_event_view'
Found in file '/private/var/db/analyticsd/config.sqlite', table 'enabled_transform_view'
Found in file '/private/var/db/analyticsd/config.sqlite', table 'disabled_transform_view'
Found in file '/private/var/db/analyticsd/config.sqlite', table 'events'
Found in file '/private/var/db/analyticsd/config.sqlite', table 'transforms'

Similarly, if we search for the bundle ID of an app that has the permission:

Found in file '/private/var/networkd/db/netusage.sqlite', table 'ZAPPDOMAINUSAGE'
Found in file '/private/var/networkd/db/netusage.sqlite', table 'ZPROCESS'
Found in file '/private/var/mobile/Containers/Data/Application/6B93C293-8E67-4B96-91B8-85059EAF2586/Library/Application Support/Google/RemoteConfig/RemoteConfig.sqlite3', table 'main_active'
Found in file '/private/var/mobile/Containers/Data/Application/6B93C293-8E67-4B96-91B8-85059EAF2586/Library/Application Support/Google/RemoteConfig/RemoteConfig.sqlite3', table 'fetch_metadata_v2'
Found in file '/private/var/mobile/Containers/Data/Application/6B93C293-8E67-4B96-91B8-85059EAF2586/Library/Application Support/Google/RemoteConfig/RemoteConfig.sqlite3', table 'main'

@baltpeter
Copy link
Member Author

Next idea: Apple also likes to store stuff in .plist files. So, I searched all *.plist files on the system for ones that contained deliveroo (part of the bundle ID of an app with Background App Refresh enabled), but not audible (part of the bundle ID of an app with BAR disabled):

FILES=$(find / -name "*.plist")

while IFS= read -r file; do
  if grep -iq deliveroo "$file" && ! grep -iq audible "$file"; then
    echo "$file"
  fi
done <<< "$FILES" > candidates.txt

Result:

/private/var/mobile/Library/Keyboard/app_usage_database.plist
/private/var/mobile/Library/Preferences/com.apple.mt.killed.plist
/private/var/mobile/Library/Preferences/com.apple.duetactivityscheduler.plist
/private/var/mobile/Library/Preferences/com.apple.osanalytics.addaily.plist
/private/var/mobile/Library/Preferences/com.apple.corespotlightui.plist
/private/var/mobile/Library/Preferences/com.apple.itunescloud.plist
/private/var/mobile/Containers/Data/Application/6B93C293-8E67-4B96-91B8-85059EAF2586/.com.apple.mobile_container_manager.metadata.plist
/private/var/mobile/Containers/Data/Application/6B93C293-8E67-4B96-91B8-85059EAF2586/Library/Caches/appsflyer-v1/700420675.2525.plist
/private/var/mobile/Containers/Data/PluginKitPlugin/44525754-031E-4BE6-8887-838CAE812519/.com.apple.mobile_container_manager.metadata.plist
/private/var/root/Library/Caches/locationd/clients.plist
/private/var/containers/Bundle/Application/270C6DE3-9CFB-40F7-888E-F5D140A7AEBA/.com.apple.mobile_container_manager.metadata.plist
/private/var/containers/Bundle/Application/270C6DE3-9CFB-40F7-888E-F5D140A7AEBA/iTunesMetadata.plist
/private/var/containers/Bundle/Application/270C6DE3-9CFB-40F7-888E-F5D140A7AEBA/Deliveroo.app/PlugIns/DeliverooWidgetExtension.appex/Info.plist
/private/var/containers/Bundle/Application/270C6DE3-9CFB-40F7-888E-F5D140A7AEBA/Deliveroo.app/SC_Info/Manifest.plist
/private/var/containers/Bundle/Application/270C6DE3-9CFB-40F7-888E-F5D140A7AEBA/Deliveroo.app/Info.plist
/private/var/containers/Bundle/Application/270C6DE3-9CFB-40F7-888E-F5D140A7AEBA/Deliveroo.app/GoogleService-Info.plist

@baltpeter
Copy link
Member Author

From going through those, none of them seems relevant.

I'll try Frida next.

@baltpeter
Copy link
Member Author

The docs I mentioned earlier various classes starting with BG (like BGAppRefreshTaskRequest), but none of those seem to be responsible for the settings. No class starting with BG was triggered when I changed the setting for an app:

❯ frida-trace -U -m "*[BG* *]" Preferences
Instrumenting...                                                        
+[BGTaskSchedulerProxy shared]: Loaded handler at "/home/benni/__handlers__/BGTaskSchedulerProxy/shared.js"
-[BGTaskSchedulerProxy registerForTaskWithIdentifier:launchHandler:]: Loaded handler at "/home/benni/__handlers__/BGTaskSchedulerProxy/registerForTaskWithIdentifier_la_39d0b759.js"
Started tracing 2 functions. Press Ctrl+C to stop.                      

@baltpeter
Copy link
Member Author

How about background (frida-trace -U -m "*[*background* *]/i" -M "*[*UI* *]" Preferences)? Nothing.

@baltpeter
Copy link
Member Author

settings (frida-trace -U -m "*[*settings* *]/i" -M "*[*UI* *]" -M "*[FBSSceneSettings *]" Preferences) yields a lot of results:

250512 ms  -[BSSettings objectForSetting:0xf]
250512 ms     | -[BSSettingsDiff copyWithZone:0xf]
250512 ms     |    | -[BSSettings copyWithZone:0xf]
250512 ms     |    |    | -[BSKeyedSettings copyWithZone:0xf]
250513 ms  -[BSSettings objectForSetting:0x16]
250513 ms     | -[BSSettingsDiff copyWithZone:0x16]
250513 ms     |    | -[BSSettings copyWithZone:0x16]
250513 ms     |    |    | -[BSKeyedSettings copyWithZone:0x16]
250513 ms  -[BSSettings objectForSetting:0x23]
250513 ms     | -[BSSettingsDiff copyWithZone:0x23]
250513 ms     |    | -[BSSettings copyWithZone:0x23]
250513 ms     |    |    | -[BSKeyedSettings copyWithZone:0x23]
250514 ms  -[BSSettings objectForSetting:0x23]
250514 ms     | -[BSSettingsDiff copyWithZone:0x23]
250514 ms     |    | -[BSSettings copyWithZone:0x23]
250514 ms     |    |    | -[BSKeyedSettings copyWithZone:0x23]
250514 ms  -[BSSettings objectForSetting:0x19]
250514 ms     | -[BSSettingsDiff copyWithZone:0x19]
250514 ms     |    | -[BSSettings copyWithZone:0x19]
250514 ms     |    |    | -[BSKeyedSettings copyWithZone:0x19]
250514 ms  -[BSSettings objectForSetting:0x23]
250515 ms     | -[BSSettingsDiff copyWithZone:0x23]
250515 ms     |    | -[BSSettings copyWithZone:0x23]
250515 ms     |    |    | -[BSKeyedSettings copyWithZone:0x23]
250515 ms  -[BSSettings objectForSetting:0x19]
250515 ms     | -[BSSettingsDiff copyWithZone:0x19]
250515 ms     |    | -[BSSettings copyWithZone:0x19]
250515 ms     |    |    | -[BSKeyedSettings copyWithZone:0x19]
250516 ms  -[BSSettings objectForSetting:0x23]
250516 ms     | -[BSSettingsDiff copyWithZone:0x23]
250516 ms     |    | -[BSSettings copyWithZone:0x23]
250516 ms     |    |    | -[BSKeyedSettings copyWithZone:0x23]
250516 ms  -[BSSettings objectForSetting:0x23]
250516 ms     | -[BSSettingsDiff copyWithZone:0x23]
250516 ms     |    | -[BSSettings copyWithZone:0x23]
250517 ms     |    |    | -[BSKeyedSettings copyWithZone:0x23]
250517 ms  -[BSSettings objectForSetting:0x3]
250517 ms     | -[BSSettingsDiff copyWithZone:0x3]
250517 ms     |    | -[BSSettings copyWithZone:0x3]
250517 ms     |    |    | -[BSKeyedSettings copyWithZone:0x3]
250518 ms  -[BSSettings boolForSetting:0x1]
250518 ms     | -[BSSettingsDiff copyWithZone:0x1]
250518 ms     |    | -[BSSettings copyWithZone:0x1]
250518 ms     |    |    | -[BSKeyedSettings copyWithZone:0x1]
250518 ms  -[BSSettings objectForSetting:0x3]
250518 ms     | -[BSSettingsDiff copyWithZone:0x3]
250518 ms     |    | -[BSSettings copyWithZone:0x3]
250518 ms     |    |    | -[BSKeyedSettings copyWithZone:0x3]
250518 ms  -[BSSettings objectForSetting:0x3]
250519 ms     | -[BSSettingsDiff copyWithZone:0x3]
250519 ms     |    | -[BSSettings copyWithZone:0x3]
250519 ms     |    |    | -[BSKeyedSettings copyWithZone:0x3]
250519 ms  -[BSSettings boolForSetting:0x1]
250519 ms     | -[BSSettingsDiff copyWithZone:0x1]
250519 ms     |    | -[BSSettings copyWithZone:0x1]
250519 ms     |    |    | -[BSKeyedSettings copyWithZone:0x1]
250519 ms  -[BSSettings objectForSetting:0x3]
250519 ms     | -[BSSettingsDiff copyWithZone:0x3]
250519 ms     |    | -[BSSettings copyWithZone:0x3]
250519 ms     |    |    | -[BSKeyedSettings copyWithZone:0x3]
250520 ms  -[BSSettings objectForSetting:0x3]
250520 ms     | -[BSSettingsDiff copyWithZone:0x3]
250520 ms     |    | -[BSSettings copyWithZone:0x3]
250520 ms     |    |    | -[BSKeyedSettings copyWithZone:0x3]
250520 ms  -[BSSettings objectForSetting:0x3]
250520 ms     | -[BSSettingsDiff copyWithZone:0x3]
250520 ms     |    | -[BSSettings copyWithZone:0x3]
250520 ms     |    |    | -[BSKeyedSettings copyWithZone:0x3]
250520 ms  -[BSSettings boolForSetting:0x1]
250521 ms     | -[BSSettingsDiff copyWithZone:0x1]
250521 ms     |    | -[BSSettings copyWithZone:0x1]
250521 ms     |    |    | -[BSKeyedSettings copyWithZone:0x1]
250521 ms  -[BSSettings objectForSetting:0x3]
250521 ms     | -[BSSettingsDiff copyWithZone:0x3]
250521 ms     |    | -[BSSettings copyWithZone:0x3]
250521 ms     |    |    | -[BSKeyedSettings copyWithZone:0x3]
250521 ms  -[BSSettings objectForSetting:0x3]
250521 ms     | -[BSSettingsDiff copyWithZone:0x3]
250521 ms     |    | -[BSSettings copyWithZone:0x3]
250522 ms     |    |    | -[BSKeyedSettings copyWithZone:0x3]
250522 ms  -[BSSettings boolForSetting:0x1]
250522 ms     | -[BSSettingsDiff copyWithZone:0x1]
250522 ms     |    | -[BSSettings copyWithZone:0x1]
250522 ms     |    |    | -[BSKeyedSettings copyWithZone:0x1]
250522 ms  -[BSSettings objectForSetting:0x3]
250522 ms     | -[BSSettingsDiff copyWithZone:0x3]
250522 ms     |    | -[BSSettings copyWithZone:0x3]
250522 ms     |    |    | -[BSKeyedSettings copyWithZone:0x3]
250522 ms  -[BSSettings objectForSetting:0x3]
250522 ms     | -[BSSettingsDiff copyWithZone:0x3]
250522 ms     |    | -[BSSettings copyWithZone:0x3]
250522 ms     |    |    | -[BSKeyedSettings copyWithZone:0x3]
250523 ms  -[BSSettings objectForSetting:0x3]
250523 ms     | -[BSSettingsDiff copyWithZone:0x3]
250523 ms     |    | -[BSSettings copyWithZone:0x3]
250523 ms     |    |    | -[BSKeyedSettings copyWithZone:0x3]
250523 ms  -[BSSettings boolForSetting:0x1]
250523 ms     | -[BSSettingsDiff copyWithZone:0x1]
250523 ms     |    | -[BSSettings copyWithZone:0x1]
250523 ms     |    |    | -[BSKeyedSettings copyWithZone:0x1]
250523 ms  -[BSSettings objectForSetting:0x3]
250523 ms     | -[BSSettingsDiff copyWithZone:0x3]
250523 ms     |    | -[BSSettings copyWithZone:0x3]
250523 ms     |    |    | -[BSKeyedSettings copyWithZone:0x3]
250523 ms  -[BSSettings objectForSetting:0x3]
250523 ms     | -[BSSettingsDiff copyWithZone:0x3]
250523 ms     |    | -[BSSettings copyWithZone:0x3]
250524 ms     |    |    | -[BSKeyedSettings copyWithZone:0x3]
250524 ms  -[BSSettings boolForSetting:0x1]
250524 ms     | -[BSSettingsDiff copyWithZone:0x1]
250524 ms     |    | -[BSSettings copyWithZone:0x1]
250524 ms     |    |    | -[BSKeyedSettings copyWithZone:0x1]
250524 ms  -[BSSettings objectForSetting:0x3]
250524 ms     | -[BSSettingsDiff copyWithZone:0x3]
250524 ms     |    | -[BSSettings copyWithZone:0x3]
250524 ms     |    |    | -[BSKeyedSettings copyWithZone:0x3]
250524 ms  -[BSSettings objectForSetting:0x3]
250524 ms     | -[BSSettingsDiff copyWithZone:0x3]
250524 ms     |    | -[BSSettings copyWithZone:0x3]
250524 ms     |    |    | -[BSKeyedSettings copyWithZone:0x3]
250580 ms  -[BSSettings objectForSetting:0x3]
250580 ms     | -[BSSettingsDiff copyWithZone:0x3]
250580 ms     |    | -[BSSettings copyWithZone:0x3]
250580 ms     |    |    | -[BSKeyedSettings copyWithZone:0x3]
250580 ms  -[BSSettings boolForSetting:0x1]
250580 ms     | -[BSSettingsDiff copyWithZone:0x1]
250581 ms     |    | -[BSSettings copyWithZone:0x1]
250581 ms     |    |    | -[BSKeyedSettings copyWithZone:0x1]
250581 ms  -[BSSettings objectForSetting:0x3]
250581 ms     | -[BSSettingsDiff copyWithZone:0x3]
250581 ms     |    | -[BSSettings copyWithZone:0x3]
250581 ms     |    |    | -[BSKeyedSettings copyWithZone:0x3]
250581 ms  -[BSSettings objectForSetting:0x3]
250581 ms     | -[BSSettingsDiff copyWithZone:0x3]
250581 ms     |    | -[BSSettings copyWithZone:0x3]
250581 ms     |    |    | -[BSKeyedSettings copyWithZone:0x3]
250582 ms  -[BSSettings boolForSetting:0x1]
250582 ms     | -[BSSettingsDiff copyWithZone:0x1]
250582 ms     |    | -[BSSettings copyWithZone:0x1]
250582 ms     |    |    | -[BSKeyedSettings copyWithZone:0x1]
250582 ms  -[BSSettings objectForSetting:0x3]
250582 ms     | -[BSSettingsDiff copyWithZone:0x3]
250582 ms     |    | -[BSSettings copyWithZone:0x3]
250582 ms     |    |    | -[BSKeyedSettings copyWithZone:0x3]
250582 ms  -[BSSettings objectForSetting:0x3]
250583 ms     | -[BSSettingsDiff copyWithZone:0x3]
250583 ms     |    | -[BSSettings copyWithZone:0x3]
250583 ms     |    |    | -[BSKeyedSettings copyWithZone:0x3]
250593 ms  +[SFSettingsAnalytics trackingPerformSelector:0x28212bd40 targetString:0x282128fe0]
250593 ms  +[SFSettingsAnalytics trackingControlValueChanged:0x28212a680 sender:0x874033f1cd108b52]

BSSettings might be interesting or it might be some UI thing.

@baltpeter
Copy link
Member Author

The headers for BSettings don't exactly tell us much. It's part of BaseBoard.framework. The other classes in that framework do sound potentially interesting, though.

@zner0L
Copy link
Contributor

zner0L commented Mar 17, 2023

I think another thing to consider is the "Low power mode" in the battery settings. It might do similar things, it also claims to limit background activity.

@baltpeter baltpeter added the help wanted Extra attention is needed label Jun 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants