andriydruk / RxDNSSD

Android version of mDNSResponder
Apache License 2.0
297 stars 75 forks source link

Android 12 #206

Closed reymalahay closed 2 years ago

reymalahay commented 3 years ago

Hi all,

Has anyone tried to install their app with the RxDNSSD library, without any modifications, on a device running Android 12 with these specs:

  1. Bindable implementation
  2. Android 12 beta

This is the entry in the log when the app in question (with no changes to the implementation) is installed on a device running Android 12:

com.github.druk.dnssd.AppleDNSSDException: DNS-SD Error -65563: SERVICENOTRUNNING

Please advise.

Thanks in advance and kind regards, rey malahay

VT-ChiragBhuva commented 3 years ago

Hi all, I am facing the same issue. did anyone found a solution?

alexgarret commented 3 years ago

A similar ticket has been opened at Google: https://issuetracker.google.com/issues/194682218 Hope they will come with a fix in the next beta versions.

reymalahay commented 3 years ago

Thank you @alexgarret,

Just a heads up guys, the Android engineering team has fixed this issue and it will be available in the next release. Details here:

https://issuetracker.google.com/issues/194682218#comment4

I will close this issue now.

Kind regards, rey malahay

A similar ticket has been opened at Google: https://issuetracker.google.com/issues/194682218 Hope they will come with a fix in the next beta versions.

andriydruk commented 3 years ago

Thank you, guys 🙏

VT-ChiragBhuva commented 3 years ago

Hi all,

Can anyone explain to me why we are getting this exception in Android 12 devices? is there is an issue with Native API? OR any restriction in Android 12?

Thanks in advance

crysxd commented 2 years ago

Anyone having an update on this? The bug mentioned above was closed by Google....but this issue is still in the release build of Android 12.

reymalahay commented 2 years ago

@crysxd, you will need to do a system update in order to get the latest changes:

Settings > System > System Update

hth

kind regards, rey malahay

Anyone having an update on this? The bug mentioned above was closed by Google....but this issue is still in the release build of Android 12.

crysxd commented 2 years ago

@reymalahay My system is fully up to date (Pixel 4) and the issue is still reproducible for me

crysxd commented 2 years ago

I found the issue. I tested again with my Pixel 4a (release build, all updates installed) using the BonjourBrowser installed from Google Play. To my surprise, everything worked perfectly. I then tested again my app, but still got the same SERVICE NOT RUNNING error. I cloned the source of BonjourBrowser, build it and installed it on the same Pixel 4a. Everything worked fine. I then tried to figure out what the difference between my app and BonjourBrowser was. After some testing, I found the issue to be the target SDK. I already target SDK 31, BonjourBrowser still 30. After changing the target SDK of BonjourBrowser to 31, it has the same issue.

See the attached video. Funnily enough, after reinstall the app briefly shows the results of the previous install before encountering SERVICE NOT RUNNING. This only happens if you test back to back, most likely some caching?

https://user-images.githubusercontent.com/5859228/140373520-a9b64891-f6c7-4f97-a54f-b5361a6c816c.mov

andriydruk commented 2 years ago

Hmm, looks like Google decide to switch off this API for Android 31 It's sad but probably we can do nothing about it

You still can try the Embedded version. It should work without an Android system deamon or switch to system NsdManager

crysxd commented 2 years ago

The embedded one seems to work fine still. I found the NsdManager to be unreliable across devices, so the embedded it will be for now. Thinking about using bindable for 5-11 and embedded for 12+ so the behaviour stays the same for old versions.

PieterAelse commented 2 years ago

@andriydruk Do you have any source for your statement "Hmm, looks like Google decide to switch off this API for Android 31" ?

crysxd commented 2 years ago

