avs-device-sdk/CapabilityAgents/DoNotDisturb/include/DoNotDisturbCA/DoNotDisturbCapabilityAgent.h

205 lines
8.9 KiB
C
Raw Normal View History

Version 1.11 alexa-client-sdk Changes in this update: **Enhancements** * Added support for the new Alexa [DoNotDisturb](https://developer.amazon.com/docs/alexa-voice-service/donotdisturb.html) interface, which enables users to toggle the do not disturb (DND) function on their Alexa built-in products. * The SDK now supports [Opus](https://opus-codec.org/license/) encoding, which is optional. To enable Opus, you must [set the CMake flag to `-DOPUS=ON`](https://github.com/alexa/avs-device-sdk/wiki/Build-Options#Opus-encoding), and include the [libopus library](https://github.com/alexa/avs-device-sdk/wiki/Dependencies#core-dependencies) dependency in your build. * The MediaPlayer reference implementation has been expanded to support the SAMPLE-AES and AES-128 encryption methods for HLS streaming. * AES-128 encryption is dependent on libcrypto, which is part of the required openSSL library, and is enabled by default. * To enable [SAMPLE-AES](https://github.com/alexa/avs-device-sdk/wiki/Dependencies#core-dependencies/Enable-SAMPLE-AES-decryption) encryption, you must set the `-DSAMPLE_AES=ON` in your CMake command, and include the [FFMPEG](https://github.com/alexa/avs-device-sdk/wiki/Dependencies#core-dependencies/Enable-SAMPLE-AES-decryption) library dependency in your build. * A new configuration for [deviceSettings](https://github.com/alexa/avs-device-sdk/blob/v1.11.0/Integration/AlexaClientSDKConfig.json#L59) has been added.This configuration allows you to specify the location of the device settings database. * Added locale support for es-MX. **Bug Fixes** * Fixed an issue where music wouldn't resume playback in the Android app. * Now all equalizer capabilities are fully disabled when equalizer is turned off in configuration file. Previously, devices were unconditionally required to provide support for equalizer in order to run the SDK. * [Issue 1106](https://github.com/alexa/avs-device-sdk/issues/1106) - Fixed an issue in which the `CBLAuthDelegate` wasn't using the correct timeout during request refresh. * [Issue 1128](https://github.com/alexa/avs-device-sdk/issues/1128) - Fixed an issue in which the `AudioPlayer` instance persisted at shutdown, due to a shared dependency with the `ProgressTimer`. * Fixed in issue that occurred when a connection to streaming content was interrupted, the SDK did not attempt to resume the connection, and appeared to assume that the content had been fully downloaded. This triggered the next track to be played, assuming it was a playlist. * [Issue 1040](https://github.com/alexa/avs-device-sdk/issues/1040) - Fixed an issue where alarms would continue to play after user barge-in. **Known Issues** * `PlaylistParser` and `IterativePlaylistParser` generate two HTTP requests (one to fetch the content type, and one to fetch the audio data) for each audio stream played. * Music playback history isn't being displayed in the Alexa app for certain account and device types. * On GCC 8+, issues related to `-Wclass-memaccess` will trigger warnings. However, this won't cause the build to fail, and these warnings can be ignored. * In order to use Bluetooth source and sink PulseAudio, you must manually load and unload PulseAudio modules after the SDK starts. * The `ACL` may encounter issues if audio attachments are received but not consumed. * `SpeechSynthesizerState` currently uses `GAINING_FOCUS` and `LOSING_FOCUS` as a workaround for handling intermediate state. These states may be removed in a future release. * The Alexa app doesn't always indicate when a device is successfully connected via Bluetooth. * Connecting a product to streaming media via Bluetooth will sometimes stop media playback within the source application. Resuming playback through the source application or toggling next/previous will correct playback. * When a source device is streaming silence via Bluetooth, the Alexa app indicates that audio content is streaming. * The Bluetooth agent assumes that the Bluetooth adapter is always connected to a power source. Disconnecting from a power source during operation is not yet supported. * On some products, interrupted Bluetooth playback may not resume if other content is locally streamed. * `make integration` is currently not available for Android. In order to run integration tests on Android, you'll need to manually upload the test binary file along with any input file. At that point, the adb can be used to run the integration tests. * On Raspberry Pi running Android Things with HDMI output audio, beginning of speech is truncated when Alexa responds to user TTS. * When the sample app is restarted and network connection is lost, alerts don't play. * When network connection is lost, lost connection status is not returned via local Text-to Speech (TTS).
2018-12-19 19:13:36 +00:00
/*
* Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0/
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
#ifndef ALEXA_CLIENT_SDK_CAPABILITYAGENTS_DONOTDISTURB_INCLUDE_DONOTDISTURBCA_DONOTDISTURBCAPABILITYAGENT_H_
#define ALEXA_CLIENT_SDK_CAPABILITYAGENTS_DONOTDISTURB_INCLUDE_DONOTDISTURBCA_DONOTDISTURBCAPABILITYAGENT_H_
#include <atomic>
#include <memory>
#include <mutex>
#include <rapidjson/document.h>
#include <AVSCommon/AVS/CapabilityAgent.h>
#include <AVSCommon/AVS/CapabilityConfiguration.h>
#include <AVSCommon/AVS/ExceptionErrorType.h>
#include <AVSCommon/SDKInterfaces/CapabilitiesDelegateInterface.h>
#include <AVSCommon/SDKInterfaces/CapabilityConfigurationInterface.h>
#include <AVSCommon/SDKInterfaces/ConnectionStatusObserverInterface.h>
#include <AVSCommon/SDKInterfaces/MessageSenderInterface.h>
#include <AVSCommon/Utils/RequiresShutdown.h>
#include <AVSCommon/Utils/Threading/Executor.h>
#include <RegistrationManager/CustomerDataHandler.h>
#include <RegistrationManager/CustomerDataManager.h>
#include <Settings/Storage/DeviceSettingStorageInterface.h>
#include <Settings/DeviceSettingsManager.h>
#include <Settings/SettingEventSenderInterface.h>
#include <Settings/Setting.h>
namespace alexaClientSDK {
namespace capabilityAgents {
namespace doNotDisturb {
/**
* Capability Agent to handle Alexa.DoNotDisturb AVS Interface.
*
* When DoNotDisturb mode is on AVS blocks some interactions from reaching the device so the customer won't be
* disturbed. Locally SDK provides only the way to get immediate state of the DND mode, track its changes coming from
* any source and update it making sure that it will be synchronized with AVS. No other customer experience is affected.
*/
class DoNotDisturbCapabilityAgent
: public std::enable_shared_from_this<DoNotDisturbCapabilityAgent>
, public avsCommon::avs::CapabilityAgent
, public avsCommon::sdkInterfaces::CapabilityConfigurationInterface
, public avsCommon::sdkInterfaces::ConnectionStatusObserverInterface
, public avsCommon::utils::RequiresShutdown
, public registrationManager::CustomerDataHandler
, public settings::SettingEventSenderInterface {
public:
/**
* Destructor.
*/
~DoNotDisturbCapabilityAgent() override = default;
/**
* Factory method to create a capability agent instance.
*
* @param customerDataManager Component to register Capability Agent as customer data container (equalizer state).
* @param exceptionEncounteredSender Interface to report exceptions to AVS.
* @param messageSender Interface to send events to AVS.
* @param settingsManager A settingsManager object that manages do not disturb setting.
* @param settingsStorage The storage interface that will be used to store device settings.
* @return A new instance of @c DoNotDisturbCapabilityAgent on success, @c nullptr otherwise.
*/
static std::shared_ptr<DoNotDisturbCapabilityAgent> create(
std::shared_ptr<registrationManager::CustomerDataManager> customerDataManager,
std::shared_ptr<avsCommon::sdkInterfaces::ExceptionEncounteredSenderInterface> exceptionEncounteredSender,
std::shared_ptr<avsCommon::sdkInterfaces::MessageSenderInterface> messageSender,
std::shared_ptr<settings::DeviceSettingsManager> settingsManager,
std::shared_ptr<settings::storage::DeviceSettingStorageInterface> settingsStorage);
/// @name CapabilityAgent Functions
/// @{
avsCommon::avs::DirectiveHandlerConfiguration getConfiguration() const override;
void handleDirectiveImmediately(std::shared_ptr<avsCommon::avs::AVSDirective> directive) override;
void preHandleDirective(std::shared_ptr<avsCommon::avs::CapabilityAgent::DirectiveInfo> info) override;
void handleDirective(std::shared_ptr<avsCommon::avs::CapabilityAgent::DirectiveInfo> info) override;
void cancelDirective(std::shared_ptr<avsCommon::avs::CapabilityAgent::DirectiveInfo> info) override;
/// @}
/// @name CapabilityConfigurationInterface Functions
/// @{
std::unordered_set<std::shared_ptr<avsCommon::avs::CapabilityConfiguration>> getCapabilityConfigurations() override;
/// @}
// @name RequiresShutdown Functions
/// @{
void doShutdown() override;
/// @}
/// @name CustomerDataHandler Functions
/// @{
void clearData() override;
/// @}
/// @name SettingEventSenderInterface Functions
/// @{
std::shared_future<bool> sendChangedEvent(const std::string& value) override;
std::shared_future<bool> sendReportEvent(const std::string& value) override;
/// @}
/// @name ConnectionStatusObserverInterface Functions
/// @{
void onConnectionStatusChanged(const Status status, const ChangedReason reason) override;
/// @}
private:
/**
* Constructor.
*
* @param customerDataManager Component to register Capability Agent as customer data container (equalizer state).
* @param exceptionEncounteredSender Interface to report exceptions to AVS.
* @param messageSender Interface to send events to AVS.
* @param settingsManager A settingsManager object that manages do not disturb setting.
*/
DoNotDisturbCapabilityAgent(
std::shared_ptr<registrationManager::CustomerDataManager> customerDataManager,
std::shared_ptr<avsCommon::sdkInterfaces::ExceptionEncounteredSenderInterface> exceptionEncounteredSender,
std::shared_ptr<avsCommon::sdkInterfaces::MessageSenderInterface> messageSender,
std::shared_ptr<settings::DeviceSettingsManager> settingsManager);
/**
* Method to initialize the new instance of the capability agent.
*
* @param settingsStorage The storage interface that will be used to store device settings.
* @return True on succes, false otherwise.
*/
bool initialize(std::shared_ptr<settings::storage::DeviceSettingStorageInterface> settingsStorage);
/**
* Sends a DND event to the AVS.
*
* @param eventName Name of the event to send.
* @param value Valid JSON string representation of the boolean value. I.e. either "true" or "false".
* @return Future to track the completion status of the message.
*/
std::shared_future<avsCommon::sdkInterfaces::MessageRequestObserverInterface::Status> sendDNDEvent(
const std::string& eventName,
const std::string& value);
/**
* Prepares AVS Interface DCF configuration and keeps it internally.
*/
void generateCapabilityConfiguration();
/**
* Handles the Alexa.DoNotDisturb.SetDoNotDisturb AVS Directive.
*
* @param info Directive details.
* @param JSON document containing the parsed directive payload.
* @return true if operation succeeds and could be reported as such to AVS, false if an error occurred. False
* implies that exception has been reported to AVS and directive is already processed.
*/
bool handleSetDoNotDisturbDirective(
std::shared_ptr<avsCommon::avs::CapabilityAgent::DirectiveInfo> info,
rapidjson::Document& document);
/// Set of capability configurations that will get published using DCF
std::unordered_set<std::shared_ptr<avsCommon::avs::CapabilityConfiguration>> m_capabilityConfigurations;
/// The @c MessageSenderInterface used to send event messages.
std::shared_ptr<avsCommon::sdkInterfaces::MessageSenderInterface> m_messageSender;
/// The device settings manager object.
std::shared_ptr<settings::DeviceSettingsManager> m_settingsManager;
/// The do not disturb mode setting.
std::shared_ptr<settings::Setting<bool>> m_dndModeSetting;
/// The storage interface that will be used to store device settings.
std::shared_ptr<settings::storage::DeviceSettingStorageInterface> m_settingsStorage;
/**
* Flag indicating latest reported connection status. True if SDK is connected to the AVS and ready,
* false otherwise.
*/
bool m_isConnected;
/// Mutex to synchronize operations related to connection state.
std::mutex m_connectedStateMutex;
/// Flag indicating whether there were changes made to the DND status while being offline.
std::atomic_bool m_hasOfflineChanges;
/// An executor used for serializing requests on agent's own thread of execution.
avsCommon::utils::threading::Executor m_executor;
};
} // namespace doNotDisturb
} // namespace capabilityAgents
} // namespace alexaClientSDK
#endif // ALEXA_CLIENT_SDK_CAPABILITYAGENTS_DONOTDISTURB_INCLUDE_DONOTDISTURBCA_DONOTDISTURBCAPABILITYAGENT_H_