jroal / a2dpvolume

Automatically exported from code.google.com/p/a2dpvolume
http://jimroal.com/slist.htm
95 stars 33 forks source link

Disconnect from devices does not remove notifications #277

Closed JoLander closed 5 years ago

JoLander commented 5 years ago

Hi Jim, first, as a long term user of your tool I would like to mention that I'm very satisfied with the functionality. Unfortunately, it seems that I have an issue with my new Huawei Mate 20 Pro running Android 9.

I have installed the latest version from the Playstore, granted all needed permissions (with Android 9 there are only 3), disabled any kind of battery optimization for this App, and set within the App the visibility option to show up only when devices are connected. I have two devices I use with this App which are my Bluetooth Headset and my Bluetooth Car entertainment system. Both have the same issue.

Issue: When I switch on my Headset, it connects correctly to my mobile. It is also correctly detected by a2dpvolume and works as desired. I see now a symbol in the status bar and also a corresponding message in the notification area:

screen0

screen1

When I now switch off the Headset, it is correctly disconnected from the mobile, but the a2dpvolume symbol still stays in the status bar and the notification does not disappear. It seems that a2dpvolume has detected the disconnect as the two '**' are not longer shown in the Application itself:

screen2

screen3

Funny enough, when I switch off Bluetooth completely on my mobile, the connection messages and the status bar icon still remains on the screen:

screen4

Best Regards, Joe

jroal commented 5 years ago

Duplicate of #277 I am rolling these 2 issues together. They seem to be the same or at least very similar. In your case it seems to be just the notification that stays. I have another person with a Pixel 2 that has the location capture notification that stays sometimes.

JoLander commented 5 years ago

Hi Jim, yes, there is a similarity. Another difference as you already mentioned is the different operating system we use. I'm already on Android 9.

Question: When I open your App and simply hit the 'stop service' button after I'm disconnected from Bluetooth, the status bar icon and the notification immediately disappear. Then, I press the 'start service' button and your App is ready for the next connection. Therefore, it might be helpful if you could simply restart the service when disconnected from the bluetooth device (you might make this optional by a settings option).

JoLander commented 5 years ago

Hello Jim, not sure if it helps, but I've produced a logcat from a connect/disconnect sequence of my headset. The connection happened around 12:05:07 and the status icon and notification are shown on the phone. The disconnect happened around 12:06:05 and the status icon and notification still persist.

logfile.zip

jroal commented 5 years ago

@JoLander thanks for the info. I will look into this when I get time. Interesting to know that toggling the service corrects it. I need a proper fix and toggling the service is not proper but may help understand what is happening. Strange it will not do this on the emulator. I test on a Pixel 2 emulator, among others.

jroal commented 5 years ago

I still can't duplicate the issue but I added some things in the app that should fix this. I am curently have some Play Store issues so it may be a bit before I can push to Beta but you can sideload from here: https://1drv.ms/u/s!AgUbpiol3wYLvHKOLSDntW-F94pO. Let me know if this works.

JoLander commented 5 years ago

Unfortunately, this version shows the same behavior as the previous one. On Bluetooth connect the statusbar icon and the notification appear. On Bluetooth disconnect, the two asterisks in the app disappear, but the icon and notification remain. After stopping and starting the service, the icon and message disappear. One odd thing: My phone has reconnected to my smart watch (which I have removed in a2dpvolume) and now I have a connection notification to 'null' and the default app icon in the statusbar. Stopping the service removes it, but on service start the 'null' connection reappear. screenshot_20190125_181756_com teslacoilsw launcher

jroal commented 5 years ago

@JoLander remove your smartwatch from the list of device in A2DP Bolume. Just click it and then click "delete" in A2DP Volume. If it is in the list it will hold the foreground notification active.

JoLander commented 5 years ago

@jroal I never had the smart watch in the list of devices in a2dpvolume. After installation I always hit the search devices button and remove all unwanted devices. There is only my car and my headset present. As I did an update of my older version with the new one before, I decided to deinstall/reinstall the app. Seems that the null device is gone now. I also played around with the android notification settings and it seems that I need to allow all notifications (foreground and background) to have the app working correctly. Even when no device is connected I must allow a persistent notification as shown in the attachment. With this setting, the icon appear/disappear correctly and the notification changes between connected and not connected. Every attempt to remove the notification when there is no connection will force the earlier mentioned behavior. screenshot_20190125_184604_com teslacoilsw launcher

