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

x/mobile: fix net.Interface() and net.InterfaceAddrs() in Android11 version #61089

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

wlynxg
Copy link

@wlynxg wlynxg commented Jun 30, 2023

For #40569
Fix: In response to the modifications made to the permissions for accessing system MAC addresses in Android 11, ordinary applications encounter several main issues when using NETLINK sockets:

  • Not allowing bind operations on NETLINK sockets.
  • Not permitting the use of the RTM_GETLINK functionality.

For detailed information, please refer to: https://developer.android.com/training/articles/user-data-ids#mac-11-plus

As a result of the aforementioned reasons, using net.Interfaces() and net.InterfaceAddrs() from the Go net package in the Android environment leads to the route ip+net: netlinkrib: permission denied error.

You can find specific issue details here: #40569

To address the issue of using the Go net package in the Android environment, we have made partial modifications to its source code to ensure proper functionality on Android.

I have fully resolved the issues with net.InterfaceAddrs().

However, for net.Interfaces(), we have only addressed some problems, as the following issues still remain:

  • It can only return interfaces with IP addresses.
  • It cannot return hardware MAC addresses.

Nevertheless, the fixed net.Interfaces() function now aligns with the Android API's NetworkInterface.getNetworkInterfaces() and can be used normally in most scenarios.

The specific fix logic includes:

Removing the Bind() operation on Netlink sockets in the NetlinkRIB() function.
Using ioctl based on the Index number returned by RTM_GETADDR to retrieve the network card's name, MTU, and flags.

Test Code

This part of the test code must be compiled into a jar and aar package that can be used under the Android 11 platform using gomobile

use net.InterfaceAddrs() :

func NetInterfaceAddrs() {
	addrs, err := net.InterfaceAddrs()
	if err != nil {
		panic(err)
	}

	for _, addr := range addrs {
		log.Println(addr)
	}
}

result:

127.0.0.1/8
::1/128
...
192.168.6.143/24
fe80::7e4f:4446:eb3:1eb8/64

use net.Interfaces() :

func NetInterface() {
	interfaces, err := net.Interfaces()
	if err != nil {
		panic(err)
	}

	for _, i := range interfaces {
		log.Println(i)
	}
}

result:

{1 65536 lo  up|loopback|running}
{15 1400 rmnet_data1  up|running}
{24 1500 wlan0  up|broadcast|multicast|running}
{3 1500 dummy0  up|broadcast|running}
{4 1500 ifb0  up|broadcast|running}
{5 1500 ifb1  up|broadcast|running}
{12 1500 ifb2  up|broadcast|running}
{14 1500 rmnet_data0  up|running}
{16 1400 rmnet_data2  up|running}
{17 1400 rmnet_data3  up|running}

@gopherbot
Copy link
Contributor

This PR (HEAD: 1012c07) has been imported to Gerrit for code review.

Please visit https://go-review.googlesource.com/c/go/+/507415 to see it.

Tip: You can toggle comments from me using the comments slash command (e.g. /comments off)
See the Wiki page for more info

@gopherbot
Copy link
Contributor

Message from Gopher Robot:

Patch Set 1:

Congratulations on opening your first change. Thank you for your contribution!

Next steps:
A maintainer will review your change and provide feedback. See
https://go.dev/doc/contribute#review for more info and tips to get your
patch through code review.

Most changes in the Go project go through a few rounds of revision. This can be
surprising to people new to the project. The careful, iterative review process
is our way of helping mentor contributors and ensuring that their contributions
have a lasting impact.

During May-July and Nov-Jan the Go project is in a code freeze, during which
little code gets reviewed or merged. If a reviewer responds with a comment like
R=go1.11 or adds a tag like "wait-release", it means that this CL will be
reviewed as part of the next development cycle. See https://go.dev/s/release
for more details.


Please don’t reply on this GitHub thread. Visit golang.org/cl/507415.
After addressing review feedback, remember to publish your drafts!

@wlynxg wlynxg changed the title fix: get network card interface in Android 11 environment 发、ix net.Interface() and net.InterfaceAddrs() in Android11 version Jul 2, 2023
@wlynxg wlynxg changed the title 发、ix net.Interface() and net.InterfaceAddrs() in Android11 version x/mobile: fix net.Interface() and net.InterfaceAddrs() in Android11 version Jul 2, 2023
@gopherbot
Copy link
Contributor

