phhusson / treble_experimentations

Notes about tinkering with Android Project Treble
3.38k stars 655 forks source link

Redmi Note 9T 5G (cannon/cannong) In-Call volume not adjustable #1908

Closed dsclee1 closed 1 year ago

dsclee1 commented 3 years ago

I can't adjust the in-call volume on my device. Logcat suggests the button press is being recognised (and the change displays on the slider on screen), but there's no effect on the volume. Full Logcat is attached. Here's an example of a relevant section after a volume button press: logcat.txt

06-18 14:27:53.461  1722  3794 D MediaSessionService: Adjusting com.android.server.telecom/HeadsetMediaButton (userId=0) by -1. flags=4113, suggestedStream=-2147483648, preferSuggestedStream=false
06-18 14:27:53.464  1722  3794 D MediaSessionService: dispatchVolumeKeyEvent, pkg=com.google.android.dialer, opPkg=com.google.android.dialer, pid=10813, uid=10151, asSystem=true, event=KeyEvent { action=ACTION_UP, keyCode=KEYCODE_VOLUME_DOWN, scanCode=114, metaState=0, flags=0x8, repeatCount=0, eventTime=6518763, downTime=6518636, deviceId=2, source=0x101, displayId=-1 }, stream=-2147483648, musicOnly=false
06-18 14:27:53.464  1722  3794 D MediaSessionService: Adjusting com.android.server.telecom/HeadsetMediaButton (userId=0) by 0. flags=4116, suggestedStream=-2147483648, preferSuggestedStream=false
06-18 14:27:53.474  1017  1197 I hwcomposer: [DPY] receive refesh frquest from driver: type[4]
06-18 14:27:53.474  1017  1197 I hwcomposer: [HWC] fire a callback of refresh to SF
06-18 14:27:53.476  1937  2237 I vol.Events: writeEvent level_changed STREAM_VOICE_CALL 3
06-18 14:27:53.480  1610  1620 D AudioALSAHardware: setVoiceVolume(), volume = 0.600000, mUseTuningVolume = 0
06-18 14:27:53.480  1610  1620 D AudioALSAStreamManager: setVoiceVolume(), volume = 0.600000
06-18 14:27:53.480  1610  1620 D AudioMTKGainController: setVoiceVolume(), index = 4, devices = 0x1, mode = 2, mBand = 1, mNetwork = 0, mVoiceVolume = 0.600000
06-18 14:27:53.480  1610  1620 D SpeechDriverOpenDSP: SetDownlinkGain(), gain = 0x0, old mDownlinkGain = 0x0
06-18 14:27:53.481  1610  1620 D AudioMTKGainController: ApplyMicGain(), analogidx = 2, mSceneIndex = 0, _mic_mode = 1, _gain_device = 0, mode = 2, micgain = 23, mULTotalGain = 164, mBand = 1, mNetwork = 0
06-18 14:27:53.481  1610  1620 E AudioMTKGainController: SetAdcPga3(), Error: get mixer ctl fail,
06-18 14:27:53.481  1610  1620 D SpeechDriverOpenDSP: SetUplinkGain(), gain = 0x3c, old mUplinkGain = 0x3c
06-18 14:27:53.481  1610  1620 D AudioMTKGainController: GetSPKGain
06-18 14:27:53.481  1610  1620 D AudioMTKGainController: GetSPKGain i = 0 index = 31
06-18 14:27:53.481  1610  1620 D AudioMTKGainController: updateSidetone(), DSP_ST_GAIN = 0, positive_gain_db = 0, dlPGAGain 0, sidetone 0, ulGain 15
06-18 14:27:53.481  1610  1620 D AudioMTKGainController: ApplySideTone gainDevice 0, sidetone 0, updated_sidetone 0
06-18 14:27:53.490  1937  2237 I vol.Events: writeEvent key STREAM_VOICE_CALL 3
06-18 14:27:53.500  1937  1937 I vol.Events: writeEvent show_dialog volume_changed keyguard=false

I'm also having an issue with headphones not being recognised by the audio jack, which could be related as it's tied in to the audio system, but the in-call volume problem is more of an issue right now.

I've already set "Bluetooth workarounds" to "Mediatek" and "Force-disable A2DP offload" to "on". This fixed bluetooth audio output, but not the in-call volume issue.

So far I've tried copying over the audio_policy files from the stock system image, but could see no change in my issue.

phhusson commented 3 years ago

Yup that's a global mediatek issue. So far I haven't found anything relevant to this.

Could you make the exact same logcat, but on stock rom?

Le ven. 18 juin 2021 à 16:19, David @.***> a écrit :

