paho.mqtt.android icon indicating copy to clipboard operation
paho.mqtt.android copied to clipboard

Security Exception in A12

Open rohittayal96 opened this issue 2 years ago • 10 comments

Getting exception: Fatal Exception: java.lang.SecurityException: Caller xxx needs to hold android.permission.SCHEDULE_EXACT_ALARM to set exact alarms.

on line 86 in AlarmPingSender.kt alarmManager.setExactAndAllowWhileIdle(AlarmManager.ELAPSED_REALTIME_WAKEUP, nextAlarmInMilliseconds, pendingIntent)

Happens on A12 devices only if, Alarms & Reminders permission is turned off. Doc: link

rohittayal96 avatar Mar 24 '22 06:03 rohittayal96

https://github.com/hannesa2/paho.mqtt.android/blob/29ca7ac7503268c8086f8c0a4b3b3dc2f551f133/serviceLibrary/src/main/AndroidManifest.xml#L6

hannesa2 avatar Mar 24 '22 07:03 hannesa2

@hannesa2 user can revoke the permission from app settings in Android 12 devices. You'll find "Alarms & reminders" option in App Info.

Please check "Check that your app still has permission" section of this doc.

rohittayal96 avatar Mar 24 '22 07:03 rohittayal96

This is a contribution open source project, and pull request are warmly welcome

hannesa2 avatar Mar 24 '22 08:03 hannesa2

Or maybe you give https://github.com/hannesa2/paho.mqtt.android/releases/tag/3.4.0-beta7 a try. It's without this permission and prevent from too much wake up of the device. But needs some more tests

hannesa2 avatar Mar 24 '22 08:03 hannesa2

Potential issue fixed with https://github.com/hannesa2/paho.mqtt.android/pull/159. Working fine on local testing, will update if production app stands to expectations.

rohittayal96 avatar Mar 24 '22 13:03 rohittayal96

Please give it a try https://github.com/hannesa2/paho.mqtt.android/releases/tag/3.4.0-beta8

hannesa2 avatar Mar 24 '22 13:03 hannesa2

@hannesa2 After adopting this solution, MQTT has been disconnecting every 2 minutes for me. Checking further on what is actually resulting in issue.

rohittayal96 avatar Mar 29 '22 05:03 rohittayal96

@hannesa2 let me know if this makes sense: https://github.com/hannesa2/paho.mqtt.android/pull/293 Meanwhile I am verifying my use-cases, and will update on it.

rohittayal96 avatar Mar 30 '22 07:03 rohittayal96

After adopting this solution, MQTT has been disconnecting every 2 minutes for me

I probably understand why it's disconnecting every 2 minutes. Maybe a simple reconnect is the right solution. What's against this ?

hannesa2 avatar Mar 30 '22 07:03 hannesa2

Earlier it was not disconnecting at all even when ideal for >30 minutes. Same behaviour now with handler-looper approach.

Why was it disconnecting? Check starting two lines of PR description: https://github.com/hannesa2/paho.mqtt.android/pull/293

rohittayal96 avatar Mar 30 '22 07:03 rohittayal96

Maybe this will help ? https://github.com/hannesa2/paho.mqtt.android/issues/378#issuecomment-1288913139

hannesa2 avatar Oct 25 '22 06:10 hannesa2

Hopefully solved with https://github.com/hannesa2/paho.mqtt.android/releases/tag/4.0 🤞

hannesa2 avatar Jul 26 '23 05:07 hannesa2