jroal / a2dpvolume

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

App crashes when attempting to set volume #250

Closed jroal closed 5 years ago

jroal commented 6 years ago

java.lang.SecurityException: at android.os.Parcel.readException(Parcel.java:1620) at android.os.Parcel.readException(Parcel.java:1573) at android.media.IAudioService$Stub$Proxy.setStreamVolume(IAudioService.java:961) at android.media.AudioManager.setStreamVolume(AudioManager.java:1340) at a2dp.Vol.service.setVolume(service.java:1027) at a2dp.Vol.service$7.onFinish(service.java:694) at android.os.CountDownTimer$1.handleMessage(CountDownTimer.java:127) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:158) at android.app.ActivityThread.main(ActivityThread.java:7225) at java.lang.reflect.Method.invoke(Native Method:0) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)

cprhokie commented 6 years ago

According to the documentation for the setStreamVolume call it can throw an exception on N or higher if the app is not granted do-not-disturb access if the call would trigger toggling do-not-disturb. I just got an N device so I will see if I can replicate this.

jroal commented 6 years ago

Thanks for helping. Let me know what you find.

cprhokie commented 6 years ago

What kind of device was this? The only ways I have been to generate the same exception are with a demo app that sets the notification volume instead of the music stream volume - or by using an android tv emulator (because the music and notification streams are the same on an android tv device). In any case the same issue appears here with a solution that the settings page where the user can enable the DND override: https://github.com/OpenLauncherTeam/openlauncher/issues/67. Also need to add permission android.permission.ACCESS_NOTIFICATION_POLICY.

jroal commented 6 years ago

Thanks for finding this. I implemented that fix in 2.12.9.2. I was never able to duplicate this issue so I have no way to test the fix.

Here is more info on this issue: image It looks like all Samsung devices but then again, Samsung sells the most Android devices.

I just pushed 2.12.9.2 to Alpha on the Play Store. Please test this and let me know the results.

cprhokie commented 6 years ago

I think you need the fix when not ramping the volume also. Also you probably should just ignore the security exception in the ontick method because you don't want to start an activity possibly multiple times.

jroal commented 6 years ago

Good points. I will make those changes.