I can't adjust the in-call volume on my device. Logcat suggests the button press is being recognised (and the change displays on the slider on screen), but there's no effect on the volume. Full Logcat is attached. Here's an example of a relevant section after a volume button press: logcat.txt https://github.com/phhusson/treble_experimentations/files/6677529/logcat.txt

06-18 14:27:53.461 1722 3794 D MediaSessionService: Adjusting com.android.server.telecom/HeadsetMediaButton (userId=0) by -1. flags=4113, suggestedStream=-2147483648, preferSuggestedStream=false 06-18 14:27:53.464 1722 3794 D MediaSessionService: dispatchVolumeKeyEvent, pkg=com.google.android.dialer, opPkg=com.google.android.dialer, pid=10813, uid=10151, asSystem=true, event=KeyEvent { action=ACTION_UP, keyCode=KEYCODE_VOLUME_DOWN, scanCode=114, metaState=0, flags=0x8, repeatCount=0, eventTime=6518763, downTime=6518636, deviceId=2, source=0x101, displayId=-1 }, stream=-2147483648, musicOnly=false 06-18 14:27:53.464 1722 3794 D MediaSessionService: Adjusting com.android.server.telecom/HeadsetMediaButton (userId=0) by 0. flags=4116, suggestedStream=-2147483648, preferSuggestedStream=false 06-18 14:27:53.474 1017 1197 I hwcomposer: [DPY] receive refesh frquest from driver: type[4] 06-18 14:27:53.474 1017 1197 I hwcomposer: [HWC] fire a callback of refresh to SF 06-18 14:27:53.476 1937 2237 I vol.Events: writeEvent level_changed STREAM_VOICE_CALL 3 06-18 14:27:53.480 1610 1620 D AudioALSAHardware: setVoiceVolume(), volume = 0.600000, mUseTuningVolume = 0 06-18 14:27:53.480 1610 1620 D AudioALSAStreamManager: setVoiceVolume(), volume = 0.600000 06-18 14:27:53.480 1610 1620 D AudioMTKGainController: setVoiceVolume(), index = 4, devices = 0x1, mode = 2, mBand = 1, mNetwork = 0, mVoiceVolume = 0.600000 06-18 14:27:53.480 1610 1620 D SpeechDriverOpenDSP: SetDownlinkGain(), gain = 0x0, old mDownlinkGain = 0x0 06-18 14:27:53.481 1610 1620 D AudioMTKGainController: ApplyMicGain(), analogidx = 2, mSceneIndex = 0, _mic_mode = 1, _gain_device = 0, mode = 2, micgain = 23, mULTotalGain = 164, mBand = 1, mNetwork = 0 06-18 14:27:53.481 1610 1620 E AudioMTKGainController: SetAdcPga3(), Error: get mixer ctl fail, 06-18 14:27:53.481 1610 1620 D SpeechDriverOpenDSP: SetUplinkGain(), gain = 0x3c, old mUplinkGain = 0x3c 06-18 14:27:53.481 1610 1620 D AudioMTKGainController: GetSPKGain 06-18 14:27:53.481 1610 1620 D AudioMTKGainController: GetSPKGain i = 0 index = 31 06-18 14:27:53.481 1610 1620 D AudioMTKGainController: updateSidetone(), DSP_ST_GAIN = 0, positive_gain_db = 0, dlPGAGain 0, sidetone 0, ulGain 15 06-18 14:27:53.481 1610 1620 D AudioMTKGainController: ApplySideTone gainDevice 0, sidetone 0, updated_sidetone 0 06-18 14:27:53.490 1937 2237 I vol.Events: writeEvent key STREAM_VOICE_CALL 3 06-18 14:27:53.500 1937 1937 I vol.Events: writeEvent show_dialog volume_changed keyguard=false

I'm also having an issue with headphones not being recognised by the audio jack, which could be related as it's tied in to the audio system, but the in-call volume problem is more of an issue right now.

I've already set "Bluetooth workarounds" to "Mediatek" and "Force-disable A2DP offload" to "on". This fixed bluetooth audio output, but not the in-call volume issue.

So far I've tried copying over the audio_policy files from the stock system image, but could see no change in my issue.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/phhusson/treble_experimentations/issues/1908, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAA4OVDS4JPR3VBRWHRPY3TTNIXNANCNFSM465YRDMQ .

dsclee1 commented 3 years ago

I'm a bit reluctant to go back to the stock rom at the moment as there's not currently a custom recovery for this phone that will do a full backup.

I'll ask on the XDA forum to see if anyone can provide a stock logcat with in-call volume adjustments. If not I'll do it myself tomorrow.

phhusson commented 3 years ago

Considering this issue is pretty widespread, it can even come from people with other mediatek devices with same issue.

Le dim. 20 juin 2021 à 16:58, David @.***> a écrit :

