blob: 6fd35758677be76bf8a7bfd6eab7118eb7661b8f [file] [log] [blame]
paulhuc8a58ff2022-02-09 18:37:27 +08001/**
2 * Copyright (c) 2022, The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#define LOG_TAG "MDnsService"
18
19#include "MDnsService.h"
20
21#include "binder_utils/BinderUtil.h"
22#include "binder_utils/NetdPermissions.h"
23
24#include <android-base/strings.h>
25#include <binder/Status.h>
26
27#include <string>
28#include <vector>
29
30using android::net::mdns::aidl::DiscoveryInfo;
31using android::net::mdns::aidl::GetAddressInfo;
32using android::net::mdns::aidl::IMDnsEventListener;
33using android::net::mdns::aidl::RegistrationInfo;
34using android::net::mdns::aidl::ResolutionInfo;
35
36namespace android::net {
37
38// TODO: DnsResolver has same macro definition but returns ScopedAStatus. Move these macros to
39// BinderUtil.h to do the same permission check.
40#define ENFORCE_ANY_PERMISSION(...) \
41 do { \
42 binder::Status status = checkAnyPermission({__VA_ARGS__}); \
43 if (!status.isOk()) { \
44 return status; \
45 } \
46 } while (0)
47
48#define ENFORCE_NETWORK_STACK_PERMISSIONS() \
49 ENFORCE_ANY_PERMISSION(PERM_NETWORK_STACK, PERM_MAINLINE_NETWORK_STACK)
50
51status_t MDnsService::start() {
52 IPCThreadState::self()->disableBackgroundScheduling(true);
53 const status_t ret = BinderService<MDnsService>::publish();
54 if (ret != android::OK) {
55 return ret;
56 }
57 return android::OK;
58}
59
60binder::Status MDnsService::startDaemon() {
61 ENFORCE_NETWORK_STACK_PERMISSIONS();
62 // default no-op
63 return binder::Status::ok();
64}
65
66binder::Status MDnsService::stopDaemon() {
67 ENFORCE_NETWORK_STACK_PERMISSIONS();
68 // default no-op
69 return binder::Status::ok();
70}
71
72binder::Status MDnsService::registerService(const RegistrationInfo& /*info*/) {
73 ENFORCE_NETWORK_STACK_PERMISSIONS();
74 // default no-op
75 return binder::Status::ok();
76}
77
78binder::Status MDnsService::discover(const DiscoveryInfo& /*info*/) {
79 ENFORCE_NETWORK_STACK_PERMISSIONS();
80 // default no-op
81 return binder::Status::ok();
82}
83
84binder::Status MDnsService::resolve(const ResolutionInfo& /*info*/) {
85 ENFORCE_NETWORK_STACK_PERMISSIONS();
86 // default no-op
87 return binder::Status::ok();
88}
89
90binder::Status MDnsService::getServiceAddress(const GetAddressInfo& /*info*/) {
91 ENFORCE_NETWORK_STACK_PERMISSIONS();
92 // default no-op
93 return binder::Status::ok();
94}
95
96binder::Status MDnsService::stopOperation(int32_t /*id*/) {
97 ENFORCE_NETWORK_STACK_PERMISSIONS();
98 // default no-op
99 return binder::Status::ok();
100}
101
102binder::Status MDnsService::registerEventListener(
103 const android::sp<IMDnsEventListener>& /*listener*/) {
104 ENFORCE_NETWORK_STACK_PERMISSIONS();
105 // default no-op
106 return binder::Status::ok();
107}
108
109binder::Status MDnsService::unregisterEventListener(
110 const android::sp<IMDnsEventListener>& /*listener*/) {
111 ENFORCE_NETWORK_STACK_PERMISSIONS();
112 // default no-op
113 return binder::Status::ok();
114}
115
116} // namespace android::net