HAL การควบคุมเสียง

HAL การควบคุมเสียงเปิดตัวใน Android 9 เพื่อรองรับกรณีการใช้งานเสียงที่เกี่ยวข้องกับยานยนต์ ตั้งแต่ Android 14 เป็นต้นไป HAL การควบคุมเสียงรองรับรายการต่อไปนี้

  • ค่อยๆ เบาลงและปรับสมดุล
  • คำขอโฟกัสเสียง HAL
  • การปิดเสียงและลดเสียงของอุปกรณ์
  • การเปลี่ยนแปลงระดับการขยายเสียงของอุปกรณ์
  • การเปลี่ยนแปลงการกำหนดค่าพอร์ตเสียง

รูปที่ 1 แสดงภาพรวมระดับสูงของสถาปัตยกรรมบริการเสียงรถยนต์ ซึ่งบริการเสียงรถยนต์จะสื่อสารกับ HAL การควบคุมเสียง

กำหนดค่าเสียงหลายโซน

รูปที่ 1 กำหนดค่าเสียงหลายโซน

เสียงค่อยๆ เบาลงและสมดุลเสียง

HAL การควบคุมเสียง HIDL เวอร์ชัน 1 เปิดตัวใน Android 9 เพื่อรองรับการเลี้ยวเสียงและการปรับสมดุลเสียงในการใช้งานยานยนต์ กลไกนี้แยกจากเอฟเฟกต์เสียงทั่วไปที่มีให้อยู่แล้วใน Android โดยช่วยให้แอปของระบบสามารถตั้งค่าสมดุลเสียงและทำให้เสียงค่อยๆ เบาลงผ่านCarAudioManager API ต่อไปนี้

class CarAudioManager {
       /**
       *   Adjust the relative volume in the front vs back of the vehicle cabin.
       *
       *   @param value in the range -1.0 to 1.0 for fully toward the back through
       *   fully toward the front. 0.0 means evenly balanced.
       */
       @SystemApi
       @RequiresPermission(Car.PERMISSION_CAR_CONTROL_AUDIO_VOLUME)
       public void setFadeTowardFront(float value);

       /**
       *   Adjust the relative volume on the left vs right side of the vehicle cabin.
       *
       *   @param value in the range -1.0 to 1.0 for fully toward the left through
       *   fully toward the right. 0.0 means evenly balanced.
       */
       @SystemApi
       @RequiresPermission(Car.PERMISSION_CAR_CONTROL_AUDIO_VOLUME)
       public void setBalanceTowardRight(float value);
}

เมื่อเรียก API เหล่านี้ ระบบจะเรียก HAL API การควบคุมเสียงที่เกี่ยวข้องจากบริการเสียงของรถยนต์

interface IAudioControl {
       /**
       *   Control the right/left balance setting of the car speakers.
       */
       oneway setBalanceTowardRight(float value);

       /**
       *   Control the fore/aft fade setting of the car speakers.
       */
       oneway setFadeTowardFront(float value);
}

API พร้อมใช้งานใน HAL การควบคุมเสียงทุกเวอร์ชัน รวมถึงอินเทอร์เฟซ AIDL HAL เวอร์ชันใหม่

คำขอโฟกัสเสียงจาก HAL

AAOS ทำงานคล้ายกับ Android โดยอาศัยการเข้าร่วมของแอปในโหมดโฟกัสเสียงเพื่อจัดการการเล่นเสียงในรถยนต์ ระบบจะใช้ข้อมูลโฟกัสเพื่อจัดการว่าสตรีมใดที่จะควบคุมระดับเสียงและการลดเสียง ด้วยเหตุนี้ เราจึงเปิดตัวแอตทริบิวต์เสียงต่อไปนี้ใน Android 11 เพื่อขยายการมุ่งเน้นที่เสียงให้ดียิ่งขึ้นและเพื่อผสานรวมเสียงเฉพาะของรถยนต์เข้ากับประสบการณ์การใช้งาน Android ได้ดียิ่งขึ้น

  • EMERGENCY
  • SAFETY
  • VEHICLE_STATUS
  • ANNOUNCEMENT