@PieterAelse there is no documentation on this change (I'm aware of after googling a bit), but please feel free to try to get an official statement from Google. From what we can observe, Google dropping support is the obvious conclusion. The bug was reported and only fixed for apps not targeting Android 12. So it seems like that new apps will no longer be allowed to make use of this API. Switching to the embedded version when the app is running on Android 12+ worked flawlessly for me

PieterAelse commented 2 years ago

@andriydruk @crysxd I was only able to find this change in Android 12: https://developer.android.com/about/versions/12/behavior-changes-12#mdnsresponder

Disclaimer: I don't have any knowledge on mDNS and this package (yet), but could it be that Android 12 still supports it, but there's just a little change needed?

andriydruk commented 2 years ago

@PieterAelse @crysxd yes, the is behaviour change I was talking about

No. We can't change anything. Google clearly says that they disable this API for every client except NsdManager

To minimize battery usage, in Android 12 and higher the system now starts the mDNSResponder daemon only when it is needed for NSD events and stops it afterwards.

Now we have only 2 option move to NsdManager or use Embedded version

PieterAelse commented 2 years ago

@andriydruk when using the Embedded version (replaced Rx2DnssdBindable with Rx2DnssdEmbedded) we see a crash happening after starting the app (sometimes immediately, sometimes some time later). Any idea? I don't see any open issue for a StackOverflowError 🤔

2021-11-12 09:37:37.352 31154-31154/? I/DNSSDEmbedded: already started 2021-11-12 09:37:44.618 31154-31315/? A/[package_id]: thread.cc:2365] No pending exception expected: java.lang.StackOverflowError: stack size 1039KB thread.cc:2365] at boolean android.os.MessageQueue.enqueueMessage(android.os.Message, long) (MessageQueue.java:554) thread.cc:2365] at boolean android.os.Handler.enqueueMessage(android.os.MessageQueue, android.os.Message, long) (Handler.java:778) thread.cc:2365] at boolean android.os.Handler.sendMessageAtTime(android.os.Message, long) (Handler.java:727) thread.cc:2365] at boolean android.os.Handler.sendMessageDelayed(android.os.Message, long) (Handler.java:697) thread.cc:2365] at boolean android.os.Handler.post(java.lang.Runnable) (Handler.java:427) thread.cc:2365] at void com.github.druk.dnssd.DNSSD$1.serviceFound(com.github.druk.dnssd.DNSSDService, int, int, byte[], byte[], byte[]) (:-1) thread.cc:2365] 2021-11-12 09:37:44.743 31154-31316/? A/[package_id]: java_vm_ext.cc:579] JNI DETECTED ERROR IN APPLICATION: java_class == null java_vm_ext.cc:579] in call to GetMethodID java_vm_ext.cc:579] from int com.github.druk.dnssd.DNSSDEmbedded.nativeLoop()

andriydruk commented 2 years ago

@PieterAelse Looks like a bug. Please open separate issue I will investigate it

tmm1 commented 2 years ago

Thinking about using bindable for 5-11 and embedded for 12+ so the behaviour stays the same for old versions.

Is there a simple way to do this in one apk?

crysxd commented 2 years ago

As simple as:

val dnssd = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
    DNSSDEmbedded(context)
} else {
    DNSSDBindable(context)
}
tmm1 commented 2 years ago

I wasn't sure if it was safe to add both to build.gradle

crysxd commented 2 years ago

I use implementation 'com.github.andriydruk:dnssd:0.9.16'

tmm1 commented 2 years ago

Using embedded version, I see crashes on some devices. For example, Pixel 2:


OS Version: Android 12 (SQ1A.220105.002)
Report Version: 104

Exception Type: Unknown (SIGSEGV)

Application Specific Information:
Segfault