This PR (HEAD: a64399c) has been imported to Gerrit for code review.

Please visit https://go-review.googlesource.com/c/go/+/507415 to see it.

Tip: You can toggle comments from me using the comments slash command (e.g. /comments off)
See the Wiki page for more info

@gopherbot
Copy link
Contributor

Message from wei liu:

Patch Set 3: Code-Review+1


Please don’t reply on this GitHub thread. Visit golang.org/cl/507415.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

Message from Zoltan Papp:

Patch Set 3:

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/507415.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

Message from Chih-Hsuan Yen:

Patch Set 3:

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/507415.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

Message from GM K:

Patch Set 3:

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/507415.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

This PR (HEAD: ad4f8ff) has been imported to Gerrit for code review.

Please visit Gerrit at https://go-review.googlesource.com/c/go/+/507415.

Important tips:

  • Don't comment on this PR. All discussion takes place in Gerrit.
  • You need a Gmail or other Google account to register for Gerrit.
  • To change your code in response to feedback:
    • Push a new commit to the branch used by your GitHub PR.
    • A new "patch set" will then appear in Gerrit.
    • Respond to each comment by marking as Done in Gerrit if implemented as suggested. You can alternatively write a reply.
    • Critical: you must click the blue Reply button near the top to publish your Gerrit responses.
    • Multiple commits in the PR will be squashed by GerritBot.
  • The title and description of the GitHub PR are used to construct the final commit message.
    • Edit these as needed via the GitHub web interface (not via Gerrit or git).
    • You should word wrap the PR description at ~76 characters unless you need longer lines (e.g., for tables or URLs).
  • See the Sending a change via GitHub and Reviews sections of the Contribution Guide as well as the FAQ for details.

@gopherbot
Copy link
Contributor

Message from Marcin Mazurek:

Patch Set 4:

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/507415.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

This PR (HEAD: bff8d40) has been imported to Gerrit for code review.

Please visit Gerrit at https://go-review.googlesource.com/c/go/+/507415.

Important tips:

  • Don't comment on this PR. All discussion takes place in Gerrit.
  • You need a Gmail or other Google account to log in to Gerrit.
  • To change your code in response to feedback:
    • Push a new commit to the branch used by your GitHub PR.
    • A new "patch set" will then appear in Gerrit.
    • Respond to each comment by marking as Done in Gerrit if implemented as suggested. You can alternatively write a reply.
    • Critical: you must click the blue Reply button near the top to publish your Gerrit responses.
    • Multiple commits in the PR will be squashed by GerritBot.
  • The title and description of the GitHub PR are used to construct the final commit message.
    • Edit these as needed via the GitHub web interface (not via Gerrit or git).
    • You should word wrap the PR description at ~76 characters unless you need longer lines (e.g., for tables or URLs).
  • See the Sending a change via GitHub and Reviews sections of the Contribution Guide as well as the FAQ for details.

@vikulin
Copy link

vikulin commented May 25, 2024

This PR (HEAD: bff8d40) has been imported to Gerrit for code review.

Please visit Gerrit at https://go-review.googlesource.com/c/go/+/507415.

Important tips:

* Don't comment on this PR. All discussion takes place in Gerrit.

