Skip to content

Request battery optimization exemption to prevent low-memory kills#1639

Closed
syphyr wants to merge 1 commit intoguardianproject:masterfrom
syphyr:battery_opt
Closed

Request battery optimization exemption to prevent low-memory kills#1639
syphyr wants to merge 1 commit intoguardianproject:masterfrom
syphyr:battery_opt

Conversation

@syphyr
Copy link
Copy Markdown
Contributor

@syphyr syphyr commented Mar 11, 2026

Orbot should always request battery optimization exemption to prevent low-memory kills. If Orbot is killed by low-memory, this can expose the users real IP address when not using power user mode.

Orbot's VPN mode and Power User Mode also require uninterrupted operation. Even transient SOCKS/HTTP proxy usage suffers from battery-killed circuits. Tor circuit rebuilds are also much faster when not restricted by battery optimizations.

@bitmold
Copy link
Copy Markdown
Collaborator

bitmold commented Mar 14, 2026

This is a start, but it might be possible to return tor to running in its own process. If this happens, being a VPN should prevent the main app process from being disconnected from the priviliged VPNService process.

Otherwise, this is regrettable, but necessary... If we want to merge this, I want there to be UI wrapped around it and not something that the user is immediately nudged with every time they open the app, especially on first launch.

Not merging this yet, but not closing either. Will update here soon...

@syphyr
Copy link
Copy Markdown
Contributor Author

syphyr commented Mar 16, 2026

@bitmold I have reworked the commit to use a toggle to enable/disable the battery optimization exemption request. From my testing, I have noticed a few things with this:

There appears to be a known issue with Android's battery optimization system. The problem stems from how Android handles repeated changes to battery optimization exemptions for the same process.

  1. After removing then re-adding battery optimization exemption, the system doesn't properly recognize subsequent changes
  2. The workaround involves:
    • Fully stopping the Orbot process
    • Clearing the app's task stack
    • Only then attempting to modify battery optimization settings again

The underlying cause seems to be that Android maintains some internal state about optimization exemptions that doesn't properly reset without a full process termination.

@syphyr
Copy link
Copy Markdown
Contributor Author

syphyr commented Mar 16, 2026

Although, I have noticed that when the battery optimization exemption is enabled, Orbot does not crash with that tor_raw_abort message under heavy load anymore.

@bitmold
Copy link
Copy Markdown
Collaborator

bitmold commented Mar 16, 2026

I'll discuss this with Nathan tomorrow. When you say "Android" do you mean on Nougat/API 24 as you often seem to be using that version.

In any case, just noting it's likely that the battery exemption and your observations may behave differently on different versions of Android.

This is all very interesting though... Will update you more here after discussing...

@syphyr
Copy link
Copy Markdown
Contributor Author

syphyr commented Mar 16, 2026

I'm testing with cm-14.1 (nougat).

@tladesignz tladesignz mentioned this pull request Mar 25, 2026
@syphyr
Copy link
Copy Markdown
Contributor Author

syphyr commented Mar 25, 2026

This PR is superseded by #1648

@syphyr syphyr closed this Mar 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants