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

Android8 #148

Merged
merged 9 commits into from Sep 28, 2017
Merged

Android8 #148

merged 9 commits into from Sep 28, 2017

Conversation

user-none
Copy link
Contributor

As of Android 8 (Oreo) access to net.dns# has been removed (https://developer.android.com/about/versions/oreo/android-8.0-changes.html). The reasoning given is that it, "improves privacy on the platform". Currently c-ares uses this to get the list of DNS servers.

Now the only way to access the DNS server list is by using the Connectivity Manager though Java. This adds the necessary JNI code to use the Connectivity Manager and pull the DNS server list. The old way using __system_property_get with net.dns# remains for compatibilty.

Using the Connectivity Manager requires the ACCESS_NETWORK_STATE permission to be set on the app. Existing applications most likely are not setting this and keeping the previous method as a fallback will at the very least ensure those apps don't break on older versions of Android. They will need to add this permission for Android 8 compatibility.

Included in the patch are two initalization functions which are required. The JVM must be registered as well as the Connectivity Manager itself. There is no way to get the Connectivity Manager except though Java. Either being passed down to C directly or by passing in an Android Context which can be used to get the Connectivity Manager. Examples are provided in the documentation.

@user-none
Copy link
Contributor Author

Referencing issue #111

Copy link
Member

@bradh352 bradh352 left a comment

Choose a reason for hiding this comment

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

Looks good to me. Good man page.

ares_android.h Outdated

#endif

#endif /* __JNI_COMMON_H__ */
Copy link
Contributor

Choose a reason for hiding this comment

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

The header guard comment is not matching

@coveralls
Copy link

Coverage Status

Coverage remained the same at 95.382% when pulling f9ee0ee on user-none:android8 into 9ef37fe on c-ares:master.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 95.382% when pulling 67d056b on user-none:android8 into 9ef37fe on c-ares:master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.08%) to 95.46% when pulling 67d056b on user-none:android8 into 9ef37fe on c-ares:master.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 95.382% when pulling 67d056b on user-none:android8 into 9ef37fe on c-ares:master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.08%) to 95.46% when pulling 67d056b on user-none:android8 into 9ef37fe on c-ares:master.

@bradh352
Copy link
Member

@bagder @daviddrysdale any feedback on this PR?

}
if (res != JNI_OK || env == NULL)
goto done;

Copy link
Member

Choose a reason for hiding this comment

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

Idle thought: it might be helpful to add a block comment here with the equivalent Java code to the JNI stuff below.

/* 
JNI invocations below are intended to recreate the following Java snippet:
import android.net.ConnectivityManager
import android.net.LinkProperties
import java.util.List
import java.net.InetAddress
...
NetworkInfo active_network = connMgr.getActiveNetwork();
LinkProperties link_properties = connMgr.getLinkProperties(active_network);
List<InetAddress> server_list = props.getDnsServers();
for (int i = 0; i < server_list.size(); i++ {
  InetAddress server = server_list.get(i);
  String str = server.getHostAddress()
  // append str to results
}
*/

}
.Ed
.SH AVAILABILITY
This function was first introduced in c-ares version 1.?.?.
Copy link
Member

Choose a reason for hiding this comment

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

I suspect we'll forget to come back and update this, so maybe fill it in as 1.14.0 as a best guess?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, please make a best guess to cover for us missing to update this later... =)

be present in the Android application.
.PP
Android older than 8 do not need to to be initalized as they
are less restritive. However, this is a run time not compile time
Copy link
Member

Choose a reason for hiding this comment

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

"restrictive"

@daviddrysdale
Copy link
Member

Looks good as far as I can tell -- I don't really speak Java nor Android. It does look safe for not affecting any other platforms or existing code, which is nicely reassuring.

Thanks!

@bagder
Copy link
Member

bagder commented Sep 28, 2017

I'll just second @daviddrysdale here as I don't speak any of those lingos either. It would be useful to get feedback from another actual Android user on this approach, but lacking that I think we can proceed with this PR as suggested.

@user-none
Copy link
Contributor Author

I corrected the typo and added the equivelent Java code as an example.

@bradh352 bradh352 merged commit 1abf13e into c-ares:master Sep 28, 2017
@coveralls
Copy link

Coverage Status

Coverage remained the same at 95.382% when pulling 6dfd6d6 on user-none:android8 into 9ef37fe on c-ares:master.

DronRathore pushed a commit to DronRathore/c-ares that referenced this pull request Mar 11, 2020
… access to net.dns# system properties. (c-ares#148)

As of Android 8 (Oreo) access to net.dns# has been removed (https://developer.android.com/about/versions/oreo/android-8.0-changes.html). The reasoning given is that it, "improves privacy on the platform". Currently c-ares uses this to get the list of DNS servers.

Now the only way to access the DNS server list is by using the Connectivity Manager though Java. This adds the necessary JNI code to use the Connectivity Manager and pull the DNS server list. The old way using __system_property_get with net.dns# remains for compatibilty.

Using the Connectivity Manager requires the ACCESS_NETWORK_STATE permission to be set on the app. Existing applications most likely are not setting this and keeping the previous method as a fallback will at the very least ensure those apps don't break on older versions of Android. They will need to add this permission for Android 8 compatibility.

Included in the patch are two initalization functions which are required. The JVM must be registered as well as the Connectivity Manager itself. There is no way to get the Connectivity Manager except though Java. Either being passed down to C directly or by passing in an Android Context which can be used to get the Connectivity Manager. Examples are provided in the documentation.
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.

None yet

6 participants