Thread 0 Crashed:
0   libart.so                       0x6db9e3a298        art::InvokeVirtualOrInterfaceWithVarArgs<T>
1   libart.so                       0x6db9e3a1e4        art::InvokeVirtualOrInterfaceWithVarArgs<T>
2   libart.so                       0x6db9fb1980        <unknown> + 471271676288
3   libjdns_sd_embedded.so          0x6cec68e940        Java_com_github_druk_dnssd_AppleQuery_CreateQuery
4   libjdns_sd_embedded.so          0x6cec677c58        <unknown> + 467822672984
5   libjdns_sd_embedded.so          0x6cec64bc3c        <unknown> + 467822492732
6   libjdns_sd_embedded.so          0x6cec64dbb4        <unknown> + 467822500788
7   libjdns_sd_embedded.so          0x6cec674924        <unknown> + 467822659876
8   libjdns_sd_embedded.so          0x6cec6750e4        <unknown> + 467822661860
9   libjdns_sd_embedded.so          0x6cec682a54        <unknown> + 467822717524
10  libjdns_sd_embedded.so          0x6cec682b84        <unknown> + 467822717828
11  libart.so                       0x6db9cd7644        <unknown> + 471268685380
12  libart.so                       0x6db9ccdfe8        <unknown> + 471268646888
13  libart.so                       0x6db9cf23d8        art::interpreter::ArtInterpreterToCompiledCodeBridge
14  libart.so                       0x6db9cf121c        art::interpreter::DoCall<T>
15  libart.so                       0x6dba1748f0        MterpInvokeStatic
16  libart.so                       0x6db9cc8594        <unknown> + 471268623764
17  <unknown>                       0x6d3d002a50        <unknown>
18  libart.so                       0x6db9c7d748        <unknown> + 471268317000
19  libart.so                       0x6db9c7c8f0        artQuickToInterpreterBridge
20  libart.so                       0x6db9cd7778        <unknown> + 471268685688
21  libart.so                       0x6db9ccdd64        <unknown> + 471268646244
22  libart.so                       0x6db9d17fb0        art::ArtMethod::Invoke
23  libart.so                       0x6db9dcc480        art::InvokeVirtualOrInterfaceWithJValues<T>
24  libart.so                       0x6db9e5eff0        art::Thread::CreateCallback
25  libc.so                         0x705788b90c        __pthread_start
26  libc.so                         0x705782b3ec        __start_thread

On SM-T970:

OS Version: Android 12 (SP1A.210812.016.T970XXU2CULC)
Report Version: 104

Exception Type: Unknown (SIGSEGV)

Application Specific Information:
Segfault

Thread 0 Crashed:
0   libjdns_sd_embedded.so          0x74063425b8        Java_com_github_druk_dnssd_AppleResolver_CreateResolver
1   libjdns_sd_embedded.so          0x740632c960        <unknown> + 498320197984
2   libjdns_sd_embedded.so          0x7406300c3c        <unknown> + 498320018492
3   libjdns_sd_embedded.so          0x7406302bb4        <unknown> + 498320026548
4   libjdns_sd_embedded.so          0x7406329924        <unknown> + 498320185636
5   libjdns_sd_embedded.so          0x740632a0e4        <unknown> + 498320187620
6   libjdns_sd_embedded.so          0x7406337a54        <unknown> + 498320243284
7   libjdns_sd_embedded.so          0x7406337b84        <unknown> + 498320243588
8   libart.so                       0x74cbed7644        <unknown> + 501637543492
9   libart.so                       0x74cbe09188        <unknown> + 501636698504
10  base.odex                       0x745617538c        <unknown> + 499660575628
11  libart.so                       0x74cbecdd64        <unknown> + 501637504356
12  libart.so                       0x74cbf17fb0        art::ArtMethod::Invoke
13  libart.so                       0x74cbfcc480        art::InvokeVirtualOrInterfaceWithJValues<T>
14  libart.so                       0x74cc05eff0        art::Thread::CreateCallback
15  libc.so                         0x7567f510f4        <unknown> + 504255287540
16  libc.so                         0x7567eed754        <unknown> + 504254879572
StevenFY commented 2 years ago

On targetSDK = 32 for Android 13, this not working (the method seem to be deleted)

andriydruk commented 2 years ago

Sine targetSDK = 31 Bindable version doesn't work anymore Google made this API deprecated in Android 12