Say, I have a profile which is always connected to VPN (Block connection w/o VPN enabled), and I also would like to keep it running to let apps on it to sync messages, receive email, etc. However, once I switch profile, the VPN goes off after a while (it is not immediate, and I cannot pinpoint when this occurs from some simple tests I've tried), cutting off all connections in that profile, and ultimately stopping everything in it from syncing. I tried setting that VPN to 'Unrestricted', but this issue persists. How do I prevent a VPN from stopping in a profile that is not currently in use, if it is possible? I would appreciate if you assumed keeping that profile active is not an option, and battery consumption is negligible.

While I want to keep the VPN in question a general one, I'm open to a workaround using a specific VPN app/provider.

This is something I want to know too. Thanks for sharing!

Really? I've kept my VPN on in an active profile while using another and have never seen any evidence that the VPN had disconnected. How did you determine the VPN disconnected?

I've had other profiles active as long as overnight and still received all of my notifications, meaning the VPN had to have been active the whole time. I use ProtonVPN, btw, but I've also used Mullvad and it remained connected as well. I regularly keep my "personal" profile active while using other profiles for games and such, sometimes connected to other VPNs or using the same VPN provider, but a separate connection.

Based on my experience, this isn't expected behavior. Maybe others have better ideas/suggestions. I'll admit my ideas are all farfetched for different reasons, but I'll suggest them anyway.

First, you're sure you didn't end the profile's session? Like you log in to the VPN profile, then switch to the other profile? Based on your description, this probably isn't the cause since you say it takes some amount of time and mentioned battery consumption before you see evidence that the VPN has disconnected.

Second, are you sure the VPN you're connecting to doesn't have time or connection limits? Maybe the VPN server terminates the connection on you if you connect again in another profile. Like Mullvad limits accounts to 5 devices. Possibly you've used up your allotted connections and end up being kicked from the server? Honestly, I wouldn't expect this to be the reason unless you're testing a free VPN.

Third, maybe the VPN app you're using has some kind of issue. Maybe the app is trying to switch servers for a faster server and fails or has a poorly designed internet kill switch? If the app does have an internet kill switch (unlikely), that can be safely turned off since the OS does that automatically. To test if the app is what's causing the issue, maybe you can try using the Wireguard or OpenVPN official apps temporarily to connect to your VPN provider instead to see if you continue to experience this issue.

    unwat
    Thank you for the reply. I determined that the VPN was disconnected through:

    1. Checking progress on downloading files, which is definitely way behind what it should be,
    2. Not being able to receive notifications on such profiles after sending messages to them, and
    3. Simply going back to that profile, and seeing those "Disconnected from always-on VPN" notification on the screen

    I switch my profiles by swiping down the notification bar, then swiping down again to reveal the "Select user" button. If there's another (proper) way of switching profiles, I am interested. I am certain that the second and third points are inapplicable, since I also tried with Mullvad, and there's only one connection.

    Is it possible that the profile in the background gets killed altogether because of battery optimization or low memory?

      lemonadehabitat

      Only if setting battery usage to unrestricted and allowing unrestricted data in special config still lets Android to kill it after a while.
      In terms of lack of memory, I do not know. How do I prevent an app getting killed for lack of memory? I will test that.

      I should've noticed this earlier, but it seems that it's not just VPN that gets shut down after a while, it includes everything. When I switch away from a profile with certain apps open, and come back to it, I have to reopen apps as if they were never open prior. So how do I prevent profiles from being shut down automatically?

      I think I figured out the issue: https://discuss.grapheneos.org/d/292-work-profile-and-the-limit-of-active-profiles/10

      I have more than 3 profiles, all of which I regularly cycle through. Since owner profile always count towards this limit, it's effectively 2 profiles plus owner that can stay active at the same time (i.e. no "Unlock with passcode after restarting your phone"), which is why VPN was kept getting shut down once I open a third profile. Because this is hard limit, I am guessing this won't change any time soon. Nevermind, post in link suggests that there may be increase in this limit due to 3rd gen being cycled out. Are there any updates regarding lifting this limit?