นอกจากการเปลี่ยนแปลงนี้แล้ว เรายังได้เพิ่มกลไกสำหรับเสียงที่มาจากภายนอก Android เพื่อให้เข้าร่วมในคำขอโฟกัสเสียงด้วย ด้วยเหตุนี้ เราจึงเปิดตัว HAL การควบคุมเสียง HIDL เวอร์ชัน 2 เพื่อรองรับคำขอโฟกัสที่มาจากภายนอก Android ดังนี้

interface IAudioControl {
       /**
       *   Registers focus listener to be used by HAL for requesting and
       *   abandoning audio focus.
       *   @param listener the listener interface
       *   @return closeHandle A handle to unregister observer.
       */
       registerFocusListener(IFocusListener listener)
       generates (ICloseHandle closeHandle);

       /**
       *   Notifies HAL of changes in audio focus status for focuses requested
       *   or abandoned by the HAL.
       *
       *   @param usage The audio usage associated with the focus change
       *   @param zoneId The identifier for the audio zone that the HAL is
       *   playing the stream in
       *   @param focusChange the AudioFocusChange that has occurred
       */
       oneway onAudioFocusChange(bitfield<AudioUsage> usage, int32_t zoneId,
       bitfield<AudioFocusChange> focusChange);
}

โดยที่ IFocusListener หมายถึง

interface IFocusListener {
       /**
       *   Called whenever HAL is requesting focus as it is starting to play
       *   audio of a given usage in a specified zone.
       *
       *   @param usage The audio usage associated with the focus request
       *    {@code AttributeUsage}
       *   @param zoneId The identifier for the audio zone where the HAL is
       *    requesting focus
       *   @param focusGain The AudioFocusChange associated with this request.
       */
       oneway requestAudioFocus(bitfield<AudioUsage> usage,
       int32_t zoneId, bitfield<AudioFocusChange> focusGain);
       /**
       *   Called whenever HAL is abandoning focus as it is finished playing audio
       *   of a given usage in a specific zone.
       *
       *   @param usage The audio usage for which the HAL is abandoning focus
       *    {@code AttributeUsage}
       *   @param zoneId The identifier for the audio zone that the HAL
       *    abandoning focus
       */
       oneway abandonAudioFocus(bitfield<AudioUsage> usage, int32_t zoneId);
}

API ด้านบนสามารถใช้เพื่อขอและยกเลิกโฟกัสเสียงจาก HAL ตามลำดับ บริการเสียงของรถยนต์จะพิจารณาคำขอโฟกัสเสียงและส่งต่อผลลัพธ์แบบไม่พร้อมกันไปยังเมธอด IAudioControl#onAudioFocusChange

นอกจากนี้ คุณยังใช้ API นี้เพื่อตรวจสอบการเปลี่ยนแปลงของคำขอโฟกัสเสียงที่มาจาก HAL การควบคุมเสียงได้ด้วย โดยทั่วไปแล้ว คำขอโฟกัสเสียงที่รอดำเนินการจาก HAL จะถือว่าทำงานอยู่ ซึ่งแตกต่างจากคำขอโฟกัสเสียงจาก Android ที่ถือว่าเฉพาะการเล่นแทร็กเสียงที่เกี่ยวข้องเท่านั้นที่ทำงานอยู่

ย้ายข้อมูล HIDL ไปยัง HAL การควบคุมเสียง AIDL

เมื่อ AIDL ถือกำเนิดขึ้นและการย้ายข้อมูลที่จำเป็นใน Android 12 (ดูข้อมูลเพิ่มเติมได้ที่ AIDL สำหรับ HAL) ระบบได้ย้ายข้อมูล HAL การควบคุมเสียงไปยัง AIDL สําหรับ API การควบคุมเสียง HIDL เวอร์ชัน 2 ที่มีอยู่ การย้ายข้อมูลจำเป็นต้องมีการอัปเดตเล็กน้อยในเมธอดที่มีอยู่ ดังนี้

