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

Commit ab2d9315 authored by Jean-Michel Trivi's avatar Jean-Michel Trivi
Browse files

Permission enforcement for A11y volume changes

Make modifying the STREAM_ACCESSIBILITY volume conditional
  to have the BIND_ACCESSIBILITY_SERVICE permission.
Add BIND_ACCESSIBILITY_SERVICE permission to sysUI.

Test: cts-tradefed run cts -m CtsMediaTestCases -t android.media.cts.AudioManagerTest#testAccessibilityVolume
Bug: 34379420
Bug: 30448020
Change-Id: I9f26affccd953bd8473d06822857edf92fef4ba8
parent 10dd6979
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -180,6 +180,9 @@
    <!-- accessibility -->
    <uses-permission android:name="android.permission.MODIFY_ACCESSIBILITY_DATA" />

    <!-- to control accessibility volume -->
    <uses-permission android:name="android.permission.BIND_ACCESSIBILITY_SERVICE" />

    <application
        android:name=".SystemUIApplication"
        android:persistent="true"
+14 −0
Original line number Diff line number Diff line
@@ -1241,6 +1241,13 @@ public class AudioService extends IAudioService.Stub
    /** @see AudioManager#adjustStreamVolume(int, int, int) */
    public void adjustStreamVolume(int streamType, int direction, int flags,
            String callingPackage) {
        if ( streamType == AudioManager.STREAM_ACCESSIBILITY
                && (PackageManager.PERMISSION_GRANTED != mContext.checkCallingOrSelfPermission(
                        android.Manifest.permission.BIND_ACCESSIBILITY_SERVICE))) {
            Log.w(TAG, "Trying to call adjustStreamVolume() for a11y without"
                    + "BIND_ACCESSIBILITY_SERVICE / callingPackage=" + callingPackage);
            return;
        }
        adjustStreamVolume(streamType, direction, flags, callingPackage, callingPackage,
                Binder.getCallingUid());
    }
@@ -1552,6 +1559,13 @@ public class AudioService extends IAudioService.Stub

    /** @see AudioManager#setStreamVolume(int, int, int) */
    public void setStreamVolume(int streamType, int index, int flags, String callingPackage) {
        if ( streamType == AudioManager.STREAM_ACCESSIBILITY
                && (PackageManager.PERMISSION_GRANTED != mContext.checkCallingOrSelfPermission(
                        android.Manifest.permission.BIND_ACCESSIBILITY_SERVICE))) {
            Log.w(TAG, "Trying to call setStreamVolume() for a11y without"
                    + " BIND_ACCESSIBILITY_SERVICE  callingPackage=" + callingPackage);
            return;
        }
        setStreamVolume(streamType, index, flags, callingPackage, callingPackage,
                Binder.getCallingUid());
    }