JoLander commented 5 years ago

Hi @jroal, unfortunately, the 'connection to null' reappeared. This happens with version 11.3 as well as the most recent version 11.4. I reverted back to 11.1 which do not show this behavior. With 11.1 the notification and icon behaves correctly as long as I accept the 'text to speech ready' notification while not connected to a configured device.

jroal commented 5 years ago

In finally duplicated the issue on my phone. I have to turn Bluetooth OFF to cause it. Working on it...

jroal commented 5 years ago

I created and tested 2.12.11.5 and this seems to fix it for me. Before I push to beta, can some others please test? It is here: https://1drv.ms/u/s!AgUbpiol3wYLvHUjskUEBbYVX4Rn

JoLander commented 5 years ago

I did some tests with the new version, but it wasn't really satisfying. The 'null' device seems to have gone, but the disconnect from known devices are not detected anymore. In the notification and the statusbar the icon and connection message still persist when I disconnect a device. When I open a2dpvolume, the message and the icon immediately disappear. No need to hit any button. But it doesn't work automatically. I also recognized that I cannot set the icon visibility in the app. This option is grayed and cannot be selected anymore.

jroal commented 5 years ago

Is the app crashing? Is the service stopped?

JoLander commented 5 years ago

There was no app crash and the service was still running, but it seems that I had not enough patience to let things happen. I tested again and it seems that it sometimes need more time to let things disappear. I disconnected my headset again and switched on my phone after some time. Now the icon and the notification are disappeared. Tomorrow I will do mor testing in my car...

jroal commented 5 years ago

Now it also broke the device specific location capture. I have many broken things to fix here. I am dealing with null exceptions all over and I have problems with the array of connected devices used in the service. Seems like I fix 1 issue and create 3 more.

The disconnect needs to complete location capture before it returns to the not connected notification (background).

I did remove the app notification settings as these are now managed in Android, not the app. See the details here: https://github.com/jroal/a2dpvolume/wiki/Notification-Icon-Settings

JoLander commented 5 years ago

Hi Jim, I hope you get the things sorted out. I'm not sure what other life you have apart from this project, but this might be a challenging task. You mentioned the location thing, but I don't use it for my headset and switched it off in your app. Even if it might be useful for others, I'm mainly interested in having notifications read out loud.

jroal commented 5 years ago

I did a bunch more work to fix this and it works on the Pixel 2 emulator and my Moto Z2. Can you please test this: https://1drv.ms/u/s!AgUbpiol3wYLvHb3vJ-MvbssnkzY

JoLander commented 5 years ago

Actually, this version (11.6) shows the connection Icon and the notification when connecting my headset, but after about 2-4 seconds the icon and the notification disappear and only the standard message (TTS ready) is shown. In a2dpvolume it is not shown as connected (there are no '**').

JoLander commented 5 years ago

I created a new logcat from this situation. From my viewpoint, the problem seems to be somewhere in this area:

01-28 12:27:37.547 20373 20373 I A2DP_Volume: Broadcast received: TaoTronics TT-BH15, TaoTronics TT-BH15: a2dp.Vol
...
01-28 12:27:40.874 20373 20373 I A2DP_Volume: Unknown device received, ignoring: a2dp.Vol
...
01-28 12:27:44.172 20373 20373 I A2DP_Volume: Unknown device disconnect received, ignoring: a2dp.Vol
...
01-28 12:27:44.181  1268  8671 I am_crash: [20373,0,a2dp.Vol,948485700,java.lang.NullPointerException,Attempt to invoke virtual method 'boolean java.lang.String.equalsIgnoreCase(java.lang.String)' on a null object reference,service.java,954]: system_server
...
01-28 12:27:44.191 20373 20373 I Process : Sending signal. PID: 20373 SIG: 9: a2dp.Vol
01-28 12:27:44.192  2080  2368 I AppManager: removeProcessDependency pid:20373: com.huawei.powergenie
01-28 12:27:44.242  1268  1782 I am_proc_died: [0,20373,a2dp.Vol,200,3]: system_server
01-28 12:27:44.242  1268  1311 W libprocessgroup: kill(-20373, 9) failed: No such process: system_server
01-28 12:27:44.242  1268  1311 I libprocessgroup: Successfully killed process cgroup uid 10226 pid 20373 in 0ms: system_server

