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

[Android] Listen to default network changes #23059

Merged
merged 3 commits into from
May 19, 2023

Conversation

joseluismarti
Copy link
Contributor

Description

All apps in a device use a default network, which is determined by the system. The network that is set as the default can change at any time. A typical example is the device coming within range of a known Wi-Fi access point. The device disconnects from the mobile network, connects to the access point and switches the default network.

The purpose of this PR is that Kodi listens to network status changes, so that if the device changes the default network, the app will do so as well.

To receive notifications of network events, use the NetworkCallback class together with
ConnectivityManager.registerDefaultNetworkCallback(NetworkCallback)

The CNetworkAndroid class will always keep the reference to the default network.

Depends on xbmc/libandroidjni#46

Types of change

  • Bug fix (non-breaking change which fixes an issue)
  • Clean up (non-breaking change which removes non-working, unmaintained functionality)
  • Improvement (non-breaking change which improves existing functionality)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that will cause existing functionality to change)
  • Cosmetic change (non-breaking change that doesn't touch code)
  • None of the above (please explain below)

Checklist:

  • My code follows the Code Guidelines of this project
  • My change requires a change to the documentation, either Doxygen or wiki
  • I have updated the documentation accordingly
  • I have read the Contributing document
  • I have added tests to cover my change
  • All new and existing tests passed

@enen92 enen92 added Type: Improvement non-breaking change which improves existing functionality Platform: Android v21 Omega Component: Network labels Mar 26, 2023
@enen92 enen92 added this to the Omega 21.0 Alpha 1 milestone Mar 26, 2023
@jenkins4kodi jenkins4kodi added the Rebase needed PR that does not apply/merge cleanly to current base branch label May 11, 2023
@jenkins4kodi jenkins4kodi removed the Rebase needed PR that does not apply/merge cleanly to current base branch label May 11, 2023
{
CJNINetworkInterface intf = CJNINetworkInterface::getByName(lp.getInterfaceName());
if (intf)
m_defaultInterface = new CNetworkInterfaceAndroid(n, lp, intf);
Copy link
Contributor

@lrusak lrusak May 13, 2023

Choose a reason for hiding this comment

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

I don't see a delete to this new. Maybe use std::unique_ptr instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've tried, but this class is common to all platforms and copy operations are done in other parts of the code... with a delete would be fine

Copy link
Contributor

Choose a reason for hiding this comment

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

Since m_defaultInterface is local to this class I don't see a problem. You can use .get() to return the raw pointer in functions that need CNetworkInteface*

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried again as you indicated and it works, please tell me if I forgot anything, thanks

@enen92
Copy link
Member

enen92 commented May 14, 2023

Good to go?

@joseluismarti
Copy link
Contributor Author

Looks good to me

@enen92 enen92 merged commit aefcb83 into xbmc:master May 19, 2023
2 checks passed
@joseluismarti joseluismarti deleted the NetworkCallback branch May 19, 2023 13:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Network Platform: Android Type: Improvement non-breaking change which improves existing functionality v21 Omega
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants