Merge "Optimize audio playback restriction check" into nyc-mr1-dev

This commit is contained in:
Jean-Michel Trivi
2016-07-13 21:50:57 +00:00
committed by Android (Google) Code Review
2 changed files with 26 additions and 17 deletions

View File

@@ -181,10 +181,15 @@ public abstract class PlayerBase {
* @return
*/
boolean isRestricted_sync() {
// check app ops
if (mHasAppOpsPlayAudio) {
return false;
}
// check bypass flag
if ((mAttributes.getAllFlags() & AudioAttributes.FLAG_BYPASS_INTERRUPTION_POLICY) != 0) {
return false;
}
return !mHasAppOpsPlayAudio;
return true;
}
// Abstract methods a subclass needs to implement

View File

@@ -505,27 +505,31 @@ public class SoundPool {
}
private boolean isRestricted() {
IAudioService service = getService();
boolean cameraSoundForced = false;
try {
cameraSoundForced = service.isCameraSoundForced();
} catch (RemoteException e) {
Log.e(TAG, "Cannot access AudioService in isRestricted()");
}
if (cameraSoundForced &&
((mAttributes.getAllFlags() & AudioAttributes.FLAG_AUDIBILITY_ENFORCED) != 0)
// FIXME: should also check usage when set properly by camera app
// && (mAttributes.getUsage() == AudioAttributes.USAGE_ASSISTANCE_SONIFICATION)
) {
// check app ops
if (mHasAppOpsPlayAudio) {
return false;
}
// check bypass flag
if ((mAttributes.getAllFlags() & AudioAttributes.FLAG_BYPASS_INTERRUPTION_POLICY) != 0) {
return false;
}
return !mHasAppOpsPlayAudio;
// check force audibility flag and camera restriction
if ((mAttributes.getAllFlags() & AudioAttributes.FLAG_AUDIBILITY_ENFORCED) != 0) {
// FIXME: should also check usage when set properly by camera app
// && (mAttributes.getUsage() == AudioAttributes.USAGE_ASSISTANCE_SONIFICATION)
boolean cameraSoundForced = false;
try {
cameraSoundForced = getService().isCameraSoundForced();
} catch (RemoteException e) {
Log.e(TAG, "Cannot access AudioService in isRestricted()");
} catch (NullPointerException e) {
Log.e(TAG, "Null AudioService in isRestricted()");
}
if (cameraSoundForced) {
return false;
}
}
return true;
}
private void updateAppOpsPlayAudio() {