Skip to content

Battery opt disable#1648

Merged
bitmold merged 5 commits intomasterfrom
battery-opt-disable
Apr 2, 2026
Merged

Battery opt disable#1648
bitmold merged 5 commits intomasterfrom
battery-opt-disable

Conversation

@bitmold
Copy link
Copy Markdown
Collaborator

@bitmold bitmold commented Mar 24, 2026

While I still do feel that for most users running most builds of Android 30+ setting "Always-on VPN" solves the problem of needing to exempt your app from battery optimizations, this setting is being added for users who, for whatever reason, absolutely need to force Orbot to stay open no matter what level of OS/Device/Vendor/API Level/etc, etc they may be running...

This work is loosely inspired off of #1639 which brought this issue to our attention.

There are now two ways to disable battery optimizations:

1. The Passive Approach, Allows Any User to Disable Optimizations From Orbot's Settings

A new item for disabling battery optimizations is added to the settings, which the user can access whenever they want.
The rhetoric around disabling battery optimizations through this path is a bit tedious - this is to ensure that users don't mistakenly set disable this reasonable system default when they don't need to. This pathway to disabling battery optimizations is primarily there for users who know they need it, or for users who through a support channel are instructed to turn off battery optimizations for whatever reason...

It looks like this:
Screenshot From 2026-03-24 12-33-56

Clicking it opens a dialog (the last sentence in the dialog updates depending on if the user has battery optimizations for Orbot or not).

  • It's longwinded, again my intention is to discourage the average user - who, as far as I'm aware, generally does not need to disable battery optimizations - from accidentally setting and forgetting this setting which would effectively lower their overall user experience in exchange for nothing
  • Also, in this flow, we try to divert the user into setting up Orbot as an Always-On VPN. The type of user who is genuinely concerned with Orbot silently being killed while they use their device ought to be very satisfied with the privileging the system bestows onto always-on VPNs. My assumption is that many users may think that they want to disable battery optimizations, but in reality what they actually desire is the simplicity and security of combining Android's always-on VPN + with the block connections without VPN killswitch. Of course, there is nothing stopping a user from using both always-on VPNs with disabled battery optimizations.
Screenshot From 2026-03-24 13-06-52

If the user decides to disable battery optimizations, they have to click through several Android settings screens to disable battery optimizations. And they may go back to re-enable them the same way. (note: these settings may look different across different Android versions)
Screenshot From 2026-03-24 12-45-00
image

And on screen 3, it's disabled 🏴 🪫 🥷 🏴 🪫 🥷 🏴 🪫 🥷
Screenshot From 2026-03-24 12-46-57

2. A More Direct Approach, Directly Disable Background Optimizations in Power User Mode

For users with power user mode enabled, OrbotService is configured to stay running indefinitely in the background. However across all the various devices we support, I'm assuming that it's more likely for certain systems to kill a longrunning background service that's not acting as a VPNService.

If you start Tor in Power User mode, you are given this dialog which explains that you have to disable battery optimizations. When you use Orbot as a VPN disabling battery optimizations is optional and stays hidden in the settings, but in power user mode it's required in order to start Tor.

image

Clicking it opens this System dialog, where if you click "Allow" Orbot automatically is marked as unrestricted.
Screenshot From 2026-03-24 13-28-27

Instead of making them dig through menus, power users are confronted with a dialog that directly sets Orbot to be unrestricted. This system dialog requires a pretty ugly permission, but luckily we already have it due to having previously nudged users into disabling battery optimizations many years ago in a way that was directed @ supporting users who host long running onion services via Orbot.

@bitmold bitmold requested review from n8fr8 and tladesignz March 24, 2026 17:31
@syphyr
Copy link
Copy Markdown
Contributor

syphyr commented Mar 24, 2026

The dialog given when starting power user mode makes it seem like disabling battery optimizations is a requirement for everyone using power user mode. I think this would be best explained only when enabling the battery exemption in the settings, not always forcing battery optimization exemption while using power user mode.

Copy link
Copy Markdown
Collaborator

@tladesignz tladesignz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks all very reasonable to me. I stumbled over an unrelated typo. You might fix it with this PR or outside. Your choice.


// remove accent marks and characters from a String, useful when searching
fun String.normalizie() : String =
fun String.normalizie(): String =
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpicking: While at it, can you fix that typo?

@tladesignz
Copy link
Copy Markdown
Collaborator

The dialog given when starting power user mode makes it seem like disabling battery optimizations is a requirement for everyone using power user mode. I think this would be best explained only when enabling the battery exemption in the settings, not always forcing battery optimization exemption while using power user mode.

AFAIU, there's VPN mode, where most all Android versions and distributions will leave the app / the VPN process alone anyway.

But when in power user mode, (so not using VPN entitlements), many Android versions and distributions exhibit a high chance of killing the service somewhere in between to save battery.

Is there a third scenario?

@syphyr
Copy link
Copy Markdown
Contributor

syphyr commented Mar 25, 2026

The dialog given when starting power user mode makes it seem like disabling battery optimizations is a requirement for everyone using power user mode. I think this would be best explained only when enabling the battery exemption in the settings, not always forcing battery optimization exemption while using power user mode.

AFAIU, there's VPN mode, where most all Android versions and distributions will leave the app / the VPN process alone anyway.

But when in power user mode, (so not using VPN entitlements), many Android versions and distributions exhibit a high chance of killing the service somewhere in between to save battery.

Is there a third scenario?

There may be some devices already using power user mode without any issues so it would not be favorable to force battery optimization exception on them. This is why I suggest a preference for that.

@syphyr
Copy link
Copy Markdown
Contributor

syphyr commented Mar 25, 2026

I suppose the next question is, should forcing battery optimization exemption on power user mode be opt-in or opt-out.

@bitmold
Copy link
Copy Markdown
Collaborator Author

bitmold commented Apr 2, 2026

I'm applying the small corrections you all have made.

You have a point @syphyr, I changed the dialog to be like this:
image

@bitmold bitmold merged commit 1f48c61 into master Apr 2, 2026
@bitmold bitmold deleted the battery-opt-disable branch April 2, 2026 12:22
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