Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3aadf0a4 authored by Dmitry Shmidt's avatar Dmitry Shmidt Committed by android-build-merger
Browse files

Merge changes If9068025,I728e5bf9,I9d41169d am: 3b6a00ec

am: 225b9d90

Change-Id: Ia3cc9fbaf08da8dd6823621366d307c40ba209d5
parents 3820d196 225b9d90
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -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);
+16 −0
Original line number Diff line number Diff line
@@ -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>
+26 −1
Original line number Diff line number Diff line
@@ -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();
        }
    }

    /**
+4 −0
Original line number Diff line number Diff line
@@ -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);
+42 −7
Original line number Diff line number Diff line
@@ -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;
@@ -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;

@@ -882,6 +887,8 @@ public class AudioService extends IAudioService.Stub
        mRoleObserver.register();

        onIndicateSystemReady();

        setMicMuteFromSwitchInput();
    }

    RoleObserver mRoleObserver;
@@ -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) {
@@ -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);
@@ -5378,7 +5412,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