interface IAudioControl {
       /**
       *   Notifies HAL of changes in audio focus status for focuses requested
       *   or abandoned by the HAL.
       *
       *   @param usage The audio usage associated with the focus change
       *        {@code AttributeUsage}. See {@code audioUsage} in
       *        audio_policy_configuration.xsd for the list of allowed values.
       *   @param zoneId The identifier for the audio zone that the HAL is
       *        playing the stream in
       *   @param focusChange the AudioFocusChange that has occurred.
       */
       oneway void onAudioFocusChange(in String usage, in int zoneId,
              in AudioFocusChange focusChange);
       /**
       *   Registers focus listener to be used by HAL for requesting and
       *   abandoning audio focus.
       *   @param listener the listener interface.
       */
       oneway void registerFocusListener(in IFocusListener listener);
       /**
       *   Control the right/left balance setting of the car speakers.
       */
       oneway void setBalanceTowardRight(in float value);
       /**
       *   Control the fore/aft fade setting of the car speakers.
       */
       oneway void setFadeTowardFront(in float value);
}

และ IFocusListener ที่เกี่ยวข้อง

       interface IFocusListener {
       /**
       *   Called whenever HAL is abandoning focus as it is finished playing audio
       *   of a given usage in a specific zone.
       *
       *   @param usage The audio usage for which the HAL is abandoning focus
       *        {@code AttributeUsage}. See {@code audioUsage} in
       *        audio_policy_configuration.xsd for the list of allowed values.
       *   @param zoneId The identifier for the audio zone that the HAL
       *        abandoning focus
       */
       oneway void abandonAudioFocus(in String usage, in int zoneId);
       /**
       *   Called whenever HAL is requesting focus as it is starting to play audio
       *        of a given usage in a specified zone.
       *
       *   @param usage The audio usage associated with the focus request
       *        {@code AttributeUsage}. See {@code audioUsage} in
       *        audio_policy_configuration.xsd for the list of allowed values.
       *   @param zoneId The identifier for the audio zone where the HAL is
       *        requesting focus
       *   @param focusGain The AudioFocusChange associated with this request.
       */
       oneway void requestAudioFocus(in String usage, in int zoneId,
              in AudioFocusChange focusGain);
}

การปิดเสียงกลุ่มระดับเสียง

Android 12 ได้เปิดตัวการปิดเสียงกลุ่มระดับเสียงเพื่อให้ควบคุมการปิดเสียงได้ครอบคลุมมากขึ้นระหว่างที่ผู้ใช้โต้ตอบกับเสียง ซึ่งจะช่วยให้ HAL การควบคุมเสียงรับเหตุการณ์การปิดเสียงได้ตามที่บริการเสียงของรถยนต์ขัดจังหวะ

หากต้องการเปิดใช้ฟีเจอร์นี้ OEM ต้องตั้งค่า audioUseCarVolumeGroupMuting config เป็น true ในบริการรถยนต์ config.xml

<!-- Configuration to enable muting of individual volume groups.
If this is set to false, muting of individual volume groups is disabled,
instead muting will toggle master mute. If this is set to true, car volume
group muting is enabled and each individual volume group can be muted separately. -->
<bool name="audioUseCarVolumeGroupMuting">true</bool>

ก่อน Android 13 คุณต้องเขียนทับการกำหนดค่าด้วยการวางซ้อนทรัพยากรรันไทม์สำหรับ packages/services/Car/service/res/values/config.xml (ดูข้อมูลเพิ่มเติมได้ที่การปรับแต่งบิลด์ด้วยการวางซ้อนทรัพยากร) ตั้งแต่ Android 13 เป็นต้นไป คุณจะใช้การวางซ้อนทรัพยากรรันไทม์เพื่อเปลี่ยนค่าการกําหนดค่าได้ ดูข้อมูลเพิ่มเติมได้ที่เปลี่ยนค่าของทรัพยากรของแอปขณะรันไทม์

