Merge "Spatial audio: read prop for spatializer init, persist feature state" into sc-v2-dev am: a1b54abe38
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/15881055 Change-Id: Ie4bc80234b23c69c3bf63603f292abc525e77353
This commit is contained in:
@@ -8980,6 +8980,15 @@ public final class Settings {
|
|||||||
@Readable
|
@Readable
|
||||||
public static final String UNSAFE_VOLUME_MUSIC_ACTIVE_MS = "unsafe_volume_music_active_ms";
|
public static final String UNSAFE_VOLUME_MUSIC_ACTIVE_MS = "unsafe_volume_music_active_ms";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates whether the spatial audio feature was enabled for this user.
|
||||||
|
*
|
||||||
|
* Type : int (0 disabled, 1 enabled)
|
||||||
|
*
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
public static final String SPATIAL_AUDIO_ENABLED = "spatial_audio_enabled";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Indicates whether notification display on the lock screen is enabled.
|
* Indicates whether notification display on the lock screen is enabled.
|
||||||
* <p>
|
* <p>
|
||||||
|
|||||||
@@ -319,6 +319,7 @@ public class AudioService extends IAudioService.Stub
|
|||||||
private static final int MSG_DISPATCH_AUDIO_MODE = 40;
|
private static final int MSG_DISPATCH_AUDIO_MODE = 40;
|
||||||
private static final int MSG_ROUTING_UPDATED = 41;
|
private static final int MSG_ROUTING_UPDATED = 41;
|
||||||
private static final int MSG_INIT_HEADTRACKING_SENSORS = 42;
|
private static final int MSG_INIT_HEADTRACKING_SENSORS = 42;
|
||||||
|
private static final int MSG_PERSIST_SPATIAL_AUDIO_ENABLED = 43;
|
||||||
|
|
||||||
// start of messages handled under wakelock
|
// start of messages handled under wakelock
|
||||||
// these messages can only be queued, i.e. sent with queueMsgUnderWakeLock(),
|
// these messages can only be queued, i.e. sent with queueMsgUnderWakeLock(),
|
||||||
@@ -1038,12 +1039,13 @@ public class AudioService extends IAudioService.Stub
|
|||||||
|
|
||||||
mMonitorRotation = SystemProperties.getBoolean("ro.audio.monitorRotation", false);
|
mMonitorRotation = SystemProperties.getBoolean("ro.audio.monitorRotation", false);
|
||||||
|
|
||||||
|
mHasSpatializerEffect = SystemProperties.getBoolean("ro.audio.spatializer_enabled", false);
|
||||||
|
|
||||||
// done with service initialization, continue additional work in our Handler thread
|
// done with service initialization, continue additional work in our Handler thread
|
||||||
queueMsgUnderWakeLock(mAudioHandler, MSG_INIT_STREAMS_VOLUMES,
|
queueMsgUnderWakeLock(mAudioHandler, MSG_INIT_STREAMS_VOLUMES,
|
||||||
0 /* arg1 */, 0 /* arg2 */, null /* obj */, 0 /* delay */);
|
0 /* arg1 */, 0 /* arg2 */, null /* obj */, 0 /* delay */);
|
||||||
queueMsgUnderWakeLock(mAudioHandler, MSG_INIT_SPATIALIZER,
|
queueMsgUnderWakeLock(mAudioHandler, MSG_INIT_SPATIALIZER,
|
||||||
0 /* arg1 */, 0 /* arg2 */, null /* obj */, 0 /* delay */);
|
0 /* arg1 */, 0 /* arg2 */, null /* obj */, 0 /* delay */);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1237,6 +1239,9 @@ public class AudioService extends IAudioService.Stub
|
|||||||
// routing monitoring from AudioSystemAdapter
|
// routing monitoring from AudioSystemAdapter
|
||||||
@Override
|
@Override
|
||||||
public void onRoutingUpdatedFromNative() {
|
public void onRoutingUpdatedFromNative() {
|
||||||
|
if (!mHasSpatializerEffect) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
sendMsg(mAudioHandler,
|
sendMsg(mAudioHandler,
|
||||||
MSG_ROUTING_UPDATED,
|
MSG_ROUTING_UPDATED,
|
||||||
SENDMSG_REPLACE, 0, 0, null,
|
SENDMSG_REPLACE, 0, 0, null,
|
||||||
@@ -1433,8 +1438,10 @@ public class AudioService extends IAudioService.Stub
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO check property if feature enabled
|
if (mHasSpatializerEffect) {
|
||||||
mSpatializerHelper.reset(/* featureEnabled */ SPATIALIZER_FEATURE_ENABLED_DEFAULT);
|
mSpatializerHelper.reset(/* featureEnabled */ isSpatialAudioEnabled());
|
||||||
|
monitorRoutingChanges(true);
|
||||||
|
}
|
||||||
|
|
||||||
onIndicateSystemReady();
|
onIndicateSystemReady();
|
||||||
// indicate the end of reconfiguration phase to audio HAL
|
// indicate the end of reconfiguration phase to audio HAL
|
||||||
@@ -7602,9 +7609,11 @@ public class AudioService extends IAudioService.Stub
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case MSG_INIT_SPATIALIZER:
|
case MSG_INIT_SPATIALIZER:
|
||||||
mSpatializerHelper.init();
|
mSpatializerHelper.init(/*effectExpected*/ mHasSpatializerEffect);
|
||||||
// TODO read property to see if enabled
|
if (mHasSpatializerEffect) {
|
||||||
mSpatializerHelper.setFeatureEnabled(SPATIALIZER_FEATURE_ENABLED_DEFAULT);
|
mSpatializerHelper.setFeatureEnabled(isSpatialAudioEnabled());
|
||||||
|
monitorRoutingChanges(true);
|
||||||
|
}
|
||||||
mAudioEventWakeLock.release();
|
mAudioEventWakeLock.release();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -7748,6 +7757,10 @@ public class AudioService extends IAudioService.Stub
|
|||||||
case MSG_ROUTING_UPDATED:
|
case MSG_ROUTING_UPDATED:
|
||||||
mSpatializerHelper.onRoutingUpdated();
|
mSpatializerHelper.onRoutingUpdated();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case MSG_PERSIST_SPATIAL_AUDIO_ENABLED:
|
||||||
|
onPersistSpatialAudioEnabled(msg.arg1 == 1);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -8317,7 +8330,40 @@ public class AudioService extends IAudioService.Stub
|
|||||||
|
|
||||||
//==========================================================================================
|
//==========================================================================================
|
||||||
private final @NonNull SpatializerHelper mSpatializerHelper;
|
private final @NonNull SpatializerHelper mSpatializerHelper;
|
||||||
private static final boolean SPATIALIZER_FEATURE_ENABLED_DEFAULT = false;
|
/**
|
||||||
|
* Initialized from property ro.audio.spatializer_enabled
|
||||||
|
* Should only be 1 when the device ships with a Spatializer effect
|
||||||
|
*/
|
||||||
|
private final boolean mHasSpatializerEffect;
|
||||||
|
/**
|
||||||
|
* Default value for the spatial audio feature
|
||||||
|
*/
|
||||||
|
private static final boolean SPATIAL_AUDIO_ENABLED_DEFAULT = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* persist in user settings whether the feature is enabled.
|
||||||
|
* Can change when {@link Spatializer#setEnabled(boolean)} is called and successfully
|
||||||
|
* changes the state of the feature
|
||||||
|
* @param featureEnabled
|
||||||
|
*/
|
||||||
|
void persistSpatialAudioEnabled(boolean featureEnabled) {
|
||||||
|
sendMsg(mAudioHandler,
|
||||||
|
MSG_PERSIST_SPATIAL_AUDIO_ENABLED,
|
||||||
|
SENDMSG_REPLACE, featureEnabled ? 1 : 0, 0, null,
|
||||||
|
/*delay ms*/ 100);
|
||||||
|
}
|
||||||
|
|
||||||
|
void onPersistSpatialAudioEnabled(boolean enabled) {
|
||||||
|
Settings.Secure.putIntForUser(mContentResolver,
|
||||||
|
Settings.Secure.SPATIAL_AUDIO_ENABLED, enabled ? 1 : 0,
|
||||||
|
UserHandle.USER_CURRENT);
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean isSpatialAudioEnabled() {
|
||||||
|
return Settings.Secure.getIntForUser(mContentResolver,
|
||||||
|
Settings.Secure.SPATIAL_AUDIO_ENABLED, SPATIAL_AUDIO_ENABLED_DEFAULT ? 1 : 0,
|
||||||
|
UserHandle.USER_CURRENT) == 1;
|
||||||
|
}
|
||||||
|
|
||||||
private void enforceModifyDefaultAudioEffectsPermission() {
|
private void enforceModifyDefaultAudioEffectsPermission() {
|
||||||
if (mContext.checkCallingOrSelfPermission(
|
if (mContext.checkCallingOrSelfPermission(
|
||||||
@@ -9076,6 +9122,12 @@ public class AudioService extends IAudioService.Stub
|
|||||||
sVolumeLogger.dump(pw);
|
sVolumeLogger.dump(pw);
|
||||||
pw.println("\n");
|
pw.println("\n");
|
||||||
dumpSupportedSystemUsage(pw);
|
dumpSupportedSystemUsage(pw);
|
||||||
|
|
||||||
|
pw.println("\n");
|
||||||
|
pw.println("\nSpatial audio:");
|
||||||
|
pw.println("mHasSpatializerEffect:" + mHasSpatializerEffect);
|
||||||
|
pw.println("isSpatializerEnabled:" + isSpatializerEnabled());
|
||||||
|
pw.println("isSpatialAudioEnabled:" + isSpatialAudioEnabled());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void dumpSupportedSystemUsage(PrintWriter pw) {
|
private void dumpSupportedSystemUsage(PrintWriter pw) {
|
||||||
|
|||||||
@@ -106,8 +106,13 @@ public class SpatializerHelper {
|
|||||||
mASA = asa;
|
mASA = asa;
|
||||||
}
|
}
|
||||||
|
|
||||||
synchronized void init() {
|
synchronized void init(boolean effectExpected) {
|
||||||
Log.i(TAG, "Initializing");
|
Log.i(TAG, "Initializing");
|
||||||
|
if (!effectExpected) {
|
||||||
|
Log.i(TAG, "Setting state to STATE_NOT_SUPPORTED due to effect not expected");
|
||||||
|
mState = STATE_NOT_SUPPORTED;
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (mState != STATE_UNINITIALIZED) {
|
if (mState != STATE_UNINITIALIZED) {
|
||||||
throw new IllegalStateException(("init() called in state:" + mState));
|
throw new IllegalStateException(("init() called in state:" + mState));
|
||||||
}
|
}
|
||||||
@@ -165,7 +170,7 @@ public class SpatializerHelper {
|
|||||||
mSpatLevel = Spatializer.SPATIALIZER_IMMERSIVE_LEVEL_NONE;
|
mSpatLevel = Spatializer.SPATIALIZER_IMMERSIVE_LEVEL_NONE;
|
||||||
mCapableSpatLevel = Spatializer.SPATIALIZER_IMMERSIVE_LEVEL_NONE;
|
mCapableSpatLevel = Spatializer.SPATIALIZER_IMMERSIVE_LEVEL_NONE;
|
||||||
mActualHeadTrackingMode = Spatializer.HEAD_TRACKING_MODE_UNSUPPORTED;
|
mActualHeadTrackingMode = Spatializer.HEAD_TRACKING_MODE_UNSUPPORTED;
|
||||||
init();
|
init(true);
|
||||||
setFeatureEnabled(featureEnabled);
|
setFeatureEnabled(featureEnabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -391,7 +396,7 @@ public class SpatializerHelper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
mStateCallbacks.finishBroadcast();
|
mStateCallbacks.finishBroadcast();
|
||||||
// TODO persist enabled state
|
mAudioService.persistSpatialAudioEnabled(featureEnabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
private synchronized void setDispatchAvailableState(boolean available) {
|
private synchronized void setDispatchAvailableState(boolean available) {
|
||||||
|
|||||||
Reference in New Issue
Block a user