blob: f4b5a102cbc41e56648583583c99a1cac6f52586 [file] [log] [blame]
/**
* Copyright (c) 2016, The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License 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.
*/
#define LOG_TAG "Netd"
#include <android-base/stringprintf.h>
#include <cutils/log.h>
#include <utils/Errors.h>
#include <binder/IPCThreadState.h>
#include <binder/IServiceManager.h>
#include "android/net/BnNetd.h"
#include "NetdConstants.h"
#include "NetdNativeService.h"
using android::base::StringPrintf;
namespace android {
namespace net {
namespace {
const char CONNECTIVITY_INTERNAL[] = "android.permission.CONNECTIVITY_INTERNAL";
binder::Status checkPermission(const char *permission) {
pid_t pid;
uid_t uid;
if (checkCallingPermission(String16(permission), (int32_t *) &pid, (int32_t *) &uid)) {
return binder::Status::ok();
} else {
auto err = StringPrintf("UID %d / PID %d lacks permission %s", uid, pid, permission);
return binder::Status::fromExceptionCode(binder::Status::EX_SECURITY, String8(err.c_str()));
}
}
#define ENFORCE_PERMISSION(permission) { \
binder::Status status = checkPermission((permission)); \
if (!status.isOk()) { \
return status; \
} \
}
#define NETD_LOCKING_RPC(permission) \
ENFORCE_PERMISSION(permission); \
android::RWLock::AutoWLock lock(gBigNetdLock);
} // namespace
binder::Status NetdNativeService::isAlive(bool *alive) {
NETD_LOCKING_RPC(CONNECTIVITY_INTERNAL);
*alive = true;
return binder::Status::ok();
}
} // namespace net
} // namespace android