แอปของระบบจะระบุได้ว่าฟีเจอร์เปิดใช้อยู่หรือไม่โดยใช้ CarAudioManager#isAudioFeatureEnabled API พารามิเตอร์ที่ส่งต้องเป็นค่าคงที่ CarAudioManager.AUDIO_FEATURE_VOLUME_GROUP_MUTING เมธอดจะแสดงผล true หากฟีเจอร์เปิดใช้ในอุปกรณ์ หรือแสดงผล false หากไม่ได้เปิดใช้

นอกจากการเปิดใช้ฟีเจอร์ audioUseCarVolumeGroupMuting แล้ว AIDL HAL การควบคุมเสียงต้องใช้กลไกการปิดเสียงกลุ่มระดับเสียง ดังนี้

interface IAudioControl {
       /**
       *   Notifies HAL of changes in output devices that the HAL should apply
       *   muting to.
       *
       *   This will be called in response to changes in audio mute state for each
       *   volume group and will include a {@link MutingInfo} object per audio
       *   zone that experienced a mute state event.
       *
       *   @param mutingInfos an array of {@link MutingInfo} objects for the audio
       *   zones where audio mute state has changed.
       */
       oneway void onDevicesToMuteChange(in MutingInfo[] mutingInfos);
}

ในกรณีที่ข้อมูลการปิดเสียงมีข้อมูลการปิดเสียงที่เกี่ยวข้องสำหรับระบบเสียง ให้ทำดังนี้

parcelable MutingInfo {
       /**
       *   ID of the associated audio zone
       */
       int zoneId;
       /**
       *   List of addresses for audio output devices that should be muted.
       */
       String[] deviceAddressesToMute;
       /**
       *   List of addresses for audio output devices that were previously be
       *   muted and should now be unmuted.
       */
       String[] deviceAddressesToUnmute;
}

AAOS มีกลไกการปิดเสียง 2 แบบ โดยอิงตามปัจจัยต่อไปนี้

  • เหตุการณ์สำคัญที่ใช้เสียง KEYCODE_VOLUME_MUTE

  • การเรียกบริการเสียงรถยนต์โดยตรงโดยใช้ API การปิดเสียงของเครื่องมือจัดการเสียงรถยนต์ CarAudioManager#setVolumeGroupMute

เมื่อเปิดใช้ กลไกทั้ง 2 รูปแบบจะทริกเกอร์การปิดเสียงการโทรไปยัง HAL การควบคุมเสียง

การลดเสียงของระบบเสียงรถยนต์

Android 12 ได้เปิดตัวการลดระดับเสียงของเสียงในรถเพื่อเพิ่มประสิทธิภาพการควบคุมการเล่นสตรีมเสียงพร้อมกัน ซึ่งช่วยให้ OEM ใช้ลักษณะการลดเสียงของตนเองตามการกำหนดค่าเสียงจริงของรถยนต์และสถานะการเล่นปัจจุบันตามที่บริการเสียงของรถยนต์กำหนด

กลไกการลดเสียงจะอิงตามการเปลี่ยนแปลงของกองโฟกัสเสียง เมื่อใดก็ตามที่มีการเปลี่ยนแปลงโฟกัส (ไม่ว่าจะเป็นคําขอโฟกัสหรือการยกเลิกโฟกัส) ระบบจะแจ้งให้ HAL การควบคุมเสียงทราบ คุณสามารถเปิดใช้การลดเสียงในรถยนต์ได้โดยใช้ Flag การกําหนดค่า audioUseHalDuckingSignals ซึ่งคล้ายกับการสนับสนุนการปิดเสียงกลุ่มระดับเสียงของรถยนต์

<!-- Configuration to enable IAudioControl#onDevicesToDuckChange API to
inform HAL when to duck. If this is set to true, the API will receive signals
indicating which output devices to duck as well as what usages are currently
holding focus. If set to false, the API will not be called. -->
<bool name="audioUseHalDuckingSignals">true</bool>

