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

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

Define stream type for accessibility volume control

New stream type for accessibility volume.
Add related appOps.

Test: see added CTS tests in AudioManagerTest & Stub
Bug 30448020

Change-Id: I34f96713b22fedf75322b8ffe2b96a7c566f5009
parent 7fdf3818
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -19914,6 +19914,7 @@ package android.media {
    field public static final int SCO_AUDIO_STATE_CONNECTING = 2; // 0x2
    field public static final int SCO_AUDIO_STATE_DISCONNECTED = 0; // 0x0
    field public static final int SCO_AUDIO_STATE_ERROR = -1; // 0xffffffff
    field public static final int STREAM_ACCESSIBILITY = 10; // 0xa
    field public static final int STREAM_ALARM = 4; // 0x4
    field public static final int STREAM_DTMF = 8; // 0x8
    field public static final int STREAM_MUSIC = 3; // 0x3
+1 −0
Original line number Diff line number Diff line
@@ -21475,6 +21475,7 @@ package android.media {
    field public static final int SCO_AUDIO_STATE_CONNECTING = 2; // 0x2
    field public static final int SCO_AUDIO_STATE_DISCONNECTED = 0; // 0x0
    field public static final int SCO_AUDIO_STATE_ERROR = -1; // 0xffffffff
    field public static final int STREAM_ACCESSIBILITY = 10; // 0xa
    field public static final int STREAM_ALARM = 4; // 0x4
    field public static final int STREAM_DTMF = 8; // 0x8
    field public static final int STREAM_MUSIC = 3; // 0x3
+1 −0
Original line number Diff line number Diff line
@@ -19995,6 +19995,7 @@ package android.media {
    field public static final int SCO_AUDIO_STATE_CONNECTING = 2; // 0x2
    field public static final int SCO_AUDIO_STATE_DISCONNECTED = 0; // 0x0
    field public static final int SCO_AUDIO_STATE_ERROR = -1; // 0xffffffff
    field public static final int STREAM_ACCESSIBILITY = 10; // 0xa
    field public static final int STREAM_ALARM = 4; // 0x4
    field public static final int STREAM_DTMF = 8; // 0x8
    field public static final int STREAM_MUSIC = 3; // 0x3
+11 −1
Original line number Diff line number Diff line
@@ -240,7 +240,9 @@ public class AppOpsManager {
    /** @hide Control whether an application is allowed to run in the background. */
    public static final int OP_RUN_IN_BACKGROUND = 63;
    /** @hide */
    public static final int _NUM_OP = 64;
    public static final int OP_AUDIO_ACCESSIBILITY_VOLUME = 64;
    /** @hide */
    public static final int _NUM_OP = 65;

    /** Access to coarse location information. */
    public static final String OPSTR_COARSE_LOCATION = "android:coarse_location";
@@ -452,6 +454,7 @@ public class AppOpsManager {
            OP_TURN_SCREEN_ON,
            OP_GET_ACCOUNTS,
            OP_RUN_IN_BACKGROUND,
            OP_AUDIO_ACCESSIBILITY_VOLUME,
    };

    /**
@@ -523,6 +526,7 @@ public class AppOpsManager {
            null,
            OPSTR_GET_ACCOUNTS,
            null,
            null, // OP_AUDIO_ACCESSIBILITY_VOLUME
    };

    /**
@@ -594,6 +598,7 @@ public class AppOpsManager {
            "TURN_ON_SCREEN",
            "GET_ACCOUNTS",
            "RUN_IN_BACKGROUND",
            "AUDIO_ACCESSIBILITY_VOLUME",
    };

    /**
@@ -665,6 +670,7 @@ public class AppOpsManager {
            null, // no permission for turning the screen on
            Manifest.permission.GET_ACCOUNTS,
            null, // no permission for running in background
            null, // no permission for changing accessibility volume
    };

    /**
@@ -737,6 +743,7 @@ public class AppOpsManager {
            null, // TURN_ON_SCREEN
            null, // GET_ACCOUNTS
            null, // RUN_IN_BACKGROUND
            UserManager.DISALLOW_ADJUST_VOLUME, //AUDIO_ACCESSIBILITY_VOLUME
    };

    /**
@@ -808,6 +815,7 @@ public class AppOpsManager {
            false, // TURN_ON_SCREEN
            false, // GET_ACCOUNTS
            false, // RUN_IN_BACKGROUND
            false, // AUDIO_ACCESSIBILITY_VOLUME
    };

    /**
@@ -878,6 +886,7 @@ public class AppOpsManager {
            AppOpsManager.MODE_ALLOWED,  // OP_TURN_ON_SCREEN
            AppOpsManager.MODE_ALLOWED,
            AppOpsManager.MODE_ALLOWED,  // OP_RUN_IN_BACKGROUND
            AppOpsManager.MODE_ALLOWED,  // OP_AUDIO_ACCESSIBILITY_VOLUME
    };

    /**
@@ -952,6 +961,7 @@ public class AppOpsManager {
            false,
            false,
            false,
            false, // OP_AUDIO_ACCESSIBILITY_VOLUME
    };

    /**
+13 −5
Original line number Diff line number Diff line
@@ -584,6 +584,10 @@ public final class AudioAttributes implements Parcelable {
         * @return the same Builder instance.
         */
        public Builder setLegacyStreamType(int streamType) {
            if (streamType == AudioManager.STREAM_ACCESSIBILITY) {
                throw new IllegalArgumentException("STREAM_ACCESSIBILITY is not a legacy stream "
                        + "type that was used for audio playback");
            }
            return setInternalLegacyStreamType(streamType);
        }

@@ -624,12 +628,15 @@ public final class AudioAttributes implements Parcelable {
                    mContentType = CONTENT_TYPE_SONIFICATION;
                    break;
                case AudioSystem.STREAM_TTS:
                    mContentType = CONTENT_TYPE_SONIFICATION;
                    break;
                case AudioSystem.STREAM_ACCESSIBILITY:
                    mContentType = CONTENT_TYPE_SPEECH;
                    break;
                default:
                    Log.e(TAG, "Invalid stream type " + streamType + " for AudioAttributes");
            }
            mUsage = usageForLegacyStreamType(streamType);
            mUsage = usageForStreamType(streamType);
            return this;
        }

@@ -842,8 +849,7 @@ public final class AudioAttributes implements Parcelable {
        }
    }

    /** @hide */
    public static int usageForLegacyStreamType(int streamType) {
    private static int usageForStreamType(int streamType) {
        switch(streamType) {
            case AudioSystem.STREAM_VOICE_CALL:
                return USAGE_VOICE_COMMUNICATION;
@@ -862,8 +868,9 @@ public final class AudioAttributes implements Parcelable {
                return USAGE_VOICE_COMMUNICATION;
            case AudioSystem.STREAM_DTMF:
                return USAGE_VOICE_COMMUNICATION_SIGNALLING;
            case AudioSystem.STREAM_TTS:
            case AudioSystem.STREAM_ACCESSIBILITY:
                return USAGE_ASSISTANCE_ACCESSIBILITY;
            case AudioSystem.STREAM_TTS:
            default:
                return USAGE_UNKNOWN;
        }
@@ -915,7 +922,6 @@ public final class AudioAttributes implements Parcelable {
        switch (aa.getUsage()) {
            case USAGE_MEDIA:
            case USAGE_GAME:
            case USAGE_ASSISTANCE_ACCESSIBILITY:
            case USAGE_ASSISTANCE_NAVIGATION_GUIDANCE:
                return AudioSystem.STREAM_MUSIC;
            case USAGE_ASSISTANCE_SONIFICATION:
@@ -935,6 +941,8 @@ public final class AudioAttributes implements Parcelable {
            case USAGE_NOTIFICATION_COMMUNICATION_DELAYED:
            case USAGE_NOTIFICATION_EVENT:
                return AudioSystem.STREAM_NOTIFICATION;
            case USAGE_ASSISTANCE_ACCESSIBILITY:
                return AudioSystem.STREAM_ACCESSIBILITY;
            case USAGE_UNKNOWN:
                return fromGetVolumeControlStream ?
                        AudioManager.USE_DEFAULT_STREAM_TYPE : AudioSystem.STREAM_MUSIC;
Loading