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

Commit 98afe389 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Revert "Consolidating MODIFY_AUDIO_SETTINGS permission checks"" into rvc-dev am: 601402ed

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/11720201

Change-Id: I8d39d708b75c5f035922af11fcb8d0e3705ee501
parents a8d5ef07 601402ed
Loading
Loading
Loading
Loading
+28 −18
Original line number Original line Diff line number Diff line
@@ -1908,8 +1908,11 @@ public class AudioService extends IAudioService.Stub
    /** @see AudioManager#adjustVolume(int, int) */
    /** @see AudioManager#adjustVolume(int, int) */
    public void adjustSuggestedStreamVolume(int direction, int suggestedStreamType, int flags,
    public void adjustSuggestedStreamVolume(int direction, int suggestedStreamType, int flags,
            String callingPackage, String caller) {
            String callingPackage, String caller) {
        boolean hasModifyAudioSettings =
                mContext.checkCallingPermission(Manifest.permission.MODIFY_AUDIO_SETTINGS)
                == PackageManager.PERMISSION_GRANTED;
        adjustSuggestedStreamVolume(direction, suggestedStreamType, flags, callingPackage,
        adjustSuggestedStreamVolume(direction, suggestedStreamType, flags, callingPackage,
                caller, Binder.getCallingUid(), hasModifyAudioSettings(), VOL_ADJUST_NORMAL);
                caller, Binder.getCallingUid(), hasModifyAudioSettings, VOL_ADJUST_NORMAL);
    }
    }


    private void adjustSuggestedStreamVolume(int direction, int suggestedStreamType, int flags,
    private void adjustSuggestedStreamVolume(int direction, int suggestedStreamType, int flags,
@@ -2014,10 +2017,13 @@ public class AudioService extends IAudioService.Stub
                    + "CHANGE_ACCESSIBILITY_VOLUME / callingPackage=" + callingPackage);
                    + "CHANGE_ACCESSIBILITY_VOLUME / callingPackage=" + callingPackage);
            return;
            return;
        }
        }
        final boolean hasModifyAudioSettings =
                mContext.checkCallingPermission(Manifest.permission.MODIFY_AUDIO_SETTINGS)
                        == PackageManager.PERMISSION_GRANTED;
        sVolumeLogger.log(new VolumeEvent(VolumeEvent.VOL_ADJUST_STREAM_VOL, streamType,
        sVolumeLogger.log(new VolumeEvent(VolumeEvent.VOL_ADJUST_STREAM_VOL, streamType,
                direction/*val1*/, flags/*val2*/, callingPackage));
                direction/*val1*/, flags/*val2*/, callingPackage));
        adjustStreamVolume(streamType, direction, flags, callingPackage, callingPackage,
        adjustStreamVolume(streamType, direction, flags, callingPackage, callingPackage,
                Binder.getCallingUid(), hasModifyAudioSettings(), VOL_ADJUST_NORMAL);
                Binder.getCallingUid(), hasModifyAudioSettings, VOL_ADJUST_NORMAL);
    }
    }


    protected void adjustStreamVolume(int streamType, int direction, int flags,
    protected void adjustStreamVolume(int streamType, int direction, int flags,
@@ -2528,10 +2534,13 @@ public class AudioService extends IAudioService.Stub
                    + " MODIFY_AUDIO_ROUTING  callingPackage=" + callingPackage);
                    + " MODIFY_AUDIO_ROUTING  callingPackage=" + callingPackage);
            return;
            return;
        }
        }
        final boolean hasModifyAudioSettings =
                mContext.checkCallingOrSelfPermission(Manifest.permission.MODIFY_AUDIO_SETTINGS)
                        == PackageManager.PERMISSION_GRANTED;
        sVolumeLogger.log(new VolumeEvent(VolumeEvent.VOL_SET_STREAM_VOL, streamType,
        sVolumeLogger.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,
                Binder.getCallingUid(), hasModifyAudioSettings());
                Binder.getCallingUid(), hasModifyAudioSettings);
    }
    }


    private boolean canChangeAccessibilityVolume() {
    private boolean canChangeAccessibilityVolume() {
@@ -3197,7 +3206,8 @@ public class AudioService extends IAudioService.Stub
        ensureValidStreamType(streamType);
        ensureValidStreamType(streamType);
        final boolean isPrivileged =
        final boolean isPrivileged =
                Binder.getCallingUid() == Process.SYSTEM_UID
                Binder.getCallingUid() == Process.SYSTEM_UID
                 || (hasModifyAudioSettings())
                 || (mContext.checkCallingPermission(Manifest.permission.MODIFY_AUDIO_SETTINGS)
                        == PackageManager.PERMISSION_GRANTED)
                 || (mContext.checkCallingPermission(Manifest.permission.MODIFY_AUDIO_ROUTING)
                 || (mContext.checkCallingPermission(Manifest.permission.MODIFY_AUDIO_ROUTING)
                        == PackageManager.PERMISSION_GRANTED);
                        == PackageManager.PERMISSION_GRANTED);
        return (mStreamStates[streamType].getMinIndex(isPrivileged) + 5) / 10;
        return (mStreamStates[streamType].getMinIndex(isPrivileged) + 5) / 10;
@@ -4755,18 +4765,9 @@ public class AudioService extends IAudioService.Stub
        handler.sendMessageAtTime(handler.obtainMessage(msg, arg1, arg2, obj), time);
        handler.sendMessageAtTime(handler.obtainMessage(msg, arg1, arg2, obj), time);
    }
    }


    private boolean hasModifyAudioSettings() {
        return mContext.checkCallingPermission(Manifest.permission.MODIFY_AUDIO_SETTINGS)
                == PackageManager.PERMISSION_GRANTED;
    }

    private boolean hasModifyAudioSettings(int pid, int uid) {
        return mContext.checkPermission(Manifest.permission.MODIFY_AUDIO_SETTINGS, pid, uid)
                == PackageManager.PERMISSION_GRANTED;
    }

    boolean checkAudioSettingsPermission(String method) {
    boolean checkAudioSettingsPermission(String method) {
        if (hasModifyAudioSettings()) {
        if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_AUDIO_SETTINGS)
                == PackageManager.PERMISSION_GRANTED) {
            return true;
            return true;
        }
        }
        String msg = "Audio Settings Permission Denial: " + method + " from pid="
        String msg = "Audio Settings Permission Denial: " + method + " from pid="