หากต้องการเปิดใช้ฟีเจอร์นี้ HAL การควบคุมเสียง AIDL ต้องใช้ตรรกะที่เกี่ยวข้องกับสัญญาณที่ได้รับจากบริการเสียงของรถยนต์ ดังนี้

interface IAudioControl {
       /**
       *   Notifies HAL of changes in output devices that the HAL should apply
       *   ducking to.
       *
       *   This will be called in response to changes in audio focus, and will
       *   include a {@link DuckingInfo} object per audio zone that experienced
       *   a change in audo focus.
       *
       *   @param duckingInfos an array of {@link DuckingInfo} objects for the
       *   audio zones where audio focus has changed.
       */
       oneway void onDevicesToDuckChange(in DuckingInfo[] duckingInfos);
}

ข้อมูลระบบเสียงที่เกี่ยวข้องอยู่ในข้อมูลการลดเสียงของเสียง

parcelable DuckingInfo {
       /**
       *   ID of the associated audio zone
       */
       int zoneId;
       /**
       *   List of addresses for audio output devices that should be ducked.
       */
       String[] deviceAddressesToDuck;
       /**
       *   List of addresses for audio output devices that were previously be
       *   ducked and should now be unducked.
       */
       String[] deviceAddressesToUnduck;
       /**
       *   List of usages currently holding focus for this audio zone.
       */
       String[] usagesHoldingFocus;
}

นอกจากข้อมูลการกำหนดค่าเสียงของรถยนต์ที่อยู่ในที่อยู่ของอุปกรณ์เพื่อเปิด/ปิดการลดเสียงแล้ว ข้อมูลการลดเสียงยังมีข้อมูลเกี่ยวกับการใช้แอตทริบิวต์เสียงที่โฟกัสอยู่ด้วย ข้อมูลนี้มีไว้เพื่อแจ้งให้ระบบเสียงทราบว่ามีการใช้แอตทริบิวต์เสียงใดอยู่

ข้อมูลนี้จําเป็นเนื่องจากในการกําหนดค่าเสียงรถยนต์ คุณสามารถกําหนดแอตทริบิวต์เสียงหลายรายการให้กับอุปกรณ์เครื่องเดียวได้ และหากไม่มีข้อมูลเพิ่มเติม ก็จะไม่ทราบว่าการใช้งานใดที่ใช้งานอยู่

HAL การควบคุมเสียง AIDL 2.0

HAL การควบคุมเสียง AIDL ได้รับการอัปเดตเป็นเวอร์ชัน 2.0 ใน Android 13 เพื่ออัปเดต API และอำนวยความสะดวกให้ฟังก์ชันการทำงานใหม่

  • โฟกัสเสียงด้วย PlaybackTrackMetadata
  • การติดต่อกลับเกี่ยวกับระดับเสียง

ข้อมูลเมตาการเล่นจะกำหนดไว้ใน android.hardware.audio.common ดังนี้

parcelable PlaybackTrackMetadata {
       AudioUsage usage = INVALID;
       AudioContentType contentType = UNKNOWN;
       float gain;
       AudioChannelLayout channelMask;
       AudioDevice sourceDevice;
       String[] tags;
}

ฟังก์ชันการทำงานอื่นๆ ทั้งหมดจากการควบคุมเสียง AIDL เวอร์ชัน 1.0 จะยังคงอยู่และใช้งานได้ ข้อยกเว้นเกี่ยวข้องกับวิธีการเปลี่ยนโฟกัสเสียงตามที่อธิบายไว้ในเกี่ยวกับวิธีการเปลี่ยนโฟกัสเสียง

โฟกัสการควบคุมเสียงด้วยข้อมูลเมตาของแทร็กการเล่น

หากต้องการแสดงข้อมูลเพิ่มเติมต่อระบบเสียงที่อยู่ด้านล่าง HAL ตอนนี้การอัปเดตจะแสดง PlaybackTrackMetadata โดยเฉพาะอย่างยิ่ง HAL การควบคุมเสียงได้รับการขยายด้วยวิธีใหม่ดังนี้