* You need a Gmail or other Google account to [log in to Gerrit](https://go-review.googlesource.com/login/).

* To change your code in response to feedback:
  
  * Push a new commit to the branch used by your GitHub PR.
  * A new "patch set" will then appear in Gerrit.
  * Respond to each comment by marking as **Done** in Gerrit if implemented as suggested. You can alternatively write a reply.
  * **Critical**: you must click the [blue **Reply** button](https://go.dev/wiki/GerritBot#i-left-a-reply-to-a-comment-in-gerrit-but-no-one-but-me-can-see-it) near the top to publish your Gerrit responses.
  * Multiple commits in the PR will be squashed by GerritBot.

* The title and description of the GitHub PR are used to construct the final commit message.
  
  * Edit these as needed via the GitHub web interface (not via Gerrit or git).
  * You should word wrap the PR description at ~76 characters unless you need longer lines (e.g., for tables or URLs).

* See the [Sending a change via GitHub](https://go.dev/doc/contribute#sending_a_change_github) and [Reviews](https://go.dev/doc/contribute#reviews) sections of the Contribution Guide as well as the [FAQ](https://go.dev/wiki/GerritBot/#frequently-asked-questions) for details.

@gopherbot with all respect but last activity in Gerrit was at Oct 19, 2023. I assume that work was suspended.

@vikulin
Copy link

vikulin commented May 25, 2024

Any updates?

@wlynxg
Copy link
Author

wlynxg commented May 25, 2024

Any updates? 

I think the go official team may not accept this PR, because this fix may become invalid with later Android updates, and it may be too troublesome for the go team to maintain such a changing system problem. My suggestion is that you can use my third-party library or compile Go yourself to resolve this bug.

@vikulin
Copy link

vikulin commented May 25, 2024

@wlynxg could you please provide a link to the 3party lib?

@wlynxg
Copy link
Author

wlynxg commented May 25, 2024

@wlynxg could you please provide a link to the 3party lib?

https://github.com/wlynxg/anet

@vikulin
Copy link

vikulin commented May 25, 2024

@wlynxg could you please provide a link to the 3party lib?

https://github.com/wlynxg/anet

Good job!

@vikulin
Copy link

vikulin commented Jun 15, 2024

Unfortunately I'm unable to verify this fix since gomobile broken in go1.20 and above.

@vikulin
Copy link

vikulin commented Jun 17, 2024

@wlynxg could you please provide a link to the 3party lib?

https://github.com/wlynxg/anet

The fix did not work for me: I got permission denied error in Android logs:

2024-06-17 14:38:47.641 15709-15792 GoLog                   org.rivchain.cuplink                 I  Failed up get addresses for interface wlan0: route ip+net: netlinkrib: permission denied
2024-06-17 14:38:47.637 15709-15709 ivchain.cuplink         org.rivchain.cuplink                 W  type=1400 audit(0.0:1139327): avc:  denied  { bind } for  scontext=u:r:untrusted_app:s0:c178,c257,c512,c768 tcontext=u:r:untrusted_app:s0:c178,c257,c512,c768 tclass=netlink_route_socket permissive=0 bug=b/155595000 app=org.rivchain.cuplink
2024-06-17 14:38:48.647 15709-15770 GoLog                   org.rivchain.cuplink                 I  Failed up get addresses for interface wlan0: route ip+net: netlinkrib: permission denied
2024-06-17 14:38:48.645 15709-15709 ivchain.cuplink         org.rivchain.cuplink                 W  type=1400 audit(0.0:1139328): avc:  denied  { bind } for  scontext=u:r:untrusted_app:s0:c178,c257,c512,c768 tcontext=u:r:untrusted_app:s0:c178,c257,c512,c768 tclass=netlink_route_socket permissive=0 bug=b/155595000 app=org.rivchain.cuplink
2024-06-17 14:38:49.658 15709-15770 GoLog                   org.rivchain.cuplink                 I  Failed up get addresses for interface wlan0: route ip+net: netlinkrib: permission denied

I have changed the net to anet package.

@wlynxg
Copy link
Author

wlynxg commented Jun 17, 2024

@wlynxg could you please provide a link to the 3party lib?

https://github.com/wlynxg/anet

The fix did not work for me: I got permission denied error in Android logs:

2024-06-17 14:38:47.641 15709-15792 GoLog                   org.rivchain.cuplink                 I  Failed up get addresses for interface wlan0: route ip+net: netlinkrib: permission denied
2024-06-17 14:38:47.637 15709-15709 ivchain.cuplink         org.rivchain.cuplink                 W  type=1400 audit(0.0:1139327): avc:  denied  { bind } for  scontext=u:r:untrusted_app:s0:c178,c257,c512,c768 tcontext=u:r:untrusted_app:s0:c178,c257,c512,c768 tclass=netlink_route_socket permissive=0 bug=b/155595000 app=org.rivchain.cuplink
2024-06-17 14:38:48.647 15709-15770 GoLog                   org.rivchain.cuplink                 I  Failed up get addresses for interface wlan0: route ip+net: netlinkrib: permission denied
2024-06-17 14:38:48.645 15709-15709 ivchain.cuplink         org.rivchain.cuplink                 W  type=1400 audit(0.0:1139328): avc:  denied  { bind } for  scontext=u:r:untrusted_app:s0:c178,c257,c512,c768 tcontext=u:r:untrusted_app:s0:c178,c257,c512,c768 tclass=netlink_route_socket permissive=0 bug=b/155595000 app=org.rivchain.cuplink
2024-06-17 14:38:49.658 15709-15770 GoLog                   org.rivchain.cuplink                 I  Failed up get addresses for interface wlan0: route ip+net: netlinkrib: permission denied

I have changed the net to anet package.

If you are willing to provide your minimum executable code, I will be happy to help you solve the problem. You can send it directly to me through the email address on my homepage.

@vikulin
Copy link

vikulin commented Jun 17, 2024

@wlynxg could you please provide a link to the 3party lib?

https://github.com/wlynxg/anet

The fix did not work for me: I got permission denied error in Android logs:

2024-06-17 14:38:47.641 15709-15792 GoLog                   org.rivchain.cuplink                 I  Failed up get addresses for interface wlan0: route ip+net: netlinkrib: permission denied
2024-06-17 14:38:47.637 15709-15709 ivchain.cuplink         org.rivchain.cuplink                 W  type=1400 audit(0.0:1139327): avc:  denied  { bind } for  scontext=u:r:untrusted_app:s0:c178,c257,c512,c768 tcontext=u:r:untrusted_app:s0:c178,c257,c512,c768 tclass=netlink_route_socket permissive=0 bug=b/155595000 app=org.rivchain.cuplink
2024-06-17 14:38:48.647 15709-15770 GoLog                   org.rivchain.cuplink                 I  Failed up get addresses for interface wlan0: route ip+net: netlinkrib: permission denied
2024-06-17 14:38:48.645 15709-15709 ivchain.cuplink         org.rivchain.cuplink                 W  type=1400 audit(0.0:1139328): avc:  denied  { bind } for  scontext=u:r:untrusted_app:s0:c178,c257,c512,c768 tcontext=u:r:untrusted_app:s0:c178,c257,c512,c768 tclass=netlink_route_socket permissive=0 bug=b/155595000 app=org.rivchain.cuplink
2024-06-17 14:38:49.658 15709-15770 GoLog                   org.rivchain.cuplink                 I  Failed up get addresses for interface wlan0: route ip+net: netlinkrib: permission denied

I have changed the net to anet package.

If you are willing to provide your minimum executable code, I will be happy to help you solve the problem. You can send it directly to me through the email address on my homepage.

Thank you for your so quick reply. I'm sending you more details as you have requested.

@vikulin
Copy link

vikulin commented Jun 17, 2024

@wlynxg could you please provide a link to the 3party lib?

https://github.com/wlynxg/anet

The fix did not work for me: I got permission denied error in Android logs:

2024-06-17 14:38:47.641 15709-15792 GoLog                   org.rivchain.cuplink                 I  Failed up get addresses for interface wlan0: route ip+net: netlinkrib: permission denied
2024-06-17 14:38:47.637 15709-15709 ivchain.cuplink         org.rivchain.cuplink                 W  type=1400 audit(0.0:1139327): avc:  denied  { bind } for  scontext=u:r:untrusted_app:s0:c178,c257,c512,c768 tcontext=u:r:untrusted_app:s0:c178,c257,c512,c768 tclass=netlink_route_socket permissive=0 bug=b/155595000 app=org.rivchain.cuplink
2024-06-17 14:38:48.647 15709-15770 GoLog                   org.rivchain.cuplink                 I  Failed up get addresses for interface wlan0: route ip+net: netlinkrib: permission denied
2024-06-17 14:38:48.645 15709-15709 ivchain.cuplink         org.rivchain.cuplink                 W  type=1400 audit(0.0:1139328): avc:  denied  { bind } for  scontext=u:r:untrusted_app:s0:c178,c257,c512,c768 tcontext=u:r:untrusted_app:s0:c178,c257,c512,c768 tclass=netlink_route_socket permissive=0 bug=b/155595000 app=org.rivchain.cuplink
2024-06-17 14:38:49.658 15709-15770 GoLog                   org.rivchain.cuplink                 I  Failed up get addresses for interface wlan0: route ip+net: netlinkrib: permission denied

I have changed the net to anet package.

If you are willing to provide your minimum executable code, I will be happy to help you solve the problem. You can send it directly to me through the email address on my homepage.

I'm not sure but I think the problem in targetSdkVersion 34. Here is a report for fix in Android API 30 but for API 34 it fails.

@vikulin
Copy link

vikulin commented Jun 17, 2024

@wlynxg I created a demo project for you to show the result:

https://github.com/vikulin/gomobile/blob/main/libmodule/src/go/mobile/hello.go

anet.Interfaces() returns an empty array for a HW device (Pixel 7a, Android 14). No errors in logs:

Put aar file in libs folder and build it.

Result:

Screenshot_20240617-191148
2024-06-17 18:52:57.150 12859-12859 VRI[MainActivity]       org.golang.example.android           D  visibilityChanged oldVisibility=true newVisibility=false
2024-06-17 18:52:57.178 12859-12859 VRI[MainActivity]       org.golang.example.android           D  Not drawing due to not visible
2024-06-17 18:52:57.202 12859-12859 WindowOnBackDispatcher  org.golang.example.android           W  sendCancelIfRunning: isInProgress=falsecallback=android.view.ViewRootImpl$$ExternalSyntheticLambda11@364958e
2024-06-17 19:04:01.324 14203-14203 example.android         org.golang.example.android           I  Late-enabling -Xcheck:jni
2024-06-17 19:04:01.342 14203-14203 example.android         org.golang.example.android           I  Using CollectorTypeCMC GC.
2024-06-17 19:04:01.363 14203-14203 Compatibil...geReporter org.golang.example.android           D  Compat change id reported: 171979766; UID 10436; state: ENABLED
2024-06-17 19:04:01.363 14203-14203 Compatibil...geReporter org.golang.example.android           D  Compat change id reported: 242716250; UID 10436; state: ENABLED
2024-06-17 19:04:01.372 14203-14203 ziparchive              org.golang.example.android           W  Unable to open '/data/app/~~CyjYR5e7Zc_jAAV-FOyMmA==/org.golang.example.android-kdOlYbN0LSPbhv9oYLgzgg==/base.dm': No such file or directory
2024-06-17 19:04:01.372 14203-14203 ziparchive              org.golang.example.android           W  Unable to open '/data/app/~~CyjYR5e7Zc_jAAV-FOyMmA==/org.golang.example.android-kdOlYbN0LSPbhv9oYLgzgg==/base.dm': No such file or directory
2024-06-17 19:04:01.375 14203-14203 nativeloader            org.golang.example.android           D  Configuring clns-4 for other apk /data/app/~~CyjYR5e7Zc_jAAV-FOyMmA==/org.golang.example.android-kdOlYbN0LSPbhv9oYLgzgg==/base.apk. target_sdk_version=34, uses_libraries=, library_path=/data/app/~~CyjYR5e7Zc_jAAV-FOyMmA==/org.golang.example.android-kdOlYbN0LSPbhv9oYLgzgg==/lib/arm64:/data/app/~~CyjYR5e7Zc_jAAV-FOyMmA==/org.golang.example.android-kdOlYbN0LSPbhv9oYLgzgg==/base.apk!/lib/arm64-v8a, permitted_path=/data:/mnt/expand:/data/user/0/org.golang.example.android
2024-06-17 19:04:01.386 14203-14203 GraphicsEnvironment     org.golang.example.android           V  Currently set values for:
2024-06-17 19:04:01.386 14203-14203 GraphicsEnvironment     org.golang.example.android           V    angle_gl_driver_selection_pkgs=[]
2024-06-17 19:04:01.386 14203-14203 GraphicsEnvironment     org.golang.example.android           V    angle_gl_driver_selection_values=[]
2024-06-17 19:04:01.386 14203-14203 GraphicsEnvironment     org.golang.example.android           V  Global.Settings values are invalid: number of packages: 0, number of values: 0
2024-06-17 19:04:01.386 14203-14203 GraphicsEnvironment     org.golang.example.android           V  Neither updatable production driver nor prerelease driver is supported.
2024-06-17 19:04:01.407 14203-14237 vulkan                  org.golang.example.android           D  searching for layers in '/data/app/~~CyjYR5e7Zc_jAAV-FOyMmA==/org.golang.example.android-kdOlYbN0LSPbhv9oYLgzgg==/lib/arm64'
2024-06-17 19:04:01.407 14203-14237 vulkan                  org.golang.example.android           D  searching for layers in '/data/app/~~CyjYR5e7Zc_jAAV-FOyMmA==/org.golang.example.android-kdOlYbN0LSPbhv9oYLgzgg==/base.apk!/lib/arm64-v8a'
2024-06-17 19:04:01.422 14203-14203 Compatibil...geReporter org.golang.example.android           D  Compat change id reported: 309578419; UID 10436; state: DISABLED
2024-06-17 19:04:01.429 14203-14203 Compatibil...geReporter org.golang.example.android           D  Compat change id reported: 279646685; UID 10436; state: DISABLED
2024-06-17 19:04:01.431 14203-14203 Compatibil...geReporter org.golang.example.android           D  Compat change id reported: 232195501; UID 10436; state: DISABLED
2024-06-17 19:04:01.446 14203-14203 Compatibil...geReporter org.golang.example.android           D  Compat change id reported: 210923482; UID 10436; state: ENABLED
2024-06-17 19:04:01.446 14203-14203 Compatibil...geReporter org.golang.example.android           D  Compat change id reported: 63938206; UID 10436; state: DISABLED
2024-06-17 19:04:01.458 14203-14203 Compatibil...geReporter org.golang.example.android           D  Compat change id reported: 237531167; UID 10436; state: DISABLED
2024-06-17 19:04:01.581 14203-14203 VRI[MainActivity]       org.golang.example.android           D  Not drawing due to not visible
2024-06-17 19:04:11.551 14203-14203 VRI[MainActivity]       org.golang.example.android           D  Start draw after previous draw not visible
2024-06-17 19:04:33.136 14203-14215 example.android         org.golang.example.android           I  Background concurrent mark compact GC freed 14171(8478KB) AllocSpace objects, 3(60KB) LOS objects, 91% free, 2212KB/26MB, paused 891us,9.637ms total 100.266ms
2024-06-17 19:04:42.507 14203-14203 VRI[MainActivity]       org.golang.example.android           D  visibilityChanged oldVisibility=true newVisibility=false
2024-06-17 19:04:42.548 14203-14203 VRI[MainActivity]       org.golang.example.android           D  Not drawing due to not visible
2024-06-17 19:05:06.570 14203-14203 VRI[MainActivity]       org.golang.example.android           D  Start draw after previous draw not visible
2024-06-17 19:05:30.173 14632-14632 Compatibil...geReporter org.golang.example.android           D  Compat change id reported: 210923482; UID 10436; state: ENABLED
2024-06-17 19:05:30.174 14632-14632 Compatibil...geReporter org.golang.example.android           D  Compat change id reported: 63938206; UID 10436; state: DISABLED
2024-06-17 19:05:30.186 14632-14632 Compatibil...geReporter org.golang.example.android           D  Compat change id reported: 237531167; UID 10436; state: DISABLED
2024-06-17 19:07:53.485 14632-14632 VRI[MainActivity]       org.golang.example.android           D  visibilityChanged oldVisibility=true newVisibility=false
2024-06-17 19:07:53.531 14632-14632 VRI[MainActivity]       org.golang.example.android           D  Not drawing due to not visible

@vikulin
Copy link

vikulin commented Jun 17, 2024

This is an output for net.Interfaces() package:

Screenshot_20240617-192406

@wlynxg
Copy link
Author

wlynxg commented Jun 18, 2024

@wlynxg I created a demo project for you to show the result:

https://github.com/vikulin/gomobile/blob/main/libmodule/src/go/mobile/hello.go

anet.Interfaces() returns an empty array for a HW device (Pixel 7a, Android 14). No errors in logs:

Put aar file in libs folder and build it.

Result:

Screenshot_20240617-191148 ``` 2024-06-17 18:52:57.150 12859-12859 VRI[MainActivity] org.golang.example.android D visibilityChanged oldVisibility=true newVisibility=false 2024-06-17 18:52:57.178 12859-12859 VRI[MainActivity] org.golang.example.android D Not drawing due to not visible 2024-06-17 18:52:57.202 12859-12859 WindowOnBackDispatcher org.golang.example.android W sendCancelIfRunning: isInProgress=falsecallback=android.view.ViewRootImpl$$ExternalSyntheticLambda11@364958e 2024-06-17 19:04:01.324 14203-14203 example.android org.golang.example.android I Late-enabling -Xcheck:jni 2024-06-17 19:04:01.342 14203-14203 example.android org.golang.example.android I Using CollectorTypeCMC GC. 2024-06-17 19:04:01.363 14203-14203 Compatibil...geReporter org.golang.example.android D Compat change id reported: 171979766; UID 10436; state: ENABLED 2024-06-17 19:04:01.363 14203-14203 Compatibil...geReporter org.golang.example.android D Compat change id reported: 242716250; UID 10436; state: ENABLED 2024-06-17 19:04:01.372 14203-14203 ziparchive org.golang.example.android W Unable to open '/data/app/~~CyjYR5e7Zc_jAAV-FOyMmA==/org.golang.example.android-kdOlYbN0LSPbhv9oYLgzgg==/base.dm': No such file or directory 2024-06-17 19:04:01.372 14203-14203 ziparchive org.golang.example.android W Unable to open '/data/app/~~CyjYR5e7Zc_jAAV-FOyMmA==/org.golang.example.android-kdOlYbN0LSPbhv9oYLgzgg==/base.dm': No such file or directory 2024-06-17 19:04:01.375 14203-14203 nativeloader org.golang.example.android D Configuring clns-4 for other apk /data/app/~~CyjYR5e7Zc_jAAV-FOyMmA==/org.golang.example.android-kdOlYbN0LSPbhv9oYLgzgg==/base.apk. target_sdk_version=34, uses_libraries=, library_path=/data/app/~~CyjYR5e7Zc_jAAV-FOyMmA==/org.golang.example.android-kdOlYbN0LSPbhv9oYLgzgg==/lib/arm64:/data/app/~~CyjYR5e7Zc_jAAV-FOyMmA==/org.golang.example.android-kdOlYbN0LSPbhv9oYLgzgg==/base.apk!/lib/arm64-v8a, permitted_path=/data:/mnt/expand:/data/user/0/org.golang.example.android 2024-06-17 19:04:01.386 14203-14203 GraphicsEnvironment org.golang.example.android V Currently set values for: 2024-06-17 19:04:01.386 14203-14203 GraphicsEnvironment org.golang.example.android V angle_gl_driver_selection_pkgs=[] 2024-06-17 19:04:01.386 14203-14203 GraphicsEnvironment org.golang.example.android V angle_gl_driver_selection_values=[] 2024-06-17 19:04:01.386 14203-14203 GraphicsEnvironment org.golang.example.android V Global.Settings values are invalid: number of packages: 0, number of values: 0 2024-06-17 19:04:01.386 14203-14203 GraphicsEnvironment org.golang.example.android V Neither updatable production driver nor prerelease driver is supported. 2024-06-17 19:04:01.407 14203-14237 vulkan org.golang.example.android D searching for layers in '/data/app/~~CyjYR5e7Zc_jAAV-FOyMmA==/org.golang.example.android-kdOlYbN0LSPbhv9oYLgzgg==/lib/arm64' 2024-06-17 19:04:01.407 14203-14237 vulkan org.golang.example.android D searching for layers in '/data/app/~~CyjYR5e7Zc_jAAV-FOyMmA==/org.golang.example.android-kdOlYbN0LSPbhv9oYLgzgg==/base.apk!/lib/arm64-v8a' 2024-06-17 19:04:01.422 14203-14203 Compatibil...geReporter org.golang.example.android D Compat change id reported: 309578419; UID 10436; state: DISABLED 2024-06-17 19:04:01.429 14203-14203 Compatibil...geReporter org.golang.example.android D Compat change id reported: 279646685; UID 10436; state: DISABLED 2024-06-17 19:04:01.431 14203-14203 Compatibil...geReporter org.golang.example.android D Compat change id reported: 232195501; UID 10436; state: DISABLED 2024-06-17 19:04:01.446 14203-14203 Compatibil...geReporter org.golang.example.android D Compat change id reported: 210923482; UID 10436; state: ENABLED 2024-06-17 19:04:01.446 14203-14203 Compatibil...geReporter org.golang.example.android D Compat change id reported: 63938206; UID 10436; state: DISABLED 2024-06-17 19:04:01.458 14203-14203 Compatibil...geReporter org.golang.example.android D Compat change id reported: 237531167; UID 10436; state: DISABLED 2024-06-17 19:04:01.581 14203-14203 VRI[MainActivity] org.golang.example.android D Not drawing due to not visible 2024-06-17 19:04:11.551 14203-14203 VRI[MainActivity] org.golang.example.android D Start draw after previous draw not visible 2024-06-17 19:04:33.136 14203-14215 example.android org.golang.example.android I Background concurrent mark compact GC freed 14171(8478KB) AllocSpace objects, 3(60KB) LOS objects, 91% free, 2212KB/26MB, paused 891us,9.637ms total 100.266ms 2024-06-17 19:04:42.507 14203-14203 VRI[MainActivity] org.golang.example.android D visibilityChanged oldVisibility=true newVisibility=false 2024-06-17 19:04:42.548 14203-14203 VRI[MainActivity] org.golang.example.android D Not drawing due to not visible 2024-06-17 19:05:06.570 14203-14203 VRI[MainActivity] org.golang.example.android D Start draw after previous draw not visible 2024-06-17 19:05:30.173 14632-14632 Compatibil...geReporter org.golang.example.android D Compat change id reported: 210923482; UID 10436; state: ENABLED 2024-06-17 19:05:30.174 14632-14632 Compatibil...geReporter org.golang.example.android D Compat change id reported: 63938206; UID 10436; state: DISABLED 2024-06-17 19:05:30.186 14632-14632 Compatibil...geReporter org.golang.example.android D Compat change id reported: 237531167; UID 10436; state: DISABLED 2024-06-17 19:07:53.485 14632-14632 VRI[MainActivity] org.golang.example.android D visibilityChanged oldVisibility=true newVisibility=false 2024-06-17 19:07:53.531 14632-14632 VRI[MainActivity] org.golang.example.android D Not drawing due to not visible ```

Your problem is due to not configuring the Android app's permissions, you need to add this line:

<uses-permission android:name="android.permission.INTERNET" />

@vikulin
Copy link

vikulin commented Jun 18, 2024

@wlynxg yes, you are right. Let me correct this.

@vikulin
Copy link

vikulin commented Jun 18, 2024

@wlynxg corrected permissions and found the code where the error is getting from: it's in iface.Addrs()

Result:

Screenshot_20240618-130746

Now the defect is fully explained and ready for a fix.

@wlynxg
Copy link
Author

wlynxg commented Jun 18, 2024

@vikulin You need to use https://pkg.go.dev/github.com/wlynxg/anet#InterfaceAddrsByInterface to get the correct address.

@vikulin
Copy link

vikulin commented Jun 18, 2024

@wlynxg I've added this method as you have suggested and got an empty response for every interface and permission errors when SetAndroidVersion added prior the call.

Result:

Screenshot_20240618-145059

@wlynxg
Copy link
Author

wlynxg commented Jun 18, 2024

@vikulin I'm sorry, there is a bug in my library, I will fix it soon.

@vikulin
Copy link

vikulin commented Jun 18, 2024

@vikulin I'm sorry, there is a bug in my library, I will fix it soon.

How may I help you to get it working?

@wlynxg
Copy link
Author

wlynxg commented Jun 19, 2024

@vikulin I'm sorry, there is a bug in my library, I will fix it soon.

How may I help you to get it working?

Sorry. It was late yesterday. I have fixed the bug today.

@vikulin
Copy link

vikulin commented Jun 19, 2024

@wlynxg the fix confirmed. Could you please use Android API version number instead of Android version in https://github.com/wlynxg/anet/blob/v0.0.2/interface.go#L30 ?

@lawndoc
Copy link

lawndoc commented Jul 15, 2024

Is this PR going to be come back to? This causes issues with a lot of go-based apps in Termux. It looks like there were a couple of comments that have yet to be addressed:

https://go-review.googlesource.com/c/go/+/507415/3/src/syscall/netlink_linux.go
https://go-review.googlesource.com/c/go/+/507415/3/src/net/interface_linux.go

@wlynxg's library is great, but native support for basic networking functionality like this should be the goal for a cross-platform language like Go.

@wlynxg
Copy link
Author

wlynxg commented Jul 19, 2024

Is this PR going to be come back to? This causes issues with a lot of go-based apps in Termux. It looks like there were a couple of comments that have yet to be addressed:

https://go-review.googlesource.com/c/go/+/507415/3/src/syscall/netlink_linux.go https://go-review.googlesource.com/c/go/+/507415/3/src/net/interface_linux.go

@wlynxg's library is great, but native support for basic networking functionality like this should be the goal for a cross-platform language like Go.

The two issues have been fixed and explained in subsequent submissions.
For this submission, I feel it will be difficult to merge it into the official version because it is related to the Android platform. I personally recommend using a third-party library to solve this problem: https://github.com/wlynxg/anet.

@wlynxg
Copy link
Author

wlynxg commented Jul 19, 2024

Android API version

Android API version does not seem to be related to this issue, as the issue is caused by Android SELinux.

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

4 participants