@@ -7688,10 +7689,13 @@ public class AudioService extends IAudioService.Stub
        @Override
        @Override
        public void adjustSuggestedStreamVolumeForUid(int streamType, int direction, int flags,
        public void adjustSuggestedStreamVolumeForUid(int streamType, int direction, int flags,
                String callingPackage, int uid, int pid) {
                String callingPackage, int uid, int pid) {
            final boolean hasModifyAudioSettings =
                    mContext.checkPermission(Manifest.permission.MODIFY_AUDIO_SETTINGS, pid, uid)
                    == PackageManager.PERMISSION_GRANTED;
            // direction and stream type swap here because the public
            // direction and stream type swap here because the public
            // adjustSuggested has a different order than the other methods.
            // adjustSuggested has a different order than the other methods.
            adjustSuggestedStreamVolume(direction, streamType, flags, callingPackage,
            adjustSuggestedStreamVolume(direction, streamType, flags, callingPackage,
                    callingPackage, uid, hasModifyAudioSettings(pid, uid), VOL_ADJUST_NORMAL);
                    callingPackage, uid, hasModifyAudioSettings, VOL_ADJUST_NORMAL);
        }
        }


        @Override
        @Override
@@ -7702,15 +7706,21 @@ public class AudioService extends IAudioService.Stub
                        direction/*val1*/, flags/*val2*/, new StringBuilder(callingPackage)
                        direction/*val1*/, flags/*val2*/, new StringBuilder(callingPackage)
                        .append(" uid:").append(uid).toString()));
                        .append(" uid:").append(uid).toString()));
            }
            }
            final boolean hasModifyAudioSettings =
                    mContext.checkPermission(Manifest.permission.MODIFY_AUDIO_SETTINGS, pid, uid)
                            == PackageManager.PERMISSION_GRANTED;
            adjustStreamVolume(streamType, direction, flags, callingPackage,
            adjustStreamVolume(streamType, direction, flags, callingPackage,
                    callingPackage, uid, hasModifyAudioSettings(pid, uid), VOL_ADJUST_NORMAL);
                    callingPackage, uid, hasModifyAudioSettings, VOL_ADJUST_NORMAL);
        }
        }


        @Override
        @Override
        public void setStreamVolumeForUid(int streamType, int direction, int flags,
        public void setStreamVolumeForUid(int streamType, int direction, int flags,
                String callingPackage, int uid, int pid) {
                String callingPackage, int uid, int pid) {
            final boolean hasModifyAudioSettings =
                    mContext.checkPermission(Manifest.permission.MODIFY_AUDIO_SETTINGS, pid, uid)
                            == PackageManager.PERMISSION_GRANTED;
            setStreamVolume(streamType, direction, flags, callingPackage, callingPackage, uid,
            setStreamVolume(streamType, direction, flags, callingPackage, callingPackage, uid,
                    hasModifyAudioSettings(pid, uid));
                    hasModifyAudioSettings);
        }
        }


        @Override
        @Override