interface IAudioControl {
       /**
       *   Notifies HAL of changes in audio focus status for focuses requested
       *   or abandoned by the HAL.
       *
       *   The HAL is not required to wait for a callback of AUDIOFOCUS_GAIN
       *   before playing audio, nor is it required to stop playing audio in the
       *   event of a AUDIOFOCUS_LOSS callback is received.
       *
       *   @param playbackMetaData The output stream metadata associated with
       *    the focus request
       *   @param zoneId The identifier for the audio zone that the HAL is
       *    playing the stream in
       *   @param focusChange the AudioFocusChange that has occurred.
       */
       oneway void onAudioFocusChangeWithMetaData(
       in PlaybackTrackMetadata playbackMetaData, in int zoneId,
       in AudioFocusChange focusChange);
}

การเปลี่ยนแปลงที่คล้ายกันและเกี่ยวข้องกันจะมีผลกับ IFocusListener ดังนี้

       /**
       *   Called to indicate that the audio output stream associated with
       *   {@link android.hardware.audio.common.PlaybackTrackMetadata} is
       *   abandoning focus as playback has stopped.
       *
       *   @param playbackMetaData The output stream metadata associated with
       *    the focus request
       *   @param zoneId The identifier for the audio zone that the HAL
       *    abandoning focus
       */
       oneway void abandonAudioFocusWithMetaData(
       in PlaybackTrackMetadata playbackMetaData, in int zoneId);
       /**
       *   Called to indicate that the audio output stream associated with
       *   {@link android.hardware.audio.common.PlaybackTrackMetadata} has taken
       *   the focus as playback is starting for the corresponding stream.
       *
       *   @param playbackMetaData The output stream metadata associated with
       *    the focus request
       *   @param zoneId The identifier for the audio zone that the HAL
       *    abandoning focus
       *   @param focusGain The focus type requested.
       */
       oneway void requestAudioFocusWithMetaData(
       in PlaybackTrackMetadata playbackMetaData, in int zoneId,
       in AudioFocusChange focusGain);
}

เกี่ยวกับวิธีการเปลี่ยนโฟกัสเสียง

การดำเนินการโฟกัสด้านบนจะทำงานในลักษณะเดียวกับที่อธิบายไว้ในคำขอโฟกัสเสียงจาก HAL เฉพาะข้อมูลเมตาของแทร็กการเล่นเท่านั้นที่มีข้อมูลเพิ่มเติมพร้อมกับการใช้แอตทริบิวต์เสียง โดยทั่วไปแล้ว Android Control HAL ที่อัปเดตแล้วจะใช้วิธีการก่อนหน้าต่อไปได้ เว้นแต่ว่าจะต้องมีข้อมูลเพิ่มเติมที่ได้จากข้อมูลเมตาของแทร็กการเล่น

หากนักพัฒนา HAL ตัดสินใจไม่รองรับ IAudioControl#onAudioFocusChangeWithMetaData เมธอดควรแสดงผลลัพธ์พร้อมข้อผิดพลาด UNKNOWN_TRANSACTION ตามที่อธิบายไว้ในการใช้เมธอดอินเทอร์เฟซเวอร์ชัน

บริการเสียงจะเรียกใช้ onAudioFocusChangeWithMetaData ก่อน แล้วจึงลองอีกครั้งด้วยเมธอด onAudioFocusChange หากเกิดUNKNOWN_TRANSACTIONข้อผิดพลาด

การลดเสียงของเสียงในรถด้วยข้อมูลเมตาของแทร็กการเล่น

HAL การควบคุมเสียง AIDL เวอร์ชัน 2.0 ได้เพิ่มข้อมูลเมตาของแทร็กการเล่นลงในข้อมูลการลดเสียง

