Loading core/jni/android_media_AudioSystem.cpp +6 −0 Original line number Original line Diff line number Diff line Loading @@ -1554,6 +1554,11 @@ exit: return jStatus; return jStatus; } } static jint android_media_AudioSystem_systemReady(JNIEnv *env, jobject thiz) { return nativeToJavaStatus(AudioSystem::systemReady()); } // ---------------------------------------------------------------------------- // ---------------------------------------------------------------------------- Loading Loading @@ -1601,6 +1606,7 @@ static JNINativeMethod gMethods[] = { (void *)android_media_AudioSystem_registerPolicyMixes}, (void *)android_media_AudioSystem_registerPolicyMixes}, {"native_register_dynamic_policy_callback", "()V", {"native_register_dynamic_policy_callback", "()V", (void *)android_media_AudioSystem_registerDynPolicyCallback}, (void *)android_media_AudioSystem_registerDynPolicyCallback}, {"systemReady", "()I", (void *)android_media_AudioSystem_systemReady}, }; }; Loading media/java/android/media/AudioSystem.java +1 −0 Original line number Original line Diff line number Diff line Loading @@ -634,6 +634,7 @@ public class AudioSystem public static native int registerPolicyMixes(ArrayList<AudioMix> mixes, boolean register); public static native int registerPolicyMixes(ArrayList<AudioMix> mixes, boolean register); public static native int systemReady(); // Items shared with audio service // Items shared with audio service Loading services/core/java/com/android/server/audio/AudioService.java +114 −87 Original line number Original line Diff line number Diff line Loading @@ -217,6 +217,7 @@ public class AudioService extends IAudioService.Stub { private static final int MSG_PERSIST_MICROPHONE_MUTE = 23; private static final int MSG_PERSIST_MICROPHONE_MUTE = 23; private static final int MSG_UNMUTE_STREAM = 24; private static final int MSG_UNMUTE_STREAM = 24; private static final int MSG_DYN_POLICY_MIX_STATE_UPDATE = 25; private static final int MSG_DYN_POLICY_MIX_STATE_UPDATE = 25; private static final int MSG_INDICATE_SYSTEM_READY = 26; // 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(), // and not with sendMsg(..., ..., SENDMSG_QUEUE, ...) // and not with sendMsg(..., ..., SENDMSG_QUEUE, ...) Loading @@ -229,6 +230,9 @@ public class AudioService extends IAudioService.Stub { // Timeout for connection to bluetooth headset service // Timeout for connection to bluetooth headset service private static final int BT_HEADSET_CNCT_TIMEOUT_MS = 3000; private static final int BT_HEADSET_CNCT_TIMEOUT_MS = 3000; // retry delay in case of failure to indicate system ready to AudioFlinger private static final int INDICATE_SYSTEM_READY_RETRY_DELAY_MS = 1000; /** @see AudioSystemThread */ /** @see AudioSystemThread */ private AudioSystemThread mAudioSystemThread; private AudioSystemThread mAudioSystemThread; /** @see AudioHandler */ /** @see AudioHandler */ Loading Loading @@ -733,6 +737,108 @@ public class AudioService extends IAudioService.Stub { StreamOverride.init(mContext); StreamOverride.init(mContext); mControllerService.init(); mControllerService.init(); onIndicateSystemReady(); } void onIndicateSystemReady() { if (AudioSystem.systemReady() == AudioSystem.SUCCESS) { return; } sendMsg(mAudioHandler, MSG_INDICATE_SYSTEM_READY, SENDMSG_REPLACE, 0, 0, null, INDICATE_SYSTEM_READY_RETRY_DELAY_MS); } public void onMediaServerDied() { if (!mSystemReady || (AudioSystem.checkAudioFlinger() != AudioSystem.AUDIO_STATUS_OK)) { Log.e(TAG, "Media server died."); sendMsg(mAudioHandler, MSG_MEDIA_SERVER_DIED, SENDMSG_NOOP, 0, 0, null, 500); return; } Log.e(TAG, "Media server started."); // indicate to audio HAL that we start the reconfiguration phase after a media // server crash // Note that we only execute this when the media server // process restarts after a crash, not the first time it is started. AudioSystem.setParameters("restarting=true"); readAndSetLowRamDevice(); // Restore device connection states synchronized (mConnectedDevices) { for (int i = 0; i < mConnectedDevices.size(); i++) { DeviceListSpec spec = mConnectedDevices.valueAt(i); AudioSystem.setDeviceConnectionState( spec.mDeviceType, AudioSystem.DEVICE_STATE_AVAILABLE, spec.mDeviceAddress, spec.mDeviceName); } } // Restore call state AudioSystem.setPhoneState(mMode); // Restore forced usage for communcations and record AudioSystem.setForceUse(AudioSystem.FOR_COMMUNICATION, mForcedUseForComm); AudioSystem.setForceUse(AudioSystem.FOR_RECORD, mForcedUseForComm); AudioSystem.setForceUse(AudioSystem.FOR_SYSTEM, mCameraSoundForced ? AudioSystem.FORCE_SYSTEM_ENFORCED : AudioSystem.FORCE_NONE); // Restore stream volumes int numStreamTypes = AudioSystem.getNumStreamTypes(); for (int streamType = numStreamTypes - 1; streamType >= 0; streamType--) { VolumeStreamState streamState = mStreamStates[streamType]; AudioSystem.initStreamVolume(streamType, 0, (streamState.mIndexMax + 5) / 10); streamState.applyAllVolumes(); } // Restore ringer mode setRingerModeInt(getRingerModeInternal(), false); // Reset device orientation (if monitored for this device) if (mMonitorOrientation) { setOrientationForAudioSystem(); } if (mMonitorRotation) { setRotationForAudioSystem(); } synchronized (mBluetoothA2dpEnabledLock) { AudioSystem.setForceUse(AudioSystem.FOR_MEDIA, mBluetoothA2dpEnabled ? AudioSystem.FORCE_NONE : AudioSystem.FORCE_NO_BT_A2DP); } synchronized (mSettingsLock) { AudioSystem.setForceUse(AudioSystem.FOR_DOCK, mDockAudioMediaEnabled ? AudioSystem.FORCE_ANALOG_DOCK : AudioSystem.FORCE_NONE); } if (mHdmiManager != null) { synchronized (mHdmiManager) { if (mHdmiTvClient != null) { setHdmiSystemAudioSupported(mHdmiSystemAudioSupported); } } } synchronized (mAudioPolicies) { for (AudioPolicyProxy policy : mAudioPolicies.values()) { policy.connectMixes(); } } onIndicateSystemReady(); // indicate the end of reconfiguration phase to audio HAL AudioSystem.setParameters("restarting=false"); } } private void createAudioSystemThread() { private void createAudioSystemThread() { Loading Loading @@ -4147,90 +4253,7 @@ public class AudioService extends IAudioService.Stub { break; break; case MSG_MEDIA_SERVER_DIED: case MSG_MEDIA_SERVER_DIED: if (!mSystemReady || onMediaServerDied(); (AudioSystem.checkAudioFlinger() != AudioSystem.AUDIO_STATUS_OK)) { Log.e(TAG, "Media server died."); sendMsg(mAudioHandler, MSG_MEDIA_SERVER_DIED, SENDMSG_NOOP, 0, 0, null, 500); break; } Log.e(TAG, "Media server started."); // indicate to audio HAL that we start the reconfiguration phase after a media // server crash // Note that we only execute this when the media server // process restarts after a crash, not the first time it is started. AudioSystem.setParameters("restarting=true"); readAndSetLowRamDevice(); // Restore device connection states synchronized (mConnectedDevices) { for (int i = 0; i < mConnectedDevices.size(); i++) { DeviceListSpec spec = mConnectedDevices.valueAt(i); AudioSystem.setDeviceConnectionState( spec.mDeviceType, AudioSystem.DEVICE_STATE_AVAILABLE, spec.mDeviceAddress, spec.mDeviceName); } } // Restore call state AudioSystem.setPhoneState(mMode); // Restore forced usage for communcations and record AudioSystem.setForceUse(AudioSystem.FOR_COMMUNICATION, mForcedUseForComm); AudioSystem.setForceUse(AudioSystem.FOR_RECORD, mForcedUseForComm); AudioSystem.setForceUse(AudioSystem.FOR_SYSTEM, mCameraSoundForced ? AudioSystem.FORCE_SYSTEM_ENFORCED : AudioSystem.FORCE_NONE); // Restore stream volumes int numStreamTypes = AudioSystem.getNumStreamTypes(); for (int streamType = numStreamTypes - 1; streamType >= 0; streamType--) { VolumeStreamState streamState = mStreamStates[streamType]; AudioSystem.initStreamVolume(streamType, 0, (streamState.mIndexMax + 5) / 10); streamState.applyAllVolumes(); } // Restore ringer mode setRingerModeInt(getRingerModeInternal(), false); // Reset device orientation (if monitored for this device) if (mMonitorOrientation) { setOrientationForAudioSystem(); } if (mMonitorRotation) { setRotationForAudioSystem(); } synchronized (mBluetoothA2dpEnabledLock) { AudioSystem.setForceUse(AudioSystem.FOR_MEDIA, mBluetoothA2dpEnabled ? AudioSystem.FORCE_NONE : AudioSystem.FORCE_NO_BT_A2DP); } synchronized (mSettingsLock) { AudioSystem.setForceUse(AudioSystem.FOR_DOCK, mDockAudioMediaEnabled ? AudioSystem.FORCE_ANALOG_DOCK : AudioSystem.FORCE_NONE); } if (mHdmiManager != null) { synchronized (mHdmiManager) { if (mHdmiTvClient != null) { setHdmiSystemAudioSupported(mHdmiSystemAudioSupported); } } } synchronized (mAudioPolicies) { for(AudioPolicyProxy policy : mAudioPolicies.values()) { policy.connectMixes(); } } // indicate the end of reconfiguration phase to audio HAL AudioSystem.setParameters("restarting=false"); break; break; case MSG_UNLOAD_SOUND_EFFECTS: case MSG_UNLOAD_SOUND_EFFECTS: Loading Loading @@ -4335,6 +4358,10 @@ public class AudioService extends IAudioService.Stub { onSystemReady(); onSystemReady(); break; break; case MSG_INDICATE_SYSTEM_READY: onIndicateSystemReady(); break; case MSG_PERSIST_MUSIC_ACTIVE_MS: case MSG_PERSIST_MUSIC_ACTIVE_MS: final int musicActiveMs = msg.arg1; final int musicActiveMs = msg.arg1; Settings.Secure.putIntForUser(mContentResolver, Settings.Secure.putIntForUser(mContentResolver, Loading Loading
core/jni/android_media_AudioSystem.cpp +6 −0 Original line number Original line Diff line number Diff line Loading @@ -1554,6 +1554,11 @@ exit: return jStatus; return jStatus; } } static jint android_media_AudioSystem_systemReady(JNIEnv *env, jobject thiz) { return nativeToJavaStatus(AudioSystem::systemReady()); } // ---------------------------------------------------------------------------- // ---------------------------------------------------------------------------- Loading Loading @@ -1601,6 +1606,7 @@ static JNINativeMethod gMethods[] = { (void *)android_media_AudioSystem_registerPolicyMixes}, (void *)android_media_AudioSystem_registerPolicyMixes}, {"native_register_dynamic_policy_callback", "()V", {"native_register_dynamic_policy_callback", "()V", (void *)android_media_AudioSystem_registerDynPolicyCallback}, (void *)android_media_AudioSystem_registerDynPolicyCallback}, {"systemReady", "()I", (void *)android_media_AudioSystem_systemReady}, }; }; Loading
media/java/android/media/AudioSystem.java +1 −0 Original line number Original line Diff line number Diff line Loading @@ -634,6 +634,7 @@ public class AudioSystem public static native int registerPolicyMixes(ArrayList<AudioMix> mixes, boolean register); public static native int registerPolicyMixes(ArrayList<AudioMix> mixes, boolean register); public static native int systemReady(); // Items shared with audio service // Items shared with audio service Loading
services/core/java/com/android/server/audio/AudioService.java +114 −87 Original line number Original line Diff line number Diff line Loading @@ -217,6 +217,7 @@ public class AudioService extends IAudioService.Stub { private static final int MSG_PERSIST_MICROPHONE_MUTE = 23; private static final int MSG_PERSIST_MICROPHONE_MUTE = 23; private static final int MSG_UNMUTE_STREAM = 24; private static final int MSG_UNMUTE_STREAM = 24; private static final int MSG_DYN_POLICY_MIX_STATE_UPDATE = 25; private static final int MSG_DYN_POLICY_MIX_STATE_UPDATE = 25; private static final int MSG_INDICATE_SYSTEM_READY = 26; // 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(), // and not with sendMsg(..., ..., SENDMSG_QUEUE, ...) // and not with sendMsg(..., ..., SENDMSG_QUEUE, ...) Loading @@ -229,6 +230,9 @@ public class AudioService extends IAudioService.Stub { // Timeout for connection to bluetooth headset service // Timeout for connection to bluetooth headset service private static final int BT_HEADSET_CNCT_TIMEOUT_MS = 3000; private static final int BT_HEADSET_CNCT_TIMEOUT_MS = 3000; // retry delay in case of failure to indicate system ready to AudioFlinger private static final int INDICATE_SYSTEM_READY_RETRY_DELAY_MS = 1000; /** @see AudioSystemThread */ /** @see AudioSystemThread */ private AudioSystemThread mAudioSystemThread; private AudioSystemThread mAudioSystemThread; /** @see AudioHandler */ /** @see AudioHandler */ Loading Loading @@ -733,6 +737,108 @@ public class AudioService extends IAudioService.Stub { StreamOverride.init(mContext); StreamOverride.init(mContext); mControllerService.init(); mControllerService.init(); onIndicateSystemReady(); } void onIndicateSystemReady() { if (AudioSystem.systemReady() == AudioSystem.SUCCESS) { return; } sendMsg(mAudioHandler, MSG_INDICATE_SYSTEM_READY, SENDMSG_REPLACE, 0, 0, null, INDICATE_SYSTEM_READY_RETRY_DELAY_MS); } public void onMediaServerDied() { if (!mSystemReady || (AudioSystem.checkAudioFlinger() != AudioSystem.AUDIO_STATUS_OK)) { Log.e(TAG, "Media server died."); sendMsg(mAudioHandler, MSG_MEDIA_SERVER_DIED, SENDMSG_NOOP, 0, 0, null, 500); return; } Log.e(TAG, "Media server started."); // indicate to audio HAL that we start the reconfiguration phase after a media // server crash // Note that we only execute this when the media server // process restarts after a crash, not the first time it is started. AudioSystem.setParameters("restarting=true"); readAndSetLowRamDevice(); // Restore device connection states synchronized (mConnectedDevices) { for (int i = 0; i < mConnectedDevices.size(); i++) { DeviceListSpec spec = mConnectedDevices.valueAt(i); AudioSystem.setDeviceConnectionState( spec.mDeviceType, AudioSystem.DEVICE_STATE_AVAILABLE, spec.mDeviceAddress, spec.mDeviceName); } } // Restore call state AudioSystem.setPhoneState(mMode); // Restore forced usage for communcations and record AudioSystem.setForceUse(AudioSystem.FOR_COMMUNICATION, mForcedUseForComm); AudioSystem.setForceUse(AudioSystem.FOR_RECORD, mForcedUseForComm); AudioSystem.setForceUse(AudioSystem.FOR_SYSTEM, mCameraSoundForced ? AudioSystem.FORCE_SYSTEM_ENFORCED : AudioSystem.FORCE_NONE); // Restore stream volumes int numStreamTypes = AudioSystem.getNumStreamTypes(); for (int streamType = numStreamTypes - 1; streamType >= 0; streamType--) { VolumeStreamState streamState = mStreamStates[streamType]; AudioSystem.initStreamVolume(streamType, 0, (streamState.mIndexMax + 5) / 10); streamState.applyAllVolumes(); } // Restore ringer mode setRingerModeInt(getRingerModeInternal(), false); // Reset device orientation (if monitored for this device) if (mMonitorOrientation) { setOrientationForAudioSystem(); } if (mMonitorRotation) { setRotationForAudioSystem(); } synchronized (mBluetoothA2dpEnabledLock) { AudioSystem.setForceUse(AudioSystem.FOR_MEDIA, mBluetoothA2dpEnabled ? AudioSystem.FORCE_NONE : AudioSystem.FORCE_NO_BT_A2DP); } synchronized (mSettingsLock) { AudioSystem.setForceUse(AudioSystem.FOR_DOCK, mDockAudioMediaEnabled ? AudioSystem.FORCE_ANALOG_DOCK : AudioSystem.FORCE_NONE); } if (mHdmiManager != null) { synchronized (mHdmiManager) { if (mHdmiTvClient != null) { setHdmiSystemAudioSupported(mHdmiSystemAudioSupported); } } } synchronized (mAudioPolicies) { for (AudioPolicyProxy policy : mAudioPolicies.values()) { policy.connectMixes(); } } onIndicateSystemReady(); // indicate the end of reconfiguration phase to audio HAL AudioSystem.setParameters("restarting=false"); } } private void createAudioSystemThread() { private void createAudioSystemThread() { Loading Loading @@ -4147,90 +4253,7 @@ public class AudioService extends IAudioService.Stub { break; break; case MSG_MEDIA_SERVER_DIED: case MSG_MEDIA_SERVER_DIED: if (!mSystemReady || onMediaServerDied(); (AudioSystem.checkAudioFlinger() != AudioSystem.AUDIO_STATUS_OK)) { Log.e(TAG, "Media server died."); sendMsg(mAudioHandler, MSG_MEDIA_SERVER_DIED, SENDMSG_NOOP, 0, 0, null, 500); break; } Log.e(TAG, "Media server started."); // indicate to audio HAL that we start the reconfiguration phase after a media // server crash // Note that we only execute this when the media server // process restarts after a crash, not the first time it is started. AudioSystem.setParameters("restarting=true"); readAndSetLowRamDevice(); // Restore device connection states synchronized (mConnectedDevices) { for (int i = 0; i < mConnectedDevices.size(); i++) { DeviceListSpec spec = mConnectedDevices.valueAt(i); AudioSystem.setDeviceConnectionState( spec.mDeviceType, AudioSystem.DEVICE_STATE_AVAILABLE, spec.mDeviceAddress, spec.mDeviceName); } } // Restore call state AudioSystem.setPhoneState(mMode); // Restore forced usage for communcations and record AudioSystem.setForceUse(AudioSystem.FOR_COMMUNICATION, mForcedUseForComm); AudioSystem.setForceUse(AudioSystem.FOR_RECORD, mForcedUseForComm); AudioSystem.setForceUse(AudioSystem.FOR_SYSTEM, mCameraSoundForced ? AudioSystem.FORCE_SYSTEM_ENFORCED : AudioSystem.FORCE_NONE); // Restore stream volumes int numStreamTypes = AudioSystem.getNumStreamTypes(); for (int streamType = numStreamTypes - 1; streamType >= 0; streamType--) { VolumeStreamState streamState = mStreamStates[streamType]; AudioSystem.initStreamVolume(streamType, 0, (streamState.mIndexMax + 5) / 10); streamState.applyAllVolumes(); } // Restore ringer mode setRingerModeInt(getRingerModeInternal(), false); // Reset device orientation (if monitored for this device) if (mMonitorOrientation) { setOrientationForAudioSystem(); } if (mMonitorRotation) { setRotationForAudioSystem(); } synchronized (mBluetoothA2dpEnabledLock) { AudioSystem.setForceUse(AudioSystem.FOR_MEDIA, mBluetoothA2dpEnabled ? AudioSystem.FORCE_NONE : AudioSystem.FORCE_NO_BT_A2DP); } synchronized (mSettingsLock) { AudioSystem.setForceUse(AudioSystem.FOR_DOCK, mDockAudioMediaEnabled ? AudioSystem.FORCE_ANALOG_DOCK : AudioSystem.FORCE_NONE); } if (mHdmiManager != null) { synchronized (mHdmiManager) { if (mHdmiTvClient != null) { setHdmiSystemAudioSupported(mHdmiSystemAudioSupported); } } } synchronized (mAudioPolicies) { for(AudioPolicyProxy policy : mAudioPolicies.values()) { policy.connectMixes(); } } // indicate the end of reconfiguration phase to audio HAL AudioSystem.setParameters("restarting=false"); break; break; case MSG_UNLOAD_SOUND_EFFECTS: case MSG_UNLOAD_SOUND_EFFECTS: Loading Loading @@ -4335,6 +4358,10 @@ public class AudioService extends IAudioService.Stub { onSystemReady(); onSystemReady(); break; break; case MSG_INDICATE_SYSTEM_READY: onIndicateSystemReady(); break; case MSG_PERSIST_MUSIC_ACTIVE_MS: case MSG_PERSIST_MUSIC_ACTIVE_MS: final int musicActiveMs = msg.arg1; final int musicActiveMs = msg.arg1; Settings.Secure.putIntForUser(mContentResolver, Settings.Secure.putIntForUser(mContentResolver, Loading