Question

As the title states AudioManager.isMicrophoneMute() always returns false, no matter what.

The setup:

Manifest includes this permission because of an older bug that could be related to this. Old bug was about checking if headphones are used. Doesn't help, but doesn't hurt either.

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

  1. Initiate a call into the emulator from telnet.
  2. Pick up phone
  3. Check app - status audioManager.getMode() == audioManager.MODE_IN_CALL is true. Ok, we're good
  4. Status check audioManager.isMicrophoneMute() is false - ok, we're still good
  5. Switch back to phone and press the Mute button
  6. Switch to app, check audioManager.isMicrophoneMute() and it's still false - no good. should be true.

So is this a broken API? Or do I need some other permissions? Or does this not work on Emulator??

Thank you.

Was it helpful?

Solution 2

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

OTHER TIPS

I've made a small research and check the sources of Android. Actually, the problem is in the default Phone application in the file packages/apps/Phone/src/com/android/phone/PhoneUtils.java. Here is 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 click on Mute button Phone application checks the parameter R.bool.send_mic_mute_to_AudioManager, which is installed to false (I checked in the sources). Thus, in this case the state is to phone, which is an instance of GSMPhone class. This class communicates with RIL socket and send there appropriate request to setMute (RIL_REQUEST_SET_MUTE). Thus, nowhere on the path of the command the state of AudioManager is updated. Similarly, I do not see that AudioManager notifies to RIL when it change the state of the microphone.

Thus, if you ask AudioManager about the state of microphone it returns the default value (which is false). I do not know if this behavior is expected or is this a bug. You can ask question in the android-platform group and make a link to this question and bug.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top