Android sdk error - AudioManager.isMicrophoneMute () always false

Because header states AudioManager.isMicrophoneMute()

always return false no matter what.

Setting:

The Manifest is enabling this permission due to an older bug that may be related to it. An old mistake was checking the use of headphones. It doesn't help, but it doesn't hurt either.

<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />

  • Initiate a call to the emulator from telnet.
  • Pick up your phone.
  • Check app - status audioManager.getMode() == audioManager.MODE_IN_CALL

    - true

    . Ok we are good
  • Status check AudioManager.isMicrophoneMute()

    false

    - good, we're still good
  • Go back to the phone and press the Mute button
  • Switch to the application, check AudioManager.isMicrophoneMute()

    and still false

    - nothing good. must be true.

So is this a broken API? Or do I need other permissions? Or does it not work on the emulator?

Thank.

+3


source to share


2 answers


This now works in 5.x Lollipop. Still doesn't work in 4.x. Maybe Google just won't fix it for an older OS.



0


source


I did a little research and checked Android sources. Actually the problem is with the default Phone app in the file packages/apps/Phone/src/com/android/phone/PhoneUtils.java

. Here's the function:

 /**
 * Internally used muting function.
 */
private static void setMuteInternal(Phone phone, boolean muted) {
    final PhoneGlobals app = PhoneGlobals.getInstance();
    Context context = phone.getContext();
    boolean routeToAudioManager =
        context.getResources().getBoolean(R.bool.send_mic_mute_to_AudioManager);
    if (routeToAudioManager) {
        AudioManager audioManager =
            (AudioManager) phone.getContext().getSystemService(Context.AUDIO_SERVICE);
        if (DBG) log("setMuteInternal: using setMicrophoneMute(" + muted + ")...");
        audioManager.setMicrophoneMute(muted);
    } else {
        if (DBG) log("setMuteInternal: using phone.setMute(" + muted + ")...");
        phone.setMute(muted);
    }
    app.notificationMgr.updateMuteNotification();
}

      



You can see that if you press the Mute button, the Phone app checks for the parameter R.bool.send_mic_mute_to_AudioManager

that is set to false

(I checked in sources). So in this case it is the state of the phone, which is an instance of the GSMPhone class. This class binds to the RIL socket and dispatches the appropriate setMute ( RIL_REQUEST_SET_MUTE

) request . Thus, the state of the AudioManager is not updated anywhere in the command path. Likewise, I don't see the AudioManager notifying RIL when it changes the state of the microphone.

Thus, if you ask AudioManager about the state of the microphone, it will return the default (which is false). I don't know if this is expected behavior or if it's a bug. You can ask a question in the android-platform group and link to this question and error.

+4


source







All Articles