I'm a bit reluctant to go back to the stock rom at the moment as there's not currently a custom recovery for this phone that will do a full backup.

I'll ask on the XDA forum to see if anyone can provide a stock logcat with in-call volume adjustments. If not I'll do it myself tomorrow.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/phhusson/treble_experimentations/issues/1908#issuecomment-864567263, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAA4OQC3RBX7O3M4PZ7GTTTTX62PANCNFSM465YRDMQ .

dsclee1 commented 3 years ago

I've gone ahead and done it myself. Please see logcat attached.

The "KeyEvents" show where I've done the volume button presses. e.g.

06-22 10:08:32.634 14014 14014 D MIUIInput: [KeyEvent] ViewRootImpl KeyEvent { action=ACTION_UP, keyCode=KEYCODE_VOLUME_UP, scanCode=115, metaState=0, flags=0x8, repeatCount=0, eventTime=481361, downTime=481216, deviceId=2, source=0x101, displayId=-1 } MIUI 12.5 in call volume logcat.txt

dsclee1 commented 3 years ago

Just to add, my headphones issue was solved by turning on "Use alternate way to detect headsets".

The in-call volume is still an issue though.

phhusson commented 3 years ago

I guess the trick is in 06-22 10:08:32.664 607 3527 D AudioALSAStreamOut: +setParameters(): flag 2, volumeDevice=1;volumeIndex=3;volumeStreamType=0

I'll dig with that. Thanks.

dsclee1 commented 3 years ago

Thanks.

I was wondering if it's something to do with the "mBand" setting?

On the stock rom it's: 06-22 10:08:33.462 607 3527 D AudioMTKGainController: setVoiceVolume(), index = 4, devices = 0x1, mode = 2, **mBand = 0**, mNetwork = 0, mVoiceVolume = 1.000000

and on the custom rom it's: 06-18 14:27:53.480 1610 1620 D AudioMTKGainController: setVoiceVolume(), index = 4, devices = 0x1, mode = 2, **mBand = 1**, mNetwork = 0, mVoiceVolume = 0.600000

