From 3f0945a608197fa8919ebe909f6388d9d59e8c29 Mon Sep 17 00:00:00 2001 From: Jean-Michel Trivi Date: Fri, 11 Nov 2016 10:05:18 -0800 Subject: [PATCH] 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 --- api/current.txt | 1 + api/system-current.txt | 1 + api/test-current.txt | 1 + core/java/android/app/AppOpsManager.java | 12 +++++++++++- media/java/android/media/AudioAttributes.java | 18 +++++++++++++----- media/java/android/media/AudioManager.java | 3 +++ media/java/android/media/AudioSystem.java | 10 +++++++--- .../com/android/server/audio/AudioService.java | 16 +++++++++++----- 8 files changed, 48 insertions(+), 14 deletions(-) diff --git a/api/current.txt b/api/current.txt index 3bf4954638154..ebd11a9a8f738 100644 --- a/api/current.txt +++ b/api/current.txt @@ -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 diff --git a/api/system-current.txt b/api/system-current.txt index 26a2f61a26dc9..b3b68727cfc49 100644 --- a/api/system-current.txt +++ b/api/system-current.txt @@ -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 diff --git a/api/test-current.txt b/api/test-current.txt index 29990433a281a..1281de524a3e2 100644 --- a/api/test-current.txt +++ b/api/test-current.txt @@ -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 diff --git a/core/java/android/app/AppOpsManager.java b/core/java/android/app/AppOpsManager.java index 191cc4944e26c..ba6bc159cdf29 100644 --- a/core/java/android/app/AppOpsManager.java +++ b/core/java/android/app/AppOpsManager.java @@ -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 }; /** diff --git a/media/java/android/media/AudioAttributes.java b/media/java/android/media/AudioAttributes.java index 89709ee6b95a1..5440f0fc214f3 100644 --- a/media/java/android/media/AudioAttributes.java +++ b/media/java/android/media/AudioAttributes.java @@ -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; diff --git a/media/java/android/media/AudioManager.java b/media/java/android/media/AudioManager.java index f24bf095eb104..435e6ba159e91 100644 --- a/media/java/android/media/AudioManager.java +++ b/media/java/android/media/AudioManager.java @@ -335,6 +335,9 @@ public class AudioManager { /** @hide Used to identify the volume of audio streams exclusively transmitted through the * speaker (TTS) of the device */ public static final int STREAM_TTS = AudioSystem.STREAM_TTS; + /** Used to identify the volume of audio streams for accessibility prompts */ + public static final int STREAM_ACCESSIBILITY = AudioSystem.STREAM_ACCESSIBILITY; + /** Number of audio streams */ /** * @deprecated Do not iterate on volume stream type values. diff --git a/media/java/android/media/AudioSystem.java b/media/java/android/media/AudioSystem.java index 384be5cb88d0a..28c7253f8c76f 100644 --- a/media/java/android/media/AudioSystem.java +++ b/media/java/android/media/AudioSystem.java @@ -63,13 +63,15 @@ public class AudioSystem /** Used to identify the volume of audio streams exclusively transmitted through the * speaker (TTS) of the device */ public static final int STREAM_TTS = 9; + /** Used to identify the volume of audio streams for accessibility prompts */ + public static final int STREAM_ACCESSIBILITY = 10; /** * @deprecated Use {@link #numStreamTypes() instead} */ public static final int NUM_STREAMS = 5; // Expose only the getter method publicly so we can change it in the future - private static final int NUM_STREAM_TYPES = 10; + private static final int NUM_STREAM_TYPES = 11; public static final int getNumStreamTypes() { return NUM_STREAM_TYPES; } public static final String[] STREAM_NAMES = new String[] { @@ -82,7 +84,8 @@ public class AudioSystem "STREAM_BLUETOOTH_SCO", "STREAM_SYSTEM_ENFORCED", "STREAM_DTMF", - "STREAM_TTS" + "STREAM_TTS", + "STREAM_ACCESSIBILITY" }; /* @@ -773,7 +776,8 @@ public class AudioSystem 7, // STREAM_BLUETOOTH_SCO 7, // STREAM_SYSTEM_ENFORCED 11, // STREAM_DTMF - 11 // STREAM_TTS + 11, // STREAM_TTS + 11, // STREAM_ACCESSIBILITY }; public static String streamToString(int stream) { diff --git a/services/core/java/com/android/server/audio/AudioService.java b/services/core/java/com/android/server/audio/AudioService.java index da016da9fa591..ac9545c06c104 100644 --- a/services/core/java/com/android/server/audio/AudioService.java +++ b/services/core/java/com/android/server/audio/AudioService.java @@ -272,7 +272,8 @@ public class AudioService extends IAudioService.Stub { 15, // STREAM_BLUETOOTH_SCO 7, // STREAM_SYSTEM_ENFORCED 15, // STREAM_DTMF - 15 // STREAM_TTS + 15, // STREAM_TTS + 15 // STREAM_ACCESSIBILITY }; /** Minimum volume index values for audio streams */ @@ -286,7 +287,8 @@ public class AudioService extends IAudioService.Stub { 0, // STREAM_BLUETOOTH_SCO 0, // STREAM_SYSTEM_ENFORCED 0, // STREAM_DTMF - 0 // STREAM_TTS + 0, // STREAM_TTS + 0 // STREAM_ACCESSIBILITY }; /* mStreamVolumeAlias[] indicates for each stream if it uses the volume settings @@ -308,7 +310,8 @@ public class AudioService extends IAudioService.Stub { AudioSystem.STREAM_BLUETOOTH_SCO, // STREAM_BLUETOOTH_SCO AudioSystem.STREAM_RING, // STREAM_SYSTEM_ENFORCED AudioSystem.STREAM_RING, // STREAM_DTMF - AudioSystem.STREAM_MUSIC // STREAM_TTS + AudioSystem.STREAM_MUSIC, // STREAM_TTS + AudioSystem.STREAM_MUSIC // STREAM_ACCESSIBILITY }; private final int[] STREAM_VOLUME_ALIAS_TELEVISION = new int[] { AudioSystem.STREAM_MUSIC, // STREAM_VOICE_CALL @@ -320,7 +323,8 @@ public class AudioService extends IAudioService.Stub { AudioSystem.STREAM_MUSIC, // STREAM_BLUETOOTH_SCO AudioSystem.STREAM_MUSIC, // STREAM_SYSTEM_ENFORCED AudioSystem.STREAM_MUSIC, // STREAM_DTMF - AudioSystem.STREAM_MUSIC // STREAM_TTS + AudioSystem.STREAM_MUSIC, // STREAM_TTS + AudioSystem.STREAM_MUSIC // STREAM_ACCESSIBILITY }; private final int[] STREAM_VOLUME_ALIAS_DEFAULT = new int[] { AudioSystem.STREAM_VOICE_CALL, // STREAM_VOICE_CALL @@ -332,7 +336,8 @@ public class AudioService extends IAudioService.Stub { AudioSystem.STREAM_BLUETOOTH_SCO, // STREAM_BLUETOOTH_SCO AudioSystem.STREAM_RING, // STREAM_SYSTEM_ENFORCED AudioSystem.STREAM_RING, // STREAM_DTMF - AudioSystem.STREAM_MUSIC // STREAM_TTS + AudioSystem.STREAM_MUSIC, // STREAM_TTS + AudioSystem.STREAM_MUSIC // STREAM_ACCESSIBILITY }; private int[] mStreamVolumeAlias; @@ -351,6 +356,7 @@ public class AudioService extends IAudioService.Stub { AppOpsManager.OP_AUDIO_MEDIA_VOLUME, // STREAM_SYSTEM_ENFORCED AppOpsManager.OP_AUDIO_MEDIA_VOLUME, // STREAM_DTMF AppOpsManager.OP_AUDIO_MEDIA_VOLUME, // STREAM_TTS + AppOpsManager.OP_AUDIO_ACCESSIBILITY_VOLUME, // STREAM_ACCESSIBILITY }; private final boolean mUseFixedVolume;