openbmap / radiocells-scanner-android

WLAN and cell tower scanner for Radiocells.org
https://www.radiocells.org
Other
55 stars 26 forks source link

App crashes when "Location" permission is off (revoked) #173

Open arsadeghi opened 7 years ago

arsadeghi commented 7 years ago

What steps will reproduce the problem? 1- Revoke the location permission for the app (In Android OS >= M, it is revoked by default after app installation) 2- Start a new session.

Here is the screenshot: openbmap

What is the expected output? What do you see instead? If the "Location" permission is not granted upon creating a new session, should show the permission dialog and ask the user to grant the missing (i.e. Location) permission.

What version are you using? On what operating system? Master branch on Nexus 5, API 23

Please provide any additional information below. stack trace after the crash:

12-27 12:15:03.057 15619-15619/org.openbmap E/AndroidRuntime: FATAL EXCEPTION: main
                                                              Process: org.openbmap, PID: 15619
                                                              java.lang.RuntimeException: Unable to create service org.openbmap.services.wireless.WirelessLoggerService: java.lang.SecurityException: Neither user 10401 nor current process has android.permission.ACCESS_COARSE_LOCATION.
                                                                  at android.app.ActivityThread.handleCreateService(ActivityThread.java:2887)
                                                                  at android.app.ActivityThread.-wrap4(ActivityThread.java)
                                                                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1427)
                                                                  at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                  at android.os.Looper.loop(Looper.java:148)
                                                                  at android.app.ActivityThread.main(ActivityThread.java:5417)
                                                                  at java.lang.reflect.Method.invoke(Native Method)
                                                                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
                                                                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
                                                               Caused by: java.lang.SecurityException: Neither user 10401 nor current process has android.permission.ACCESS_COARSE_LOCATION.
                                                                  at android.os.Parcel.readException(Parcel.java:1599)
                                                                  at android.os.Parcel.readException(Parcel.java:1552)
                                                                  at com.android.internal.telephony.ITelephonyRegistry$Stub$Proxy.listenForSubscriber(ITelephonyRegistry.java:553)
                                                                  at android.telephony.TelephonyManager.listen(TelephonyManager.java:2675)
                                                                  at org.openbmap.services.wireless.WirelessLoggerService.registerPhoneStateManager(WirelessLoggerService.java:416)
                                                                  at org.openbmap.services.wireless.WirelessLoggerService.onCreate(WirelessLoggerService.java:297)
                                                                  at android.app.ActivityThread.handleCreateService(ActivityThread.java:2877)
                                                                  at android.app.ActivityThread.-wrap4(ActivityThread.java) 
                                                                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1427) 
                                                                  at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                  at android.os.Looper.loop(Looper.java:148) 
                                                                  at android.app.ActivityThread.main(ActivityThread.java:5417) 
                                                                  at java.lang.reflect.Method.invoke(Native Method)
ndwaya commented 6 years ago

I don't know if you have already found an answer but this is not a bug. What happens is that the savedInstanceState value becomes invalid because your app process got killed and restarted after you revoke the permission. The current fix I have for my app is passing null to my onCreate activity. This is because even after your process is killed the savedInstanceState still remains and is returned after you go back to the app. If you did the same thing without having the app open, it won't crash because savedInstanceState is null. This is a Marshmellow and bove problem. It is because of Google changing how users give access to permission and that they now have the ability to revoke it.

Shaftar commented 3 years ago

Ok, that make sence. But how to know, if the savedInstanceState has invalid value?

Shaftar commented 3 years ago

And what is the disadvantage by passing null to super.onCreate() method?

wish7code commented 3 years ago

Hey Shaftar, haven't time to continue work on this branch.

If you're interested in the scanning part only, I might share an unpublished, which works on Android 10 (scanning, not uploading though)