Merge "AudioAttributes: introduce new flags to bypass audio restrictions."
This commit is contained in:
committed by
Android (Google) Code Review
commit
0a7269bbaf
@@ -15118,6 +15118,8 @@ package android.media {
|
||||
field public static final android.os.Parcelable.Creator<android.media.AudioAttributes> CREATOR;
|
||||
field public static final int FLAG_AUDIBILITY_ENFORCED = 1; // 0x1
|
||||
field public static final int FLAG_BEACON = 8; // 0x8
|
||||
field public static final int FLAG_BYPASS_INTERRUPTION_POLICY = 64; // 0x40
|
||||
field public static final int FLAG_BYPASS_MUTE = 128; // 0x80
|
||||
field public static final int FLAG_HW_AV_SYNC = 16; // 0x10
|
||||
field public static final int FLAG_HW_HOTWORD = 32; // 0x20
|
||||
field public static final int USAGE_ALARM = 4; // 0x4
|
||||
|
||||
@@ -21,6 +21,7 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.database.ContentObserver;
|
||||
import android.media.AudioAttributes;
|
||||
import android.media.AudioManager;
|
||||
import android.media.Ringtone;
|
||||
import android.media.RingtoneManager;
|
||||
@@ -174,6 +175,11 @@ public class SeekBarVolumizer implements OnSeekBarChangeListener, Handler.Callba
|
||||
}
|
||||
if (mRingtone != null) {
|
||||
try {
|
||||
mRingtone.setAudioAttributes(new AudioAttributes.Builder(mRingtone
|
||||
.getAudioAttributes())
|
||||
.setFlags(AudioAttributes.FLAG_BYPASS_INTERRUPTION_POLICY |
|
||||
AudioAttributes.FLAG_BYPASS_MUTE)
|
||||
.build());
|
||||
mRingtone.play();
|
||||
} catch (Throwable e) {
|
||||
Log.w(TAG, "Error playing ringtone, stream " + mStreamType, e);
|
||||
|
||||
@@ -209,8 +209,23 @@ public final class AudioAttributes implements Parcelable {
|
||||
@SystemApi
|
||||
public final static int FLAG_HW_HOTWORD = 0x1 << 5;
|
||||
|
||||
/**
|
||||
* @hide
|
||||
* Flag requesting audible playback even under limited interruptions.
|
||||
*/
|
||||
@SystemApi
|
||||
public final static int FLAG_BYPASS_INTERRUPTION_POLICY = 0x1 << 6;
|
||||
|
||||
/**
|
||||
* @hide
|
||||
* Flag requesting audible playback even when the underlying stream is muted.
|
||||
*/
|
||||
@SystemApi
|
||||
public final static int FLAG_BYPASS_MUTE = 0x1 << 7;
|
||||
|
||||
private final static int FLAG_ALL = FLAG_AUDIBILITY_ENFORCED | FLAG_SECURE | FLAG_SCO |
|
||||
FLAG_BEACON | FLAG_HW_AV_SYNC | FLAG_HW_HOTWORD;
|
||||
FLAG_BEACON | FLAG_HW_AV_SYNC | FLAG_HW_HOTWORD | FLAG_BYPASS_INTERRUPTION_POLICY |
|
||||
FLAG_BYPASS_MUTE;
|
||||
private final static int FLAG_ALL_PUBLIC = FLAG_AUDIBILITY_ENFORCED | FLAG_HW_AV_SYNC;
|
||||
|
||||
private int mUsage = USAGE_UNKNOWN;
|
||||
|
||||
@@ -1178,6 +1178,9 @@ public class AudioTrack
|
||||
}
|
||||
|
||||
private boolean isRestricted() {
|
||||
if ((mAttributes.getFlags() & AudioAttributes.FLAG_BYPASS_INTERRUPTION_POLICY) != 0) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
final int usage = AudioAttributes.usageForLegacyStreamType(mStreamType);
|
||||
final int mode = mAppOps.checkAudioOperation(AppOpsManager.OP_PLAY_AUDIO, usage,
|
||||
|
||||
@@ -604,6 +604,7 @@ public class MediaPlayer implements SubtitleController.Listener
|
||||
private final IAppOpsService mAppOps;
|
||||
private int mStreamType = AudioManager.USE_DEFAULT_STREAM_TYPE;
|
||||
private int mUsage = -1;
|
||||
private boolean mBypassInterruptionPolicy;
|
||||
|
||||
/**
|
||||
* Default constructor. Consider using one of the create() methods for
|
||||
@@ -1169,6 +1170,9 @@ public class MediaPlayer implements SubtitleController.Listener
|
||||
private native void _start() throws IllegalStateException;
|
||||
|
||||
private boolean isRestricted() {
|
||||
if (mBypassInterruptionPolicy) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
final int usage = mUsage != -1 ? mUsage
|
||||
: AudioAttributes.usageForLegacyStreamType(getAudioStreamType());
|
||||
@@ -1560,6 +1564,8 @@ public class MediaPlayer implements SubtitleController.Listener
|
||||
throw new IllegalArgumentException(msg);
|
||||
}
|
||||
mUsage = attributes.getUsage();
|
||||
mBypassInterruptionPolicy = (attributes.getFlags()
|
||||
& AudioAttributes.FLAG_BYPASS_INTERRUPTION_POLICY) != 0;
|
||||
Parcel pattributes = Parcel.obtain();
|
||||
attributes.writeToParcel(pattributes, AudioAttributes.FLATTEN_TAGS);
|
||||
setParameter(KEY_PARAMETER_AUDIO_ATTRIBUTES, pattributes);
|
||||
|
||||
@@ -608,6 +608,9 @@ public class SoundPool {
|
||||
int priority, int loop, float rate);
|
||||
|
||||
private boolean isRestricted() {
|
||||
if ((mAttributes.getFlags() & AudioAttributes.FLAG_BYPASS_INTERRUPTION_POLICY) != 0) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
final int mode = mAppOps.checkAudioOperation(AppOpsManager.OP_PLAY_AUDIO,
|
||||
mAttributes.getUsage(),
|
||||
|
||||
Reference in New Issue
Block a user