diff options
author | Ken Chen <cken@google.com> | 2023-12-12 04:36:46 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2023-12-12 04:36:46 +0000 |
commit | 74474b0ee5c08f4fed39babc1382e48022584c3b (patch) | |
tree | 5e2b708165bf93d6436a558cc58ee3e71e0dfbc6 | |
parent | bb3fe6bb6a27c2130209e61e0e37dfec708e6b65 (diff) | |
parent | 1703a8ab74a06be98ce7c6a538479de83c42a52d (diff) | |
download | netd-74474b0ee5c08f4fed39babc1382e48022584c3b.tar.gz |
Add startDaemon and stopDaemon back in MDnsService am: b1e5977ca6 am: 1703a8ab74
Original change: https://android-review.googlesource.com/c/platform/system/netd/+/2867838
Change-Id: Idefdb25190c6aa73c60855afe77be654bf24ed67
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r-- | server/MDnsService.cpp | 49 |
1 files changed, 39 insertions, 10 deletions
diff --git a/server/MDnsService.cpp b/server/MDnsService.cpp index 0c55e7ae..68359ede 100644 --- a/server/MDnsService.cpp +++ b/server/MDnsService.cpp @@ -18,6 +18,7 @@ #include "MDnsService.h" +#include <android-base/properties.h> #include <binder/Status.h> #include <binder_utils/BinderUtil.h> @@ -27,8 +28,26 @@ using android::net::mdns::aidl::IMDnsEventListener; using android::net::mdns::aidl::RegistrationInfo; using android::net::mdns::aidl::ResolutionInfo; +using std::literals::chrono_literals::operator""s; + namespace android::net { +#define MDNS_SERVICE_NAME "mdnsd" +#define MDNS_SERVICE_STATUS "init.svc.mdnsd" + +// TODO: DnsResolver has same macro definition but returns ScopedAStatus. Move these macros to +// BinderUtil.h to do the same permission check. +#define ENFORCE_ANY_PERMISSION(...) \ + do { \ + binder::Status status = checkAnyPermission({__VA_ARGS__}); \ + if (!status.isOk()) { \ + return status; \ + } \ + } while (0) + +#define ENFORCE_NETWORK_STACK_PERMISSIONS() \ + ENFORCE_ANY_PERMISSION(PERM_NETWORK_STACK, PERM_MAINLINE_NETWORK_STACK) + status_t MDnsService::start() { IPCThreadState::self()->disableBackgroundScheduling(true); const status_t ret = BinderService<MDnsService>::publish(); @@ -39,22 +58,32 @@ status_t MDnsService::start() { } binder::Status MDnsService::startDaemon() { - // TODO(b/298594687): switch from EX_SERVICE_SPECIFIC to DEPRECATED when tethering module - // for 2024-02 release is fully rolled out and prebuilt updated in AP1A.xxxxxx.yy build. - // Return EX_SERVICE_SPECIFIC for short-term only because callers in tethering module do not - // catch the EX_UNSUPPORTED_OPERATION. It will throw an exception and cause a fatal exception. - // The EX_UNSUPPORTED_OPERATION has been catched in tethering module since 2024-02 release. - return binder::Status::fromExceptionCode(binder::Status::EX_SERVICE_SPECIFIC); - // DEPRECATED; + ENFORCE_NETWORK_STACK_PERMISSIONS(); + if (android::base::GetProperty(MDNS_SERVICE_STATUS, "") == "running") { + return binder::Status::fromExceptionCode(-EBUSY); + } + + ALOGD("Starting MDNSD"); + android::base::SetProperty("ctl.start", MDNS_SERVICE_NAME); + // To maintain the same behavior as before, the returned value is not checked. + android::base::WaitForProperty(MDNS_SERVICE_STATUS, "running", 5s); + return binder::Status::ok(); } binder::Status MDnsService::stopDaemon() { - // TODO(b/298594687): switch to DEPRECATED. - return binder::Status::fromExceptionCode(binder::Status::EX_SERVICE_SPECIFIC); - // DEPRECATED; + ENFORCE_NETWORK_STACK_PERMISSIONS(); + ALOGD("Stopping MDNSD"); + android::base::SetProperty("ctl.stop", MDNS_SERVICE_NAME); + android::base::WaitForProperty(MDNS_SERVICE_STATUS, "stopped", 5s); + return binder::Status::ok(); } binder::Status MDnsService::registerService(const RegistrationInfo&) { + // TODO(b/298594687): switch from EX_SERVICE_SPECIFIC to DEPRECATED when tethering module + // for 2024-02 release is fully rolled out and prebuilt updated in AP1A.xxxxxx.yy build. + // Return EX_SERVICE_SPECIFIC for short-term only because callers in tethering module do not + // catch the EX_UNSUPPORTED_OPERATION. It will throw an exception and cause a fatal exception. + // The EX_UNSUPPORTED_OPERATION has been catched in tethering module since 2024-02 release. // TODO(b/298594687): switch to DEPRECATED. return binder::Status::fromExceptionCode(binder::Status::EX_SERVICE_SPECIFIC); // DEPRECATED; |