Loading core/java/android/hardware/input/IInputManager.aidl +3 −0 Original line number Diff line number Diff line Loading @@ -76,6 +76,9 @@ interface IInputManager { // Registers a tablet mode change listener void registerTabletModeChangedListener(ITabletModeChangedListener listener); // Queries whether the device's microphone is muted by switch int isMicMuted(); // Input device vibrator control. void vibrate(int deviceId, in long[] pattern, int repeat, IBinder token); void cancelVibrate(int deviceId, IBinder token); Loading core/java/android/hardware/input/InputManager.java +16 −0 Original line number Diff line number Diff line Loading @@ -519,6 +519,22 @@ public final class InputManager { return -1; } /** * Queries whether the device's microphone is muted * * @return The mic mute switch state which is one of {@link #SWITCH_STATE_UNKNOWN}, * {@link #SWITCH_STATE_OFF} or {@link #SWITCH_STATE_ON}. * @hide */ @SwitchState public int isMicMuted() { try { return mIm.isMicMuted(); } catch (RemoteException ex) { throw ex.rethrowFromSystemServer(); } } /** * Gets information about all supported keyboard layouts. * <p> Loading media/java/android/media/AudioManager.java +26 −1 Original line number Diff line number Diff line Loading @@ -1856,13 +1856,38 @@ public class AudioManager { } } /** * @hide * Sets the microphone from switch mute on or off. * <p> * This method should only be used by InputManager to notify * Audio Subsystem about Microphone Mute switch state. * * @param on set <var>true</var> to mute the microphone; * <var>false</var> to turn mute off */ @UnsupportedAppUsage public void setMicrophoneMuteFromSwitch(boolean on) { final IAudioService service = getService(); try { service.setMicrophoneMuteFromSwitch(on); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } } /** * Checks whether the microphone mute is on or off. * * @return true if microphone is muted, false if it's not */ public boolean isMicrophoneMute() { return AudioSystem.isMicrophoneMuted(); final IAudioService service = getService(); try { return service.isMicrophoneMuted(); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } } /** Loading media/java/android/media/IAudioService.aidl +4 −0 Original line number Diff line number Diff line Loading @@ -106,8 +106,12 @@ interface IAudioService { List<AudioProductStrategy> getAudioProductStrategies(); boolean isMicrophoneMuted(); void setMicrophoneMute(boolean on, String callingPackage, int userId); oneway void setMicrophoneMuteFromSwitch(boolean on); void setRingerModeExternal(int ringerMode, String caller); void setRingerModeInternal(int ringerMode, String caller); Loading services/core/java/com/android/server/audio/AudioService.java +42 −7 Original line number Diff line number Diff line Loading @@ -59,6 +59,7 @@ import android.hardware.hdmi.HdmiAudioSystemClient; import android.hardware.hdmi.HdmiControlManager; import android.hardware.hdmi.HdmiPlaybackClient; import android.hardware.hdmi.HdmiTvClient; import android.hardware.input.InputManager; import android.hardware.usb.UsbManager; import android.media.AudioAttributes; import android.media.AudioFocusInfo; Loading Loading @@ -545,6 +546,10 @@ public class AudioService extends IAudioService.Stub private String mEnabledSurroundFormats; private boolean mSurroundModeChanged; private boolean mMicMuteFromSwitch; private boolean mMicMuteFromApi; private boolean mMicMuteFromRestrictions; @GuardedBy("mSettingsLock") private int mAssistantUid; Loading Loading @@ -882,6 +887,8 @@ public class AudioService extends IAudioService.Stub mRoleObserver.register(); onIndicateSystemReady(); setMicMuteFromSwitchInput(); } RoleObserver mRoleObserver; Loading Loading @@ -1021,6 +1028,8 @@ public class AudioService extends IAudioService.Stub sendMsg(mAudioHandler, MSG_DISPATCH_AUDIO_SERVER_STATE, SENDMSG_QUEUE, 1, 0, null, 0); setMicMuteFromSwitchInput(); } private void onDispatchAudioServerStateChange(boolean state) { Loading Loading @@ -2837,20 +2846,45 @@ public class AudioService extends IAudioService.Stub != PackageManager.PERMISSION_GRANTED) { return; } setMicrophoneMuteNoCallerCheck(on, userId); mMicMuteFromApi = on; setMicrophoneMuteNoCallerCheck(userId); } /** @see AudioManager#setMicrophoneMuteFromSwitch(boolean) */ public void setMicrophoneMuteFromSwitch(boolean on) { int userId = Binder.getCallingUid(); if (userId != android.os.Process.SYSTEM_UID) { Log.e(TAG, "setMicrophoneMuteFromSwitch() called from non system user!"); return; } mMicMuteFromSwitch = on; setMicrophoneMuteNoCallerCheck(userId); } private void setMicMuteFromSwitchInput() { InputManager im = mContext.getSystemService(InputManager.class); final int isMicMuted = im.isMicMuted(); if (isMicMuted != InputManager.SWITCH_STATE_UNKNOWN) { setMicrophoneMuteFromSwitch(im.isMicMuted() != InputManager.SWITCH_STATE_OFF); } } public boolean isMicrophoneMuted() { return mMicMuteFromSwitch || mMicMuteFromRestrictions || mMicMuteFromApi; } private void setMicrophoneMuteNoCallerCheck(boolean on, int userId) { private void setMicrophoneMuteNoCallerCheck(int userId) { final boolean muted = isMicrophoneMuted(); if (DEBUG_VOL) { Log.d(TAG, String.format("Mic mute %s, user=%d", on, userId)); Log.d(TAG, String.format("Mic mute %d, user=%d", muted, userId)); } // only mute for the current user if (getCurrentUserId() == userId) { if (getCurrentUserId() == userId || userId == android.os.Process.SYSTEM_UID) { final boolean currentMute = AudioSystem.isMicrophoneMuted(); final long identity = Binder.clearCallingIdentity(); AudioSystem.muteMicrophone(on); AudioSystem.muteMicrophone(muted); Binder.restoreCallingIdentity(identity); if (on != currentMute) { if (muted != currentMute) { mContext.sendBroadcastAsUser( new Intent(AudioManager.ACTION_MICROPHONE_MUTE_CHANGED) .setFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY), UserHandle.ALL); Loading Loading @@ -5390,7 +5424,8 @@ public class AudioService extends IAudioService.Stub final boolean isRestricted = newRestrictions.getBoolean(UserManager.DISALLOW_UNMUTE_MICROPHONE); if (wasRestricted != isRestricted) { setMicrophoneMuteNoCallerCheck(isRestricted, userId); mMicMuteFromRestrictions = isRestricted; setMicrophoneMuteNoCallerCheck(userId); } } Loading Loading
core/java/android/hardware/input/IInputManager.aidl +3 −0 Original line number Diff line number Diff line Loading @@ -76,6 +76,9 @@ interface IInputManager { // Registers a tablet mode change listener void registerTabletModeChangedListener(ITabletModeChangedListener listener); // Queries whether the device's microphone is muted by switch int isMicMuted(); // Input device vibrator control. void vibrate(int deviceId, in long[] pattern, int repeat, IBinder token); void cancelVibrate(int deviceId, IBinder token); Loading
core/java/android/hardware/input/InputManager.java +16 −0 Original line number Diff line number Diff line Loading @@ -519,6 +519,22 @@ public final class InputManager { return -1; } /** * Queries whether the device's microphone is muted * * @return The mic mute switch state which is one of {@link #SWITCH_STATE_UNKNOWN}, * {@link #SWITCH_STATE_OFF} or {@link #SWITCH_STATE_ON}. * @hide */ @SwitchState public int isMicMuted() { try { return mIm.isMicMuted(); } catch (RemoteException ex) { throw ex.rethrowFromSystemServer(); } } /** * Gets information about all supported keyboard layouts. * <p> Loading
media/java/android/media/AudioManager.java +26 −1 Original line number Diff line number Diff line Loading @@ -1856,13 +1856,38 @@ public class AudioManager { } } /** * @hide * Sets the microphone from switch mute on or off. * <p> * This method should only be used by InputManager to notify * Audio Subsystem about Microphone Mute switch state. * * @param on set <var>true</var> to mute the microphone; * <var>false</var> to turn mute off */ @UnsupportedAppUsage public void setMicrophoneMuteFromSwitch(boolean on) { final IAudioService service = getService(); try { service.setMicrophoneMuteFromSwitch(on); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } } /** * Checks whether the microphone mute is on or off. * * @return true if microphone is muted, false if it's not */ public boolean isMicrophoneMute() { return AudioSystem.isMicrophoneMuted(); final IAudioService service = getService(); try { return service.isMicrophoneMuted(); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } } /** Loading
media/java/android/media/IAudioService.aidl +4 −0 Original line number Diff line number Diff line Loading @@ -106,8 +106,12 @@ interface IAudioService { List<AudioProductStrategy> getAudioProductStrategies(); boolean isMicrophoneMuted(); void setMicrophoneMute(boolean on, String callingPackage, int userId); oneway void setMicrophoneMuteFromSwitch(boolean on); void setRingerModeExternal(int ringerMode, String caller); void setRingerModeInternal(int ringerMode, String caller); Loading
services/core/java/com/android/server/audio/AudioService.java +42 −7 Original line number Diff line number Diff line Loading @@ -59,6 +59,7 @@ import android.hardware.hdmi.HdmiAudioSystemClient; import android.hardware.hdmi.HdmiControlManager; import android.hardware.hdmi.HdmiPlaybackClient; import android.hardware.hdmi.HdmiTvClient; import android.hardware.input.InputManager; import android.hardware.usb.UsbManager; import android.media.AudioAttributes; import android.media.AudioFocusInfo; Loading Loading @@ -545,6 +546,10 @@ public class AudioService extends IAudioService.Stub private String mEnabledSurroundFormats; private boolean mSurroundModeChanged; private boolean mMicMuteFromSwitch; private boolean mMicMuteFromApi; private boolean mMicMuteFromRestrictions; @GuardedBy("mSettingsLock") private int mAssistantUid; Loading Loading @@ -882,6 +887,8 @@ public class AudioService extends IAudioService.Stub mRoleObserver.register(); onIndicateSystemReady(); setMicMuteFromSwitchInput(); } RoleObserver mRoleObserver; Loading Loading @@ -1021,6 +1028,8 @@ public class AudioService extends IAudioService.Stub sendMsg(mAudioHandler, MSG_DISPATCH_AUDIO_SERVER_STATE, SENDMSG_QUEUE, 1, 0, null, 0); setMicMuteFromSwitchInput(); } private void onDispatchAudioServerStateChange(boolean state) { Loading Loading @@ -2837,20 +2846,45 @@ public class AudioService extends IAudioService.Stub != PackageManager.PERMISSION_GRANTED) { return; } setMicrophoneMuteNoCallerCheck(on, userId); mMicMuteFromApi = on; setMicrophoneMuteNoCallerCheck(userId); } /** @see AudioManager#setMicrophoneMuteFromSwitch(boolean) */ public void setMicrophoneMuteFromSwitch(boolean on) { int userId = Binder.getCallingUid(); if (userId != android.os.Process.SYSTEM_UID) { Log.e(TAG, "setMicrophoneMuteFromSwitch() called from non system user!"); return; } mMicMuteFromSwitch = on; setMicrophoneMuteNoCallerCheck(userId); } private void setMicMuteFromSwitchInput() { InputManager im = mContext.getSystemService(InputManager.class); final int isMicMuted = im.isMicMuted(); if (isMicMuted != InputManager.SWITCH_STATE_UNKNOWN) { setMicrophoneMuteFromSwitch(im.isMicMuted() != InputManager.SWITCH_STATE_OFF); } } public boolean isMicrophoneMuted() { return mMicMuteFromSwitch || mMicMuteFromRestrictions || mMicMuteFromApi; } private void setMicrophoneMuteNoCallerCheck(boolean on, int userId) { private void setMicrophoneMuteNoCallerCheck(int userId) { final boolean muted = isMicrophoneMuted(); if (DEBUG_VOL) { Log.d(TAG, String.format("Mic mute %s, user=%d", on, userId)); Log.d(TAG, String.format("Mic mute %d, user=%d", muted, userId)); } // only mute for the current user if (getCurrentUserId() == userId) { if (getCurrentUserId() == userId || userId == android.os.Process.SYSTEM_UID) { final boolean currentMute = AudioSystem.isMicrophoneMuted(); final long identity = Binder.clearCallingIdentity(); AudioSystem.muteMicrophone(on); AudioSystem.muteMicrophone(muted); Binder.restoreCallingIdentity(identity); if (on != currentMute) { if (muted != currentMute) { mContext.sendBroadcastAsUser( new Intent(AudioManager.ACTION_MICROPHONE_MUTE_CHANGED) .setFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY), UserHandle.ALL); Loading Loading @@ -5390,7 +5424,8 @@ public class AudioService extends IAudioService.Stub final boolean isRestricted = newRestrictions.getBoolean(UserManager.DISALLOW_UNMUTE_MICROPHONE); if (wasRestricted != isRestricted) { setMicrophoneMuteNoCallerCheck(isRestricted, userId); mMicMuteFromRestrictions = isRestricted; setMicrophoneMuteNoCallerCheck(userId); } } Loading