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

am: 69c6166684

Change-Id: If626176f014e65f0248c5ae80d9196dd27076ec4
This commit is contained in:
Jean-Michel Trivi
2016-07-13 21:57:24 +00:00
committed by android-build-merger
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() {