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

Commit 4d7cc1a3 authored by Nadav Bar's avatar Nadav Bar Committed by Android (Google) Code Review
Browse files

Merge "Enable phone apps to mute the VOICE_CALL stream"

parents a17274fb 6b7751d2
Loading
Loading
Loading
Loading
+2 −1
Original line number Original line Diff line number Diff line
@@ -914,7 +914,8 @@ public class AudioSystem
            (1 << STREAM_MUSIC) |
            (1 << STREAM_MUSIC) |
            (1 << STREAM_RING) |
            (1 << STREAM_RING) |
            (1 << STREAM_NOTIFICATION) |
            (1 << STREAM_NOTIFICATION) |
            (1 << STREAM_SYSTEM);
            (1 << STREAM_SYSTEM) |
            (1 << STREAM_VOICE_CALL);


    /**
    /**
     * Event posted by AudioTrack and AudioRecord JNI (JNIDeviceCallback) when routing changes.
     * Event posted by AudioTrack and AudioRecord JNI (JNIDeviceCallback) when routing changes.
+24 −1
Original line number Original line Diff line number Diff line
@@ -1047,9 +1047,11 @@ public class AudioService extends IAudioService.Stub


    private void checkMuteAffectedStreams() {
    private void checkMuteAffectedStreams() {
        // any stream with a min level > 0 is not muteable by definition
        // any stream with a min level > 0 is not muteable by definition
        // STREAM_VOICE_CALL can be muted by applications that has the the MODIFY_PHONE_STATE permission.
        for (int i = 0; i < mStreamStates.length; i++) {
        for (int i = 0; i < mStreamStates.length; i++) {
            final VolumeStreamState vss = mStreamStates[i];
            final VolumeStreamState vss = mStreamStates[i];
            if (vss.mIndexMin > 0) {
            if (vss.mIndexMin > 0 &&
                vss.mStreamType != AudioSystem.STREAM_VOICE_CALL) {
                mMuteAffectedStreams &= ~(1 << vss.mStreamType);
                mMuteAffectedStreams &= ~(1 << vss.mStreamType);
            }
            }
        }
        }
@@ -1412,6 +1414,18 @@ public class AudioService extends IAudioService.Stub
            return;
            return;
        }
        }


        // If adjust is mute and the stream is STREAM_VOICE_CALL, make sure
        // that the calling app have the MODIFY_PHONE_STATE permission.
        if (isMuteAdjust &&
            streamType == AudioSystem.STREAM_VOICE_CALL &&
            mContext.checkCallingOrSelfPermission(
                android.Manifest.permission.MODIFY_PHONE_STATE)
                    != PackageManager.PERMISSION_GRANTED) {
            Log.w(TAG, "MODIFY_PHONE_STATE Permission Denial: adjustStreamVolume from pid="
                    + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid());
            return;
        }

        // use stream type alias here so that streams with same alias have the same behavior,
        // use stream type alias here so that streams with same alias have the same behavior,
        // including with regard to silent mode control (e.g the use of STREAM_RING below and in
        // including with regard to silent mode control (e.g the use of STREAM_RING below and in
        // checkForRingerModeChange() in place of STREAM_RING or STREAM_NOTIFICATION)
        // checkForRingerModeChange() in place of STREAM_RING or STREAM_NOTIFICATION)
@@ -1712,6 +1726,15 @@ public class AudioService extends IAudioService.Stub
                    + " CHANGE_ACCESSIBILITY_VOLUME  callingPackage=" + callingPackage);
                    + " CHANGE_ACCESSIBILITY_VOLUME  callingPackage=" + callingPackage);
            return;
            return;
        }
        }
        if ((streamType == AudioManager.STREAM_VOICE_CALL) &&
                (index == 0) &&
                (mContext.checkCallingOrSelfPermission(
                android.Manifest.permission.MODIFY_PHONE_STATE)
                    != PackageManager.PERMISSION_GRANTED)) {
            Log.w(TAG, "Trying to call setStreamVolume() for STREAM_VOICE_CALL and index 0 without"
                    + " MODIFY_PHONE_STATE  callingPackage=" + callingPackage);
            return;
        }
        mVolumeLogger.log(new VolumeEvent(VolumeEvent.VOL_SET_STREAM_VOL, streamType,
        mVolumeLogger.log(new VolumeEvent(VolumeEvent.VOL_SET_STREAM_VOL, streamType,
                index/*val1*/, flags/*val2*/, callingPackage));
                index/*val1*/, flags/*val2*/, callingPackage));
        setStreamVolume(streamType, index, flags, callingPackage, callingPackage,
        setStreamVolume(streamType, index, flags, callingPackage, callingPackage,