parcelable DuckingInfo {
       /**
       *   ID of the associated audio zone
       */
       int zoneId;
       /**
       *   List of addresses for audio output devices that should be ducked.
       */
       String[] deviceAddressesToDuck;
       /**
       *   List of addresses for audio output devices that were previously be
       *   ducked and should now be unducked.
       */
       String[] deviceAddressesToUnduck;
       /**
       *   List of usages currently holding focus for this audio zone.
       */
       String[] usagesHoldingFocus;
       /**
       *   List of output stream metadata associated with the current focus
       *   holder for this audio zone
       */
       @nullable PlaybackTrackMetadata[] playbackMetaDataHoldingFocus;
}

usagesHoldingFocus เลิกใช้งานแล้ว ตอนนี้นักพัฒนาแอปควรใช้ playbackMetaDataHoldingFocus เพื่อกำหนดการใช้งานแอตทริบิวต์เสียงและข้อมูลเสียงอื่นๆ อย่างไรก็ตาม พารามิเตอร์ usagesHoldingFocus จะยังคงมีข้อมูลที่จําเป็นจนกว่าตัวเลือกนี้จะนําออกอย่างเป็นทางการ

การติดต่อกลับเกี่ยวกับระดับการขยายเสียง

เราได้เพิ่มกลไกที่คุณสามารถใช้เพื่อสื่อสารการเปลี่ยนแปลงระดับเสียงจากระบบเสียงของรถยนต์ไปยังบริการเสียงของรถยนต์เพื่อให้ AAOS ใน Android 13 เห็นการเปลี่ยนแปลงเสียงด้านล่าง HAL มากขึ้น กลไกนี้จะแสดงการเปลี่ยนแปลงดัชนีระดับเสียงของอัตราขยายเสียงพร้อมเหตุผลที่เกี่ยวข้องว่าเหตุใดจึงมีการเปลี่ยนแปลงอัตราขยายเสียง

  • ข้อจำกัดที่ถูกบล็อกหรือปิดเสียง
  • ข้อจำกัดเกี่ยวกับข้อจำกัด
  • ข้อจำกัดการลดทอน

การเปลี่ยนแปลงเหล่านี้จะแสดงข้อจำกัดเหล่านี้จากด้านล่าง HAL ไปยังบริการเสียงรถยนต์ และสุดท้ายไปยังแอป UI ของระบบเพื่อแจ้งให้ผู้ใช้ทราบ ส่วนหลังซึ่งเกี่ยวข้องกับการแสดง UI ของระบบที่เป็นไปได้ได้รับการขยายเพิ่มเติมใน Android 14 เพื่อให้แอป UI ของระบบได้รับข้อมูลนี้ได้ง่ายขึ้นผ่านกลไกการเรียกกลับข้อมูลกลุ่มระดับเสียง

HAL API การควบคุมเสียงจะลงทะเบียนการเรียกกลับของอัตราขยายเสียงดังนี้

interface IAudioControl {
       /**
       *   Registers callback to be used by HAL for reporting unexpected gain(s)
       *    changed and the reason(s) why.
       *
       *   @param callback The {@link IAudioGainCallback}.
       */
       oneway void registerGainCallback(in IAudioGainCallback callback);
}

IAudioGainCallback ได้รับการกําหนดดังนี้

interface IAudioGainCallback {
       /**
       *   Used to indicate that one or more audio device port gains have changed,
       *   i.e. initiated by HAL, not by CarAudioService.
       *   This is the counter part of the
       *   {@link onDevicesToDuckChange}, {@link onDevicesToMuteChange} and,
       *   {@link setAudioDeviceGainsChanged} APIs.
       *
       *   @param reasons List of reasons that triggered the given gains changed.
       *   @param gains List of gains affected by the change.
       */
       void onAudioDeviceGainsChanged(in Reasons[] reasons,
       in AudioGainConfigInfo[] gains);
}

ตามที่ไฮไลต์ไว้ในเอกสารประกอบของ API บริการเสียงรถยนต์จะลงทะเบียนการเรียกกลับของอัตราขยายไปยัง HAL การควบคุมเสียง เมื่อมีการเรียก API จาก HAL การควบคุมเสียง บริการเสียงของรถยนต์จะตอบสนองด้วยการดําเนินการที่เกี่ยวข้อง (เช่น บล็อก จํากัด หรือลดดัชนีการขยายสัญญาณ)