Another thing I saw in the log was the following line: 01-28 12:27:37.547 20373 20373 V AudioManager: getStreamVolume treamType: 3: a2dp.Vol

Could this be a typo ??

logcat1.zip

JoLander commented 5 years ago

Short update. It seems that this happens with my headset only. The connection to my car entertainment system worked without problems.

jroal commented 5 years ago

I just pushed 2.12.11.7 to beta. Please test and let me know where we stand on this. The logcat files are very helpful, thanks. I added additional log file entries into this version to better see what is happening.

JoLander commented 5 years ago

Hi @jroal , I tried the new version, but the behaviour is similar to the last one. When I connect my car audio system all works fine (unfortunately, I do not have a logcat from this connect). When I connect my headset (TaoTronics TT-BH15), it shortly shows the connection (a few seconds), but then it seems that the a2dpvolume service crashes and is restarted without recognizing that the headset is still connected to the phone. The headset itself is working fine, so the bluetooth connection seems to be ok. I attached another Logcat.

logcat2.zip

JoLander commented 5 years ago

@jroal just to be on the safe side I reinstalled version 11.1 on my phone to see how it works. With 11.1 I do not get the mentioned problem and a2dpvolume works fine when I connect my headset. After that I created another logcat from the old version and filtered the output to have only a2dpvolume related messages. I did the same with the logcat from 11.7 and made a verification of both versions. I put some comments in the files and placed the result here as attachment. Maybe you want to have a look....

special_logs.zip

jroal commented 5 years ago

@JoLander that was very helpful! I found the null error where the disconnected device was not recognized and then it ran DoDisconneced function anyway. I fixed 2 places, the first where it called DoDisconnected with an unknown device (that should never happen) and also within DoDisconnected I now check for the null device before trying to remove it from the currently connected device list. So it looks like 2 devices not in the database disconnected and my app incorrectly tried to run DoDisconnected on a null device.

I made the changes and uploaded a test file 2.12.11.8. Please give that a try and let me know how it works. Thanks for your help and patience.

jroal commented 5 years ago

A friend who was also having an issue like this just tested 2.12.11.8 on his Pixel 2 and it now works correctly. Please install and test and let me know how it works for you. I pushed it to beta on the Play Store now as well.

JoLander commented 5 years ago

Hi @jroal , the version 11.8 works much better now. I do not have crashes anymore when I connect my devices and the headset connection works without problems.

There is just one thing left regarding notifications: When I allow all notifications for a2dpvolume in Android, I have a persistent message in the notification area which simply says that TTS is ready when there is no device connected. The other behaviour when connecting/disconnecting devices is correct. Now I would like to get rid of the persistant notification when no device is connected, and have one only if a configured device connects. Therefore, I disabled the background notification in the Android notification settings. After this, the persistent message immediately disappears. Fine so far... Unfortunately, with disabled background notifications, I receive a correct notification message and statusbar icon on connect of a device, but there is no change to these messages on disconnect. They simply stay on the screen.

As I'm curious whats going on, I produced again some logs and checked for the differences. It seems that on device connection, all messages are handled with the forground message channel (a2dp_foreground) while all disconnect messages are handled via the background channel (a2dp_background). If background notifications are disabled in the system, the background changes are simply ignored.