I had a browse around some code on GitHub (https://github.com/iykex/vendor_mediatek_proprietary_hardware/blob/a592a52719cb43d2364e9c4d641f68ff6442d959/audio/common/V3/aud_drv/AudioALSAGainController.cpp and https://github.com/PixelExperience/vendor_mediatek-opensource/blob/eleven/external/audio_utils/common_headers/gain_table/AudioGainTableParam.h), and it looks like the stock rom sets it to GAINSPEECHNB and the custom rom sets it to GAINSPEECHWB. I have no idea what this actually means in practice though? I couldn't find info on what the "band" means in this context.

dsclee1 commented 3 years ago

I've done a bit more digging. GAINSPEECHNB means Narrow Band and GAINSPEECHWB means Wideband, which from what I gather Wideband is VoLTE. I had a go at enabling VoLTE via the "IMS Features" to see if that would help, but I've turned on what it would let me, and "Install IMS APK" says "NOT SUPPORTED", so that idea is out.

I think what's happening is that the custom rom is assuming the call is in VoLTE mode, and attempting to change the volume for a VoLTE call, but in reality the call is running in standard narrow band mode, so the volume change isn't being applied - but I might still be completely wrong!

dsclee1 commented 3 years ago

I tried turning off VoLTE using any VoLTE setting from getprop:

I'm still seeing mBand = 1 in logcat when trying an in-call volume change: 06-24 08:19:49.604 1617 1885 D AudioMTKGainController: setVoiceVolume(), index = 4, devices = 0x1, mode = 2, mBand = 1, mNetwork = 0, mVoiceVolume = 0.600000

phhusson commented 3 years ago

Before going into side-effect stuff, you first need to look at first-effects -_-'

The line I quoted 06-22 10:08:32.664 607 3527 D AudioALSAStreamOut: +setParameters(): flag 2, volumeDevice=1;volumeIndex=3;volumeStreamType=0 exists in your stock rom, but NOT in AOSP. This is a command sent from framework to vendor, and it is NOT sent in AOSP.

So yeah if the command to set volume is not set, volume won't be set. No need to look into VoLTE for that

lapingv755 commented 3 years ago

I have attached my logcats. My device is a Blackview BV9500 Plus (MediaTek Helio P70) and i cannot adjust the in call volume as well. In my case the volume is on max on all of the following: headset, headphones, loudspeaker. I have not tried bt, so i cannot comment on that.

I am not sure if it's the same issue as my logcat looks a bit different stock: AudioMTKGainController: setVoiceVolume(), index = 1, devices = 0x1, mode = 2, mBand = 1, mNetwork = 0, mVoiceVolume = 1.000000

gsi: AudioMTKGainController: setNormalVolume(), mSceneIndex = 0, stream -1, devices 0x1, index -1, mode 0x0 AudioMTKGainController: error, stream -1 is invalid, use 3 instead AudioMTKGainController: error, index -1 is invalid, use max 15 instead

Both logs are somewhat old, but i can get new ones alongside anything else you need. stock.txt new_logcat.txt

dsclee1 commented 3 years ago

Before going into side-effect stuff, you first need to look at first-effects -_-'

The line I quoted 06-22 10:08:32.664 607 3527 D AudioALSAStreamOut: +setParameters(): flag 2, volumeDevice=1;volumeIndex=3;volumeStreamType=0 exists in your stock rom, but NOT in AOSP. This is a command sent from framework to vendor, and it is NOT sent in AOSP.

So yeah if the command to set volume is not set, volume won't be set. No need to look into VoLTE for that

Point taken! I've downloaded the source tree using the build.sh. I've run a search for "AudioALSAStreamOut", "AudioMTKGainController", and "AudioALSAHardware". But found no results. I can see results for the "setVoiceVolume" function, but these tie up to "AudioFlinger".

Am I even looking in the right place?

phhusson commented 3 years ago

Yes. That's precisely the issue. volumeDevice/volumeIndex commands are proprietary mediatek, and need to be added for this to work.

eremitein commented 3 years ago

AudioALSAStreamOut

there is some code on the Github https://github.com/search?q=AudioALSAStreamOut&type=code

Vgdn1942 commented 3 years ago

Yes. That's precisely the issue. volumeDevice/volumeIndex commands are proprietary mediatek, and need to be added for this to work.

I can provide ALPS android 9.0 source codes (t-alps-release-p0.mp1-V5.75.mt6750) if it can help. I do not yet have enough knowledge to deal with this problem alone.

dsclee1 commented 3 years ago

I've had a look at the sound controller down at the device level. If I run the following command as su during a call (using tinymix) I can reduce the in-call volume (CANNONG specific): tinymix 390 16

This sets "Handset Volume" to 16. The number needs to be between 0 and 18, and then 31 is mute. 0 is loud, 18 is quiet (I.E. the higher the number the quieter it is).

Mileage will vary depending on your device. You probably won't be lucky enough that "Handset Volume" is item 390 in tinymix for other devices, so you'll need to run tinymix yourselves and find out which number "Handset Volume" is registered under. Something like this should help: tinymix | grep 'Handset Volume'

@phhusson I don't know the feasibility of implementing this somehow as a framework code patch? It would obviously be very hacky.

phhusson commented 3 years ago

You should be able to do tinymix "Handset Volume" 16

But I don't want that in my GSI, since I'm expecting that the audio system parameters I've given earlier are enough to set volume

19 juil. 2021 18:24:43 David @.***>:

I've had a look at the sound controller down at the device level. If I run the following command as su during a call (using tinymix) I can reduce the in-call volume (CANNONG specific): tinymix 390 16

This sets "Handset Volume" to 16. The number needs to be between 0 and 18, and then 31 is mute. 0 is loud, 18 is quiet (I.E. the higher the number the quieter it is).

Mileage will vary depending on your device. You probably won't be lucky enough that "Handset Volume" is item 390 in tinymix for other devices, so you'll need to run tinymix yourselves and find out which number "Handset Volume" is registered under. Something like this should help: tinymix | grep 'Handset Volume'

@phhusson[https://github.com/phhusson] I don't know the feasibility of implementing this somehow as a framework code patch? It would obviously be very hacky.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub[https://github.com/phhusson/treble_experimentations/issues/1908#issuecomment-882684659], or unsubscribe[https://github.com/notifications/unsubscribe-auth/AAAA4OU3T6TLJ3JLZARVGU3TYRGUXANCNFSM465YRDMQ]. [data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADgAAAA4CAYAAACohjseAAAAAXNSR0IArs4c6QAAAARzQklUCAgICHwIZIgAAAAjSURBVGiB7cEBDQAAAMKg909tDwcUAAAAAAAAAAAAAADApwExOAABR9ZGcwAAAABJRU5ErkJggg==###24x24:true###][Image de pistage][https://github.com/notifications/beacon/AAAA4OQCLYKWE66GQX4WBWLTYRGUXA5CNFSM465YRDM2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOGSOLF4Y.gif]

xenon205 commented 3 years ago

But I don't want that in my GSI, since I'm expecting that the audio system parameters I've given earlier are enough to set volume

That's good to hear. We will wait for Your implementation. Thank You

phhusson commented 3 years ago

I didn't say I would do it... I don't have much time available

19 juil. 2021 20:39:52 xenon205 @.***>:

But I don't want that in my GSI, since I'm expecting that the audio system parameters I've given earlier are enough to set volume

That's good to hear. We will wait for Your implementation. Thank You

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub[https://github.com/phhusson/treble_experimentations/issues/1908#issuecomment-882771869], or unsubscribe[https://github.com/notifications/unsubscribe-auth/AAAA4OQDIEWJUGYA7RUXLQ3TYRWPRANCNFSM465YRDMQ]. [data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADgAAAA4CAYAAACohjseAAAAAXNSR0IArs4c6QAAAARzQklUCAgICHwIZIgAAAAjSURBVGiB7cEBDQAAAMKg909tDwcUAAAAAAAAAAAAAADApwExOAABR9ZGcwAAAABJRU5ErkJggg==###24x24:true###][Image de pistage][https://github.com/notifications/beacon/AAAA4OTBQCC6JXOBERHWD53TYRWPRA5CNFSM465YRDM2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOGSPAPHI.gif]

xenon205 commented 3 years ago

Fair enough maybe some one else will be able to pick up gloves :)

dsclee1 commented 3 years ago

As a short term solution, I've hacked together a script which can be used in Magisk (create it in /data/adb/service.d/).

#!/bin/sh
while [ "$(getprop sys.boot_completed | tr -d '\r')" != "1" ]; do sleep 1; done
sleep 1
# audio system min volume
inmin=$(/system/bin/service call audio 17 i32 0 | /system/bin/awk -F ' ' '{print $3}')
# audio system max volume
inmax=$(/system/bin/service call audio 18 i32 0 | /system/bin/awk -F ' ' '{print $3}')
# output max volume (lowest number)
outmax=$(/system/bin/tinymix "Handset Volume" | /system/bin/awk -F ' ' '{print $5}' | /system/bin/awk -F '-' '{print $1}')
# output min volume (highest number)
outmin=$(/system/bin/tinymix "Handset Volume" | /system/bin/awk -F ' ' '{print $5}' | /system/bin/awk -F '>' '{print substr($2,1,length($2)-1)}')
# calculate intervals (ceiling)
interval=$(/system/bin/expr $(/system/bin/expr $outmin + $inmax - 1) / $inmax)
# starting volume for audio system
incurrentold=$(/system/bin/service call audio 16 i32 0 | /system/bin/awk -F ' ' '{print $3}') 
# starting volume for hardware
outcurrent=$(/system/bin/tinymix "Handset Volume" --v)
outcurrentold=99
/system/bin/log -t MTKInCallDirtyFix "AudioManager Min Volume: $inmin"
/system/bin/log -t MTKInCallDirtyFix "AudioManager Max Volume: $inmax"
/system/bin/log -t MTKInCallDirtyFix "AudioManager Current Volume: $incurrentold"
/system/bin/log -t MTKInCallDirtyFix "Hardware Min Volume: $outmin"
/system/bin/log -t MTKInCallDirtyFix "Hardware Max Volume: $outmax"
/system/bin/log -t MTKInCallDirtyFix "Hardware Current Volume: $outcurrent"
/system/bin/log -t MTKInCallDirtyFix "Hardware Volume Interval: $interval"
/system/bin/log -t MTKInCallDirtyFix "Starting Service"
# loop
# run every 0.5 seconds
while true
do
  # check the handset is active
  outcurrent=$(/system/bin/tinymix "Handset Volume" --v)
  if [ "$outcurrent" -le "$outmin" ] && [ "$outcurrent" -ge "$outmax" ]
  then
    # get the audio system value and check that it's changed, or force it if it's the first entry to the call
    incurrent=$(/system/bin/service call audio 16 i32 0 | /system/bin/awk -F ' ' '{print $3}')
    if [ "$incurrentold" != "$incurrent" ] || [ "$outcurrentold" -gt "$outmin" ]
    then
      if [ "$incurrent" -ge "$inmax" ]
      then
        newhardwarevol=$outmax
      elif [ "$incurrent" -le "$inmin" ]
      then
        newhardwarevol=$outmin
      else
        # calculate the new hardware volume, by flipping the audio system volume round and multiplying by the interval
        flipvol=$(/system/bin/expr $inmax - $incurrent)
        newhardwarevol=$(/system/bin/expr $flipvol \* $interval)
      fi
      /system/bin/tinymix "Handset Volume" $newhardwarevol
      /system/bin/log -t MTKInCallDirtyFix "Hardware In-Call Volume: $newhardwarevol"
      incurrentold=$incurrent
    fi
  fi
  outcurrentold=$outcurrent
  sleep 0.5
done

It makes calls to the Audio service to work out Android's idea of what the volume should be, then calculates and applies it to the Hardware using tinymix. If anyone wants to try it out let me know how you get on.

chaoscreater commented 2 years ago

!/bin/sh

while [ "$(getprop sys.boot_completed | tr -d '\r')" != "1" ]; do sleep 1; done sleep 1

audio system min volume

inmin=$(/system/bin/service call audio 17 i32 0 | /system/bin/awk -F ' ' '{print $3}')

audio system max volume

inmax=$(/system/bin/service call audio 18 i32 0 | /system/bin/awk -F ' ' '{print $3}')

output max volume (lowest number)

outmax=$(/system/bin/tinymix "Handset Volume" | /system/bin/awk -F ' ' '{print $5}' | /system/bin/awk -F '-' '{print $1}')

output min volume (highest number)

outmin=$(/system/bin/tinymix "Handset Volume" | /system/bin/awk -F ' ' '{print $5}' | /system/bin/awk -F '>' '{print substr($2,1,length($2)-1)}')

calculate intervals (ceiling)

interval=$(/system/bin/expr $(/system/bin/expr $outmin + $inmax - 1) / $inmax)

starting volume for audio system

incurrentold=$(/system/bin/service call audio 16 i32 0 | /system/bin/awk -F ' ' '{print $3}')

starting volume for hardware

outcurrent=$(/system/bin/tinymix "Handset Volume" --v) outcurrentold=99 /system/bin/log -t MTKInCallDirtyFix "AudioManager Min Volume: $inmin"

Doesn't seem to work for me. I created a .sh file called "InCall_Volume.sh" and pasted your script into the file. Then I copied the file to /data/adb/service.d and restarted my phone. I don't see this in Magisk (probably because it's not a module), but I can see in Magisk logs it says "running service.d scripts". I made a test call and tried adjusting volume and it doesn't do anything...

but it could be because I'm using OctaviOS and not Lineage?

UPDATE: Looks like OctaviOS doesn't have tinymix under /system/bin......I then copied tinymix and put it in /system/bin and gave it full permissions. Restarted phone and it's still the same issue....

If I run "tinymix 390 16" in Termux while in a call, it lowers my volume so it is definitely working. However, the script itself doesn't seem to work...

If I run the script in Termux, I get this:

line 42: syntax error near unexpected token 'elif' elif [ "$incurrent" -le "$inmin" ]

UPDATE 2: I'm now using Lineage and it still doesn't work for me. If I run it in Termux, it works, but it doesn't work if I put the script in service.d for Magisk......btw, have to run Termux as su first in order to run script.

UPDATE 3: OK, I got it working now. Here's how I did it:

I don't know why, but if I copy the script from my PC to my microSD card and then from there, copy it to service.d, it won't work. I have to edit the script in Termux first.

Also, you may need to put in "sleep 10" (without quotations) in the 2nd line of the script. I read somewhere that this is required, as the script may be executed too quickly during startup and not actually run or something like that.

Anyway, I just switched back to OctaviOS and did all the above and confirmed that the fix is working.

My only concern is, does this script create a wakelock or use up battery? If it needs to be running/monitoring in the background constantly, then I'm not sure how good this is for the battery. Having said that, I also don't understand the script and I'm not a programmer....

dsclee1 commented 2 years ago

Great to hear you got it working, and thanks for the tip on the "sleep 10".

I've had the script running on my phone for a few months now, and I haven't noticed any impact on the battery (I charge my phone each day, and after a full day of my use I still have over 70% battery left). I think most phones have a lot more running in the background anyway, so this script is pretty lightweight.

Vgdn1942 commented 2 years ago

How to find out your value in tinymix? I tried everything, but none of them change the ringer volume. Here are my values:

Mixer name: 'mt-snd-card'
Number of controls: 125
ctl type    num name                                     value

0   ENUM    1   Audio_Amp_R_Switch                       Off
1   ENUM    1   Audio_Amp_L_Switch                       Off
2   ENUM    1   Voice_Amp_Switch                         Off
3   ENUM    1   Speaker_Amp_Switch                       Off
4   ENUM    1   Headset_Speaker_Amp_Switch               Off
5   ENUM    1   Headset_PGAL_GAIN                        -40Db
6   ENUM    1   Headset_PGAR_GAIN                        -40Db
7   ENUM    1   Handset_PGA_GAIN                         0Db
8   ENUM    1   Lineout_PGAR_GAIN                        8Db
9   ENUM    1   Lineout_PGAL_GAIN                        -40Db
10  ENUM    1   AUD_CLK_BUF_Switch                       (null)
11  ENUM    1   Ext_Speaker_Amp_Switch                   Off
12  ENUM    1   Receiver_Speaker_Switch                  Off
13  ENUM    1   PMIC_REG_CLEAR                           Off
14  INT 1   Codec_ADC_SampleRate                     32000
15  INT 1   Codec_DAC_SampleRate                     32000
16  INT 2   DcTrim_DC_Offset                         -7 8
17  ENUM    1   Dctrim_Control_Switch                    Calibrated
18  INT 1   Audio HP ImpeDance Setting               436
19  ENUM    1   Headphone Plugged In                     Off
20  ENUM    1   Audio_ADC_1_Switch                       Off
21  ENUM    1   Audio_ADC_2_Switch                       Off
22  ENUM    1   Audio_ADC_3_Switch                       Off
23  ENUM    1   Audio_ADC_4_Switch                       Off
24  ENUM    1   Audio_Preamp1_Switch                     OPEN
25  ENUM    1   Audio_ADC_1_Sel                          Preamp
26  ENUM    1   Audio_ADC_2_Sel                          Preamp
27  ENUM    1   Audio_ADC_3_Sel                          idle
28  ENUM    1   Audio_ADC_4_Sel                          idle
29  ENUM    1   Audio_PGA1_Setting                       12Db
30  ENUM    1   Audio_PGA2_Setting                       12Db
31  ENUM    1   Audio_PGA3_Setting                       0Db
32  ENUM    1   Audio_PGA4_Setting                       0Db
33  ENUM    1   Audio_MicSource1_Setting                 ADC1
34  ENUM    1   Audio_MicSource2_Setting                 ADC1
35  ENUM    1   Audio_MicSource3_Setting                 ADC1
36  ENUM    1   Audio_MicSource4_Setting                 ADC1
37  ENUM    1   Audio_MIC1_Mode_Select                   ACCMODE
38  ENUM    1   Audio_MIC2_Mode_Select                   ACCMODE
39  ENUM    1   Audio_MIC3_Mode_Select                   ACCMODE
40  ENUM    1   Audio_MIC4_Mode_Select                   ACCMODE
41  ENUM    1   Audio_Mic_Power_Mode                     normal
42  ENUM    1   Audio_Preamp2_Switch                     OPEN
43  ENUM    1   Audio_UL_LR_Swap                         Off
44  ENUM    1   Audio_Vow_ADC_Func_Switch                Off
45  ENUM    1   Audio_Vow_Digital_Func_Switch            Off
46  ENUM    1   Audio_Vow_MIC_Type_Select                HandsetAMIC
47  INT 1   Audio VOWCFG0 Data                       0
48  INT 1   Audio VOWCFG1 Data                       0
49  INT 1   Audio VOWCFG2 Data                       8738
50  INT 1   Audio VOWCFG3 Data                       34663
51  INT 1   Audio VOWCFG4 Data                       110
52  INT 1   Audio VOWCFG5 Data                       1
53  INT 1   Audio_VOW_State                          0
54  INT 1   Audio_VOW_Periodic                       0
55  ENUM    1   SineTable_DAC_HP                         Off
56  ENUM    1   DAC_LOOP_DAC_HS                          Off
57  ENUM    1   DAC_LOOP_DAC_HP                          Off
58  ENUM    1   Voice_Call_DAC_DAC_HS                    Off
59  ENUM    1   SineTable_UL2                            Off
60  ENUM    1   Pmic_Loopback                            Off
61  INT 1   Codec_Debug_Enable                       0
62  INT 1   Audio AUXADC Data                        0
63  ENUM    1   Audio_capture_hd_Switch                  Off
64  INT 1   Audio IRQ2 CNT                           0
65  ENUM    1   capture_use_adc2_for_ch1_ch2             Off
66  INT 1   Speech_A2M_Msg_ID                        0
67  INT 1   Speech_MD_Status                         0
68  INT 1   Speech_MD_Ext_Status                     0
69  BOOL    1   Speech_Mic_Mute                          Off
70  BOOL    1   Speech_DL_Mute                           Off
71  BOOL    1   Speech_UL_Mute                           Off
72  INT 1   Speech_Phone1_MD_Idx                     0
73  INT 1   Speech_Phone2_MD_Idx                     0
74  BOOL    1   Speech_Phone_ID                          Off
75  BOOL    1   Speech_MD_EPOF                           Off
76  BOOL    1   Speech_BT_SCO_WB                         Off
77  BOOL    1   Speech_MD_Active                         Off
78  ENUM    1   loopback_use_single_input                Off
79  ENUM    1   LPBK_IN_USE_LCH                          Off
80  ENUM    1   Audio_i2s0_SideGen_Switch                Off
81  ENUM    1   Audio_i2s0_hd_Switch                     Off
82  ENUM    1   Audio_always_hd_Switch                   Off
83  ENUM    1   Audio_ExtCodec_EchoRef_Switch            Off
84  INT 1   Audio Mrgrx Volume                       65536
85  ENUM    1   cmb stub Audio Control                   CMB_STUB_AIF_0
86  ENUM    1   Audio_I2S0dl1_hd_Switch                  Off
87  INT 1   Audio IRQ1 CNT                           0
88  ENUM    1   deep_buffer_dl_hd_Switch                 Off
89  INT 1   deep_buffer_irq_cnt                      0
90  ENUM    1   dl1bt_memif_select                       dl1
91  ENUM    1   Audio_FMTX_hd_Switch                     On
92  ENUM    1   Audio_SineGen_Switch                     OFF
93  ENUM    1   Audio_SineGen_SampleRate                 48K
94  ENUM    1   Audio_SineGen_Amplitude                  1/2
95  ENUM    1   Audio_Sidetone_Switch                    Off
96  INT 1   Sidetone_Gain                            0
97  INT 1   Sidetone_Positive_Gain_dB                0
98  ENUM    1   Audio_Mode_Switch                        Normal_Mode
99  ENUM    1   Audio_Debug_Setting                      Off
100 ENUM    1   Audio_Ipoh_Setting                       Off
101 ENUM    1   Audio_I2S1_Setting                       Off
102 INT 2   Audio_DL2_DataTransfer                   -1 -1
103 INT 1   Audio_LowLatency_Debug                   0
104 ENUM    1   Audio_DPD_Switch                         Off
105 INT 1   Audio_Assign_DRAM                        0
106 ENUM    1   MTK_SPK_TYPE_GET                         MTK_SPK_NOT_SMARTPA
107 ENUM    1   Pmic_Anc_Switch                          ANCON
108 INT 1   Audio FM I2S Volume                      65536
109 ENUM    1   fast_dl_hd_Switch                        Off
110 ENUM    1   btcvsd_band                              NB
111 ENUM    1   btcvsd_tx_mute                           Off
112 ENUM    1   btcvsd_rx_irq_received                   No
113 ENUM    1   btcvsd_rx_timeout                        No
114 BYTE    16  btcvsd_rx_timestamp                       00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00
115 ENUM    1   btcvsd_tx_timeout                        No
116 ENUM    1   BT_DIRECT_LOOPBACK                       Off
117 BYTE    16  btcvsd_tx_timestamp                       00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00
118 ENUM    1   USB_Modem_Select                         md1
119 ENUM    1   USB_Voice_UL_Select                      primary
120 ENUM    1   USB_Voice_Loopback_Switch                Off
121 INT 1   USB_Voice_Debug                          0
122 INT 1   USB_Voice_Echo_Ref                       0
123 ENUM    1   USB_EchoRef_Modem_Select                 md1
124 INT 1   USB_EchoRef_Voice_Debug                  0
dsclee1 commented 2 years ago

Sorry, I'm not sure on how to identify which one would be your ring volume based off the names. I had to do as trial an error (the same as it sounds like you've tried!).

What I can say is that the you might find 0 (zero) is actually the maximum volume and the minimum is a higher value (say 9), so you might want to experiment with changing some of the zeroes to higher numbers and see if that reduces the ring volume?

chaoscreater commented 2 years ago

You need to use service call audio.

This is mentioned in one of the comments above:

service call audio 17 i32 0
service call audio 18 i32 0

The number is gonna be different for different phones, but is usually the same for different models of the same phone brand. Take a look at this as an example, it's very similar and shows you how to get the number: https://stackoverflow.com/questions/48696898/turning-off-second-sim-via-adb-shell-tasker-using-activities-intents

I used the link above to find the number for turning off my 2nd SIM card via Tasker. As long as you know what function to look for, you should be able to find the number you need for service call audio. Don't ask me on this though, I won't know what the function is for that.

LinkBoi00 commented 2 years ago

I understand this is beyond the scope of treble but here is a simple audio parameters config fix which fixes in call volume adjustment for the earpiece. This is at least better than the bash scripts some people have been temporarily using hence why I am posting this here, just sharing knowledge. https://gitlab.com/LinkBoi00/android_vendor_xiaomi_cannon/-/commit/4f353ba72199d20ba1fd21a45e1e4a1a4398145e

dsclee1 commented 2 years ago

I understand this is beyond the scope of treble but here is a simple audio parameters config fix which fixes in call volume adjustment for the earpiece. This is at least better than the bash scripts some people have been temporarily using hence why I am posting this here, just sharing knowledge. https://gitlab.com/LinkBoi00/android_vendor_xiaomi_cannon/-/commit/4f353ba72199d20ba1fd21a45e1e4a1a4398145e

This is a much better solution. Tested and confirmed working using Magisk (MTKInCallVolume.zip).

I'd be interested to know if this fixes the global Mediatek issue or just our Note9Ts?

olsdf commented 1 month ago

This method's does not work for me((