enviroCar / enviroCar-app

enviroCar Android Application
https://envirocar.org
GNU General Public License v3.0
88 stars 154 forks source link

Android 12 support #887

Closed SebaDro closed 2 years ago

SebaDro commented 2 years ago

Description Up to now, the app does not support Android 12 very well. Several issues have been reported regarding the Bluetooth permission management and OBDII connections.

As stated in the official Android documentation, Bluetooth permission management has changed for Android 12 devices. This has already been addressed by a5b531e8. However, the solution does not work perfectly, so that abrupt app crashes still occur.

In addition, these crashes are not logged and therefore do not appear inthe crash report which makes it hard to retrace the failure.

Branches master, develop

How to reproduce If you have had the enviroCar app already in use on a device with Android version <12 and upgrade to Android 12, you will notice the first crash when trying to open the Bluetooth selection screen. A helpful workaround for this issue is a clean installation (remove app from your deivce and install again from Google Playstore) in combination with manually revoking enviroCar app permissions from you device settings. By doing so, new permissions will be queried the first time you will visit the Bluetooth selection screen. However, when you try to start recording, the app still crashes abrupt.

How to fix Refine Bluetooth permission management according to Android 12 requirements and add a more sensible logging that takes into account abrupt crashes caused by permission issues.

Special thanks to @ChrissW-R1 who extensively tested the behavior on an Android 12 device and reported the issues.

cdhiraj40 commented 2 years ago

Hello @SebaDro sir, I checked on this bug researched it, and did some coding.

you will notice the first crash when trying to open the Bluetooth selection screen.

The request permission code was in the OBDSelectionFragment, After seeing the code I just thought as the OBDSelectionActivity is getting initialized first so we should ask for permission in the activity and then move to the fragment. and it worked. It stopped crashing. so it does not need any more manually revoking permissions.

However, when you try to start recording, the app still crashes abruptly.

I researched about it too, and after getting done with the permission issues, it was crashing because of not specifying the mutability of each pending intent that is being used. This results in a crash.

If your app targets Android 12, you must [specify the mutability](https://developer.android.com/guide/components/intents-filters#DeclareMutabilityPendingIntent) of each [PendingIntent](https://developer.android.com/reference/android/app/PendingIntent) object that your app creates. This additional requirement improves your app's security.

more info here

I did add some code to handle this issue but I was still facing some issues, I would talk about it more when I have proper information about it. This is all I gathered by checking on this. Do tell me your thoughts on this sir @SebaDro

SebaDro commented 2 years ago

Hey @cdhiraj40. Thanks for your elaborations on this issue. It sounds like you are on the right track. Could you please create a work in progress pull request with the coding you have done so far? Then we can use the pull request to discuss further about possible approaches for fixing the issue.

cdhiraj40 commented 2 years ago

Sure @SebaDro sir, I will create a PR soon for this.

SebaDro commented 2 years ago

Has been fixed with #910 and proofed as working.