2 * Copyright (c) 2016, The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #define LOG_TAG "Netd"
19 #include <android-base/stringprintf.h>
20 #include <cutils/log.h>
21 #include <utils/Errors.h>
23 #include <binder/IPCThreadState.h>
24 #include <binder/IServiceManager.h>
25 #include "android/net/BnNetd.h"
27 #include "NetdConstants.h"
28 #include "NetdNativeService.h"
30 using android::base::StringPrintf;
37 const char CONNECTIVITY_INTERNAL[] = "android.permission.CONNECTIVITY_INTERNAL";
39 binder::Status checkPermission(const char *permission) {
43 if (checkCallingPermission(String16(permission), (int32_t *) &pid, (int32_t *) &uid)) {
44 return binder::Status::ok();
46 auto err = StringPrintf("UID %d / PID %d lacks permission %s", uid, pid, permission);
47 return binder::Status::fromExceptionCode(binder::Status::EX_SECURITY, String8(err.c_str()));
51 #define ENFORCE_PERMISSION(permission) { \
52 binder::Status status = checkPermission((permission)); \
53 if (!status.isOk()) { \
58 #define NETD_LOCKING_RPC(permission) \
59 ENFORCE_PERMISSION(permission); \
60 android::RWLock::AutoWLock lock(gBigNetdLock);
65 binder::Status NetdNativeService::isAlive(bool *alive) {
66 NETD_LOCKING_RPC(CONNECTIVITY_INTERNAL);
69 return binder::Status::ok();
73 } // namespace android