HAL จะกำหนดเวลาเรียกใช้ API โดยหลักๆ เพื่อรายงานการเปลี่ยนแปลงสถานะดัชนีการได้ผู้ใช้ สำหรับข้อกำหนดด้านกฎระเบียบโดยเฉพาะ ระบบเสียงของรถยนต์ควรดำเนินการที่จำเป็นและใช้การเรียกกลับเพื่อรายงานข้อมูลไปยังบริการเสียงของรถยนต์เพื่อให้ผู้ใช้ใช้งานได้ เช่น เพื่อแสดง UI ต่อผู้ใช้

HAL การควบคุมเสียง AIDL 3.0

HAL การควบคุมเสียง AIDL ของ Android 14 ได้รับการอัปเดตเป็นเวอร์ชัน 3.0 เพื่ออัปเดต API ให้ฟังก์ชันการระบุดัชนีอัตราขยายเสียงมีประสิทธิภาพมากขึ้น HAL API การควบคุมเสียงช่วยให้บริการเสียงสามารถตั้งค่าและยกเลิกการตั้งค่า IModuleChangeCallback ดังนี้

interface IAudioControl {
       /**
       *   Sets callback with HAL for notifying changes to hardware module
       *   (that is: {@link android.hardware.audio.core.IModule}) configurations.
       *
       *   @param callback The {@link IModuleChangeCallback} interface to use
       *    use when new updates are available for
       */
       void setModuleChangeCallback(in IModuleChangeCallback callback);
       /**
       *   Clears module change callback
       */
       void clearModuleChangeCallback();
}

setModuleChangeCallback ได้รับการลงทะเบียนโดยบริการเสียงรถยนต์เมื่อบริการเริ่มขึ้นหรือเมื่อกู้คืนจากข้อผิดพลาด เช่น การแจ้งเตือนการตายของ Binder HAL ที่บริการเสียงของรถยนต์ได้รับ การใช้งาน HAL การควบคุมเสียงควรแทนที่การเรียกกลับการเปลี่ยนแปลงของโมดูลที่มีอยู่เมื่อมีการเรียก API

สําหรับ clearModuleChangeCallback API การติดตั้งใช้งานควรล้างการเรียกกลับที่มีอยู่ หรือไม่ต้องดําเนินการใดๆ หากไม่มี แนวทางปฏิบัติแนะนำสำหรับการใช้งานการควบคุมเสียงคือการลงทะเบียนเครื่องมือตรวจสอบการสิ้นสุดของการทำงานสำหรับคอลแบ็ก จากนั้นล้างคอลแบ็กหากมีการเรียกเหตุการณ์ on binder death

IModuleChangeCallback มีคำจำกัดความดังนี้

oneway interface IModuleChangeCallback {
       /**
       *   Used to indicate that one or more {@link AudioPort} configs have
       *   changed. Implementations MUST return at least one AudioPort.
       *
       *   @param audioPorts list of {@link AudioPort} that are updated
       */
       void onAudioPortsChanged(in AudioPort[] audioPorts);
}

เมื่อบริการเสียงรถยนต์ลงทะเบียนการเรียกกลับการเปลี่ยนแปลงของโมดูลแล้ว บริการดังกล่าวจะพร้อมรับการเปลี่ยนแปลงพอร์ตเสียงผ่าน onAudioPortChanged API คุณสามารถใช้ API เพื่อเริ่มต้นการเพิ่มระดับเสียงสำหรับระบบเสียงได้ทันทีที่ลงทะเบียนการเรียกกลับ สําหรับการเปลี่ยนแปลงอัตราขยายแบบไดนามิกอื่นๆ คุณสามารถเรียกใช้ API ได้ทุกเมื่อ ระบบจะใช้การเปลี่ยนแปลงที่เกี่ยวข้องและอัปเดตบริการเสียงรถยนต์ตามนั้น