Skip to content

Conversation

thromer
Copy link

@thromer thromer commented Sep 26, 2025

  • Add getDefaultProfile and setDefaultProfile API methods and intents.
  • Add example usage of both to remoteExample.
  • Bring the two copies of IOpenVPNAPIService.aidl and of APIVpnProfile.java into sync.

Fixes #1857.

* setDefaultProfile takes UUID, not name
* added getDefaultProfile
* added sample usage to remoteExample
* brought remoteExample/.../IOpenVPNAPIService.aidl into sync with main/...
@thromer
Copy link
Author

thromer commented Sep 26, 2025

Works for me, but of course I won't take anything for granted. If you're able to take a look that would be great.


}

private APIVpnProfile newAPIVpnProfile(VpnProfile vp) {
Copy link
Owner

Choose a reason for hiding this comment

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

Should be named rather something like APIVPNProfileFromVPNProfile or even better have a static method in APIVpnProfile like constructFromVPNProfile

Copy link
Author

@thromer thromer Sep 28, 2025

Choose a reason for hiding this comment

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

The static method would be ideal except then there would have to be a dependency in APIVPNProfile on the implementation class VPNProfile, though. So I renamed to apiVPNProfileFromVPNProfile, in order to have the method name start with a lower case letter. (Google style guide would have us write use "Vpn" and "vpn" everywhere but we're not following that in any case). Not attached to the name.

I did notice that the two copies of APIVpnProfile.java were out of sync so I updated those. Notably, the copyright notices were different.


@Override
public APIVpnProfile getDefaultProfile() throws RemoteException {
ProfileManager pm = ProfileManager.getInstance(getBaseContext());
Copy link
Owner

Choose a reason for hiding this comment

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

Missing permission check.

Copy link
Author

Choose a reason for hiding this comment

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

Done

}
break;
case ".api.SetDefaultVPN":
String defaultVpnName = intent.getStringExtra(EXTRA_NAME);
Copy link
Owner

Choose a reason for hiding this comment

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

This case is quite long, better to put into into its own method.

Copy link
Author

Choose a reason for hiding this comment

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

Moved the bodies of the two long cases into new methods.

* This file is used for implementing the external API and this file like the AIDL and is exempted
* from the GPLv2.
*
*/
Copy link
Author

Choose a reason for hiding this comment

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

@schwabe Note that I updated the copyright notice in remoteExample/.../APIVpnProfile.java to match main/.../APIVpnProfile.java.

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.

FR: Add ability to set default VPN profile through API

2 participants