LOCAL_SHARED_LIBRARIES := \
libbinder \
libutils
+LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/binder
LOCAL_AIDL_INCLUDES := $(LOCAL_PATH)/binder
-LOCAL_SRC_FILES := binder/android/net/INetd.aidl
+LOCAL_C_INCLUDES := $(LOCAL_PATH)/binder
+LOCAL_SRC_FILES := \
+ binder/android/net/INetd.aidl \
+ binder/android/net/UidRange.cpp
include $(BUILD_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := netd_unit_test
LOCAL_CFLAGS := -Wall -Werror -Wunused-parameter
-LOCAL_C_INCLUDES := system/netd/server system/core/logwrapper/include
+LOCAL_C_INCLUDES := system/netd/server system/netd/server/binder system/core/logwrapper/include
LOCAL_SRC_FILES := \
NetdConstants.cpp IptablesBaseTest.cpp \
BandwidthController.cpp BandwidthControllerTest.cpp \
#include <binder/BinderService.h>
#include "android/net/BnNetd.h"
+#include "android/net/UidRange.h"
namespace android {
namespace net {
#ifndef NETD_SERVER_UID_RANGES_H
#define NETD_SERVER_UID_RANGES_H
+#include "android/net/UidRange.h"
+
#include <sys/types.h>
#include <utility>
#include <vector>
--- /dev/null
+/*
+ * 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.
+ */
+
+package android.net;
+
+/**
+ * An inclusive range of UIDs.
+ *
+ * {@hide}
+ */
+parcelable UidRange cpp_header "binder/android/net/UidRange.h";
--- /dev/null
+/*
+ * 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.
+ */
+
+#include "android/net/UidRange.h"
+
+#define LOG_TAG "UidRange"
+
+#include <binder/IBinder.h>
+#include <binder/Parcel.h>
+#include <log/log.h>
+#include <utils/Errors.h>
+
+using android::BAD_VALUE;
+using android::NO_ERROR;
+using android::Parcel;
+using android::status_t;
+
+namespace android {
+
+namespace net {
+
+UidRange::UidRange(int32_t start, int32_t stop) {
+ ALOG_ASSERT(start <= stop, "start UID must be less than or equal to stop UID");
+ mStart = start;
+ mStop = stop;
+}
+
+status_t UidRange::writeToParcel(Parcel* parcel) const {
+ /*
+ * Keep implementation in sync with writeToParcel() in
+ * frameworks/base/core/java/android/net/UidRange.java.
+ */
+ if (status_t err = parcel->writeInt32(mStart)) {
+ return err;
+ }
+ if (status_t err = parcel->writeInt32(mStop)) {
+ return err;
+ }
+ return NO_ERROR;
+}
+
+status_t UidRange::readFromParcel(const Parcel* parcel) {
+ /*
+ * Keep implementation in sync with readFromParcel() in
+ * frameworks/base/core/java/android/net/UidRange.java.
+ */
+ if (status_t err = parcel->readInt32(&mStart)) {
+ return err;
+ }
+ if (status_t err = parcel->readInt32(&mStop)) {
+ return err;
+ }
+ if (mStart > mStop) return BAD_VALUE;
+ return NO_ERROR;
+}
+
+void UidRange::setStart(int32_t uid) {
+ if (mStop != -1) {
+ ALOG_ASSERT(uid <= mStop, "start UID must be less than or equal to stop UID");
+ }
+ mStart = uid;
+}
+
+void UidRange::setStop(int32_t uid) {
+ if (mStart != -1) {
+ ALOG_ASSERT(uid <= mStop, "stop UID must be greater than or equal to start UID");
+ }
+ mStop = uid;
+}
+
+int32_t UidRange::getStart() const {
+ return mStart;
+}
+
+int32_t UidRange::getStop() const {
+ return mStop;
+}
+
+} // namespace net
+
+} // namespace android
--- /dev/null
+/*
+ * 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.
+ */
+
+#ifndef NETD_SERVER_ANDROID_NET_UID_RANGE_H
+#define NETD_SERVER_ANDROID_NET_UID_RANGE_H
+
+#include <binder/Parcelable.h>
+
+namespace android {
+
+namespace net {
+
+/*
+ * C++ implementation of UidRange, a contiguous range of UIDs.
+ */
+class UidRange : public Parcelable {
+public:
+ UidRange() = default;
+ virtual ~UidRange() = default;
+ UidRange(const UidRange& range) = default;
+ UidRange(int32_t start, int32_t stop);
+
+ status_t writeToParcel(Parcel* parcel) const override;
+ status_t readFromParcel(const Parcel* parcel) override;
+
+ /*
+ * Setters for UidRange start and stop UIDs.
+ */
+ void setStart(int32_t uid);
+ void setStop(int32_t uid);
+
+ /*
+ * Getters for UidRange start and stop UIDs.
+ */
+ int32_t getStart() const;
+ int32_t getStop() const;
+
+ friend bool operator<(const UidRange& lhs, const UidRange& rhs) {
+ return lhs.mStart != rhs.mStart ? (lhs.mStart < rhs.mStart) : (lhs.mStop < rhs.mStop);
+ }
+
+ friend bool operator==(const UidRange& lhs, const UidRange& rhs) {
+ return (lhs.mStart == rhs.mStart && lhs.mStop == rhs.mStop);
+ }
+
+ friend bool operator!=(const UidRange& lhs, const UidRange& rhs) {
+ return !(lhs == rhs);
+ }
+
+private:
+ int32_t mStart = -1;
+ int32_t mStop = -1;
+};
+
+} // namespace net
+
+} // namespace android
+
+#endif // NETD_SERVER_ANDROID_NET_UID_RANGE_H