I added a few screenshots to show the different behaviour when the background messaging is enabled/disabled. In addition I added parts of a log which shows the message processing in a2dpvolume with enabled and disabled background notification. As the disconnect communicates only via a2dp_background, there might be a chance to get rid of the persistent messages when using the forground channel instead. (but as I'm not a programmer, I cannot judge if this is possible).

screenshots.zip log_msg.txt

jroal commented 5 years ago

@JoLander if you turn off that notification completely Android will kill the service. Instead do this https://github.com/jroal/a2dpvolume/wiki/Notification-Icon-Settings

JoLander commented 5 years ago

Hi Jim, I already tried a lot of settings, but without success. Just to show you what options I have, I switched my phone language to english. This is the message I see when I pull down the notification shade when no device is connected:

screenshot_20190131_184518_com teslacoilsw launcher

I do not want this notification when no device is connected. The 'TTS Ready' is useless here. And these are the options I have when I try to manage the background notification options:

screenshot_20190131_184623_com huawei systemmanager

jroal commented 5 years ago

@JoLander your settings should give you a minimized notification I think. Those settings are different as you have a different launcher than any of my devices or emulators.

Here is what it looks like in a Pixel 2 screenshot_1548978043 The notification does not show on the status bar. You can see it minimized in the shade. To see the TTS Ready you have to open the minimized notification. That is about as non-intrusive as it is going to get and still keep the service running. The Pixel 2 settings look like this. This is after I open notification settings -> A2DP Volume -> background notification. screenshot_1548978093 and the behavior opens these options. screenshot_1548978077

Bottom line, if you disable the background notification the service will be killed. I cannot fix that it is how Android works. Running a background service without an active notification is no longer allowed. They consider that spyware I guess. The settings you show in your last post are not disabled though. That setting should work and it should not show on your status bar. Does that not work?

jroal commented 5 years ago

I did find some issues with the service OnDestroy function that may leave the notification when the service is killed. Try this: https://1drv.ms/u/s!AgUbpiol3wYLvQbR32DO8KVM2LRg. The service will still get killed I suspect but now it should show it in the log and hopefully remove the notification.

JoLander commented 5 years ago

Hi @jroal, first, I do not see any differences between the 11.8 and 11.9test versions. When I disable the background notification, I get a correct icon and notification on device connect, but when the device disconnects, the icon and notification doesn't disappear. When background and foreground notifications are enabled, the behaviour is correct and the same in both versions.

Secondly, I can only partly agree to your comment about the notifications. The different settings in my notification management are probably based on the EMUI 9 System which is running on my Huawei Mate 20 Pro. When all (foreground and background) notifications are allowed, I do have the same result as you got on the Pixel. When no device is connected, I have no icon in the statusbar and only a small 'TTS Ready' message when I pull down the notification shade. But I have a lot of other Apps running in the background which do not show any notifications and do not get killed. In an earlier screenshot from a pulled down notification shade, you might have recognized the connection message from my Samsung Gear smartwatch. In the notification management for the Gear App, I have a lot more options as I find in the a2dpvolume App. There is a specific option to disable the connection message. When I do this, there is no longer a notification when I pull down the notification shade, but the connection is still working in the background. Therefore, I think there are programming options to handle this.

Attached you see a screenshot from the notification management of the a2dpvolume app and the Samsung Gear plugin which handles the communication to the phone. You can see the different options there.

Nevertheless, since version 11.8, the App is running fine when all notifications are allowed. I personally can live with the persistent 'TTS Ready' message when no device is connected. So please do not spent more time in the research (except you want to).

Notification settings for a2dpvolume: notifications_a2dp

Notification settings for the Samsung Gear Plugin: notifications_gear

JoLander commented 5 years ago

Please find attached also the log from version 11.9 when the background notification is disabled. There is no indication that the app is killed, but the notification and icon which are shown on device connect are not removed when device disconnects. log_11.9.txt

jroal commented 5 years ago

I am going by this: https://developer.android.com/guide/background/ . There are other things that can do certain things and not be in the foreground but I have not spent the time to work out how to do that with this app. If you run something like Tasker, it requires a foreground notification to operate fort he same reasons this app does. In the case of this app it has system triggers and does need to complete otherwise the features just won't work at times. If you scroll down that page you will also see Android has made more restrictions on background process in later versions. Also, the app may not get killed immediately. Android will kill it as needed for memory. If you are not using much memory at the time they may run for a while, or not.

It is strange that the notification stays even after you can see in the log that all notifications were cancelled multiple times on disconnect. I don't know why that would happen. I would have expected the service to possible get killed at times but when that happens the notifications should also be cleared. It is strange the UI is not clearing them even after the request to clear multiple times. Does anything crash during this time? It looks like a partial log file.

By the way, the TTS ready message is used to let the user know they have the text to speech engine up and running and ready to read out notifications. This is helpful when you are trying to get that set up. I had a toast message for that before but now I just put it in the notification that had to be there anyway.

JoLander commented 5 years ago

The log I attached to my last comment was reduced to messages related to the PID of your App. There was no kill signal or anything else in the full log which points to a killed service. With background notification disabled, I think the systems simply ignores any message routed to the background channel. As I said before, please do not spent more time on this issue. I'm glad that I was helpful to identify some other issues and I can live fine with the way the app works now. This app is far too useful to get bored by a message in the notification area. I simply accept it.