diff options
Diffstat (limited to 'src/android/otdaemon_server.cpp')
-rw-r--r-- | src/android/otdaemon_server.cpp | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/android/otdaemon_server.cpp b/src/android/otdaemon_server.cpp index cf67016d..8eb23846 100644 --- a/src/android/otdaemon_server.cpp +++ b/src/android/otdaemon_server.cpp @@ -38,10 +38,12 @@ #include <android/binder_process.h> #include <openthread/border_router.h> #include <openthread/ip6.h> +#include <openthread/link.h> #include <openthread/openthread-system.h> #include <openthread/platform/infra_if.h> #include "agent/vendor.hpp" +#include "android/otdaemon_telemetry.hpp" #include "common/code_utils.hpp" #define BYTE_ARR_END(arr) ((arr) + sizeof(arr)) @@ -117,6 +119,8 @@ void OtDaemonServer::Init(void) otIp6SetReceiveCallback(GetOtInstance(), OtDaemonServer::ReceiveCallback, this); otBackboneRouterSetMulticastListenerCallback(GetOtInstance(), OtDaemonServer::HandleBackboneMulticastListenerEvent, this); + + mTaskRunner.Post(kTelemetryCheckInterval, [this]() { PushTelemetryIfConditionMatch(); }); } void OtDaemonServer::BinderDeathCallback(void *aBinderServer) @@ -575,6 +579,27 @@ void OtDaemonServer::SendMgmtPendingSetCallback(otError aResult, void *aBinderSe } } +Status OtDaemonServer::setCountryCode(const std::string &aCountryCode, + const std::shared_ptr<IOtStatusReceiver> &aReceiver) +{ + static constexpr int kCountryCodeLength = 2; + otError error = OT_ERROR_NONE; + std::string message; + uint16_t countryCode; + + VerifyOrExit((aCountryCode.length() == kCountryCodeLength) && isalpha(aCountryCode[0]) && isalpha(aCountryCode[1]), + error = OT_ERROR_INVALID_ARGS, message = "The country code is invalid"); + + otbrLogInfo("Set country code: %c%c", aCountryCode[0], aCountryCode[1]); + VerifyOrExit(GetOtInstance() != nullptr, error = OT_ERROR_INVALID_STATE, message = "OT is not initialized"); + countryCode = (static_cast<uint16_t>(aCountryCode[0]) << 8) | aCountryCode[1]; + SuccessOrExit(error = otLinkSetRegion(GetOtInstance(), countryCode), message = "Failed to set the country code"); + +exit: + PropagateResult(error, message, aReceiver); + return Status::ok(); +} + Status OtDaemonServer::configureBorderRouter(const BorderRouterConfigurationParcel &aBorderRouterConfiguration, const std::shared_ptr<IOtStatusReceiver> &aReceiver) { @@ -630,5 +655,18 @@ binder_status_t OtDaemonServer::dump(int aFd, const char **aArgs, uint32_t aNumA return STATUS_OK; } + +void OtDaemonServer::PushTelemetryIfConditionMatch() +{ + VerifyOrExit(GetOtInstance() != nullptr); + + // TODO: Push telemetry per kTelemetryUploadIntervalThreshold instead of on startup. + // TODO: Save unpushed telemetries in local cache to avoid data loss. + RetrieveAndPushAtoms(GetOtInstance()); + mTaskRunner.Post(kTelemetryUploadIntervalThreshold, [this]() { PushTelemetryIfConditionMatch(); }); + +exit: + return; +} } // namespace Android } // namespace otbr |