In some countries (e.g. Japan), in order to prevent candid photography, the forced photo is required to come out of the speaker (even if the headset is plugged in).
The easiest way to do this is to set the camera type to ringtone or Alarm or notification type so that when device is selected in AudioPolicyManager.cpp, speaker is set to output Device
Another way is to set the camera sound to enforced_audible, which type of audio stream is interpreted:
enforced_audible = 7,// Sounds that cannot is muted by user and must is routed to Speaker
The explanation should be that this type of sound cannot be muted and must come out of the speaker.
But simply setting the audio stream type to enforced_audible does not guarantee that the sound will come out of the speaker from the AudioPolicyManager.cpp logic:
Casestrategy_enforced_audible://strategy Strategy_enforced_audible uses same routing policy as strategy_sonification//except://-When on call where it doesn ' t default to Strategy_phone behavior//-in countries where isn't enforced in which case it follows Strategy_media if((strategy = = strategy_sonification) | |(Mforceuse[audiosystem::for_system]==audiosystem::force_system_enforced)) {Device= Mavailableoutputdevices &Audio_device_out_speaker; if(Device = =Audio_device_none) {Aloge ("getdeviceforstrategy () speaker device not found for strategy_sonification"); } } //The second device used for sonification are the same as the device used by media strategy//FALL THROUGH CaseStrategy_media: {uint32_t device2=Audio_device_none; if(Strategy! =strategy_sonification) { //no sonification on remote submix (e.g. WFD)Device2 = mavailableoutputdevices &Audio_device_out_remote_submix; } if((Device2 = = Audio_device_none) &&MHASA2DP&& (Mforceuse[audiosystem::for_media]! = AUDIOSYSTEM::FORCE_NO_BT_A2DP) &&(Geta2dpoutput ()!=0) &&!ma2dpsuspended) {Device2= Mavailableoutputdevices &AUDIO_DEVICE_OUT_BLUETOOTH_A2DP; if(Device2 = =Audio_device_none) {Device2= Mavailableoutputdevices &Audio_device_out_bluetooth_a2dp_headphones; } if(Device2 = =Audio_device_none) {Device2= Mavailableoutputdevices &Audio_device_out_bluetooth_a2dp_speaker; } } if(Device2 = =Audio_device_none) {Device2= Mavailableoutputdevices &Audio_device_out_wired_headphone; } if(Device2 = =Audio_device_none) {Device2= Mavailableoutputdevices &Audio_device_out_wired_headset; } if(Device2 = =Audio_device_none) {Device2= Mavailableoutputdevices &audio_device_out_usb_accessory; } if(Device2 = =Audio_device_none) {Device2= Mavailableoutputdevices &Audio_device_out_usb_device; } if(Device2 = =Audio_device_none) {Device2= Mavailableoutputdevices &Audio_device_out_dgtl_dock_headset; } if(Device2 = = Audio_device_none) && (Strategy! =strategy_sonification)) { //no sonification on aux digital (e.g. HDMI)Device2 = mavailableoutputdevices &Audio_device_out_aux_digital; } if((Device2 = = Audio_device_none) &&(Mforceuse[audiosystem::for_dock]==Audiosystem::force_analog_dock)) {Device2= Mavailableoutputdevices &Audio_device_out_anlg_dock_headset; } if(Device2 = =Audio_device_none) {Device2= Mavailableoutputdevices &Audio_device_out_speaker; } //device is Device_out_speaker if we come from case strategy_sonification or//strategy_enforced_audible, Audio_device_none otherwiseDevice |=Device2; if(device) Break; Device=Mdefaultoutputdevice; if(Device = =Audio_device_none) {Aloge ("getdeviceforstrategy () No device found for Strategy_media"); } } Break;
In case strategy_enforced_audible, because the current (strategy! = strategy_sonification) is so wanted in the audio stream type is enforced_ In case of audible speaker still can make a sound, need to satisfy:(mforceuse[audiosystem::for_system] = = Audiosystem::force_system_ ENFORCED), otherwise The device of case Strategy_media will be follow.
and (mforceuse[audiosystem::for_system] = = audiosystem::force_system_enforced) on which side is set?
The code was searched globally, originally when Audioservice was initialized:
boolean camerasoundforced = mcontext.getresources (). Getboolean ( com.android.internal.r.bool.config_camera_sound_forced); New Boolean (camerasoundforced); Sendmsg (Maudiohandler, msg_set_force_use, sendmsg_queue, audiosystem.for_system, ? AudioSystem.FORCE_SYSTEM_ENFORCED:AudioSystem.FORCE_NONE, null, 0);
So when the value of camerasoundforced is true, it will Setforceuse (for_system,force_system_enforced); The com.android.internal.r.bool.config_camera_sound_forced is set in config. config_, so you need to add the The camera_sound_forced variable is set to True.
Camera Camera Sound setting