question

"cured_one" avatar image
"cured_one" asked

Service PrivateADMRegistrationService has leaked ServiceConnection

I'd like to revisit that problem and hopefully someone at Amazon can provide a solution. Basically, now i have seen the error "Service com.amazon.device.messaging.PrivateADMRegistrationService has leaked ServiceConnection" showing up in existing project where i tried to integrate ADM push messaging to. After few unsuccessful attempts with connection leak error showing ( https://forums.developer.amazon.com/forums/thread.jspa?threadID=1192&tstart=0) I was unable to repro the issue using sample code. So i gave up on that and created new project from scratch with ADM messaging integrated and then added our custom code into (in order to try and find out whether some of our custom logic caused the problems). And voila, everything worked - registration passed successfully and i was able to receive ADM messages in our app. The trouble started when i created package for release testing (signed with our custom keystore). I have updated the api_key and onRegistered was called giving valid registration ID, but then again i saw this error: [i]06-29 23:12:21.486: E/ActivityThread(28507): Service com.amazon.device.messaging.PrivateADMRegistrationService has leaked ServiceConnection com.amazon.identity.auth.device.authorization.api.AmazonCredentialManager$CredentialManagerServiceConnection@415ccc58 that was originally bound here [/i] After that message, ADM functionality in the app is dead. Now, since ADM works in debug build and does not work in release. As the code is Amazon, i am not sure how to proceed with that. I'd appreciate help with that as it now basically a) blocks our release as only debug DPK functions and b) creates some doubt as to ADM stability. Moreover, it appears (based on the forum) that this is not the first time the exception was reported and yet there was no solution provided. Thanks!
amazon device messaging
10 |5000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

ethertree avatar image
ethertree answered
Hi, Having been through quite a few combinations of problems with the leak you mention, which only happens as far as I have seen during an attempt to register the device with ADM. And because the code is common for all builds it's likely to be a difference between how you are building your app for test and release. On that basis I have a few suggestions/questions for you which might help you check your code: - Do you not get an error coming back via the onRegistrationError of your ADM service class? I would expect to see an error there. If it's SENDER_INVALID then I believe that means the api_key.txt does not match the key used to sign the APK. If it's SERVICE_NOT_AVAILABLE then the device is not registered. Those are the only errors I have seen. - When you built the release version was it self-signed APK or were you letting Amazon sign it? For compatibility with my Play store app, I'm using self-signed which seems to work so far (although I haven't submitted yet). I found this useful to compare the MD5 of the APK in the cert.rsa file with the certificate kety used for ADM. - Have you checked the MD5 for the api key in assets/ api_key.txt (as shown in your Security Profile) is the same as that signing your realease APK? I havn't looked at this for "signed by Amazon" but for self-signed only. I did a sanity check check involved checking the certificate used for signing in my keystore had the same MD5 as shown for my release api key in the Amazon Security Profile AND I checked the MD5 actually matched the the APK by unzipping the APK and extracting and then viewing META-INF/Cert.rsa (uisng the command line "%JAVA_HOME%/bin/keytool" -printcert -file cert.rsa where you can see the line foor the MD5). It's worth just checking that everything matched and so rule out the certificate as a problem! - When you tried the release version did you uninstall the previous debug version or just build with a different signature? If you did not uninstall the previous debug build the registrationId will still be cached for the app, and I'm not sure if a registration Id generated with the debug key, will work with another key, even if it is the same account. It's worth checking at least. Hope that helps! Tree
10 |5000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

"cured_one" avatar image
"cured_one" answered
Thank you for taking time to answer. It is a good checklist, but i have already been through that :) 1. onRegistered fires correctly. Registration id is returned for both debug and release version 2. It is self-signed APK, so i do not see whats the major difference it makes between debug (using local debugstore) and release 3. I am using MD5 for release keystore; did not not do the sanity check by unzipping APK, but in my experience invalid api key results in onRegistrationError firing which is not the case 4.Yes, i am trying release on clean device So based on past experience i think there must be something in ADM code. Waiting to hear from Amazon.
10 |5000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

ethertree avatar image
ethertree answered
Well hopefully it might help someone else. I totally misread where you said you had hit onRegisterer! I'll just add one more experience because it happened past registration, although I don't think it's likely to be your problem, it might suggest something else to you or the Amazon support team: - I have an compatibility issue with "Login with Amazon" and the Amazon SDK APIs which need a key, as they both use keys which come from different sources, and both use the same api_key.txt file. What I noticed is that if I used the "Login with Amazon" key, I can actually register the device (which surprised me), but after that, no push messages arrived, and attempts to send from the server where rejected with INVALID_REGISTRATION. So I have a generated but useless registrationId. I must admit I didn't check the log to look for the leak issue you see but I don't remember seeming the same error. Is there anything in the stack trace that suggests there the trigger for the leak comes from?
10 |5000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

"cured_one" avatar image
"cured_one" answered
I do not have another key in the file. Only one is ADM API key; I do though have Amazon Ads enabled, not sure if that would be relevant. There is nothing in the stack to indicate the trigger; it does not happen on activity thread.
10 |5000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

"cured_one" avatar image
"cured_one" answered
Anyone from AMZN cares to comment? We are still blocked.
10 |5000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Sujoy@Amazon avatar image
Sujoy@Amazon answered
Hi Cured_one, Sorry for the delay to respond. I would request you to raise a ContactUs ( https://developer.amazon.com/help/contactus.html) today, there I would give you my mail id (can not say it in the public forum) to send me the release certificate (.keystore), alias and storepass of the cert. I want to test it in my end. Also, I see 5 api keys you have created for the security profile named "Test". Could you tell me which one is for release testing?
10 |5000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Sujoy@Amazon avatar image
Sujoy@Amazon answered
Hi, One potential problem is that you have set RECEIEVE_ADM_MESSAGE permission incorrectly. You should define and take the permission .permission.RECEIVE_ADM_MESSAGE
10 |5000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

"cured_one" avatar image
"cured_one" answered
I have verified that the permission is set in the manifest. Besides, I do not see how that explains debug build working - should the permission be invalid both debug and release builds would have the same failure, would they?
10 |5000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Sujoy@Amazon avatar image
Sujoy@Amazon answered
I have replied to your mail.
10 |5000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

BenB avatar image
BenB answered
Hey cured_one, I was having this problem too until I updated my kindle software. Which software version are you running on your device? You can get the version in Settings -> Device -> About
10 |5000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.