OSDN Git Service

Move UidRange aidl to create a native cpp version
authorRobin Lee <rgl@google.com>
Wed, 30 Mar 2016 17:33:07 +0000 (18:33 +0100)
committerRobin Lee <rgl@google.com>
Mon, 18 Apr 2016 14:59:26 +0000 (15:59 +0100)
Moved from:
    //frameworks/base/core/java/android/net/
To:
    //system/netd/binder

Since frameworks/base depends on netd but not vice versa, it is cleaner
to keep the internal aidl in the same place as the native implementation
in netd.

Bug: 26694104
Change-Id: If21a72978ad5b93f0eed04c75143b55157c1a014

server/Android.mk
server/NetdNativeService.h
server/UidRanges.h
server/binder/android/net/UidRange.aidl [new file with mode: 0644]
server/binder/android/net/UidRange.cpp [new file with mode: 0644]
server/binder/android/net/UidRange.h [new file with mode: 0644]

index b028440..71a1087 100644 (file)
@@ -25,8 +25,12 @@ LOCAL_MODULE := libnetdaidl
 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)
 
@@ -126,7 +130,7 @@ include $(BUILD_EXECUTABLE)
 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 \
index f7409d8..57bb72b 100644 (file)
@@ -22,6 +22,7 @@
 #include <binder/BinderService.h>
 
 #include "android/net/BnNetd.h"
+#include "android/net/UidRange.h"
 
 namespace android {
 namespace net {
index 2a39953..1c40a5b 100644 (file)
@@ -17,6 +17,8 @@
 #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>
diff --git a/server/binder/android/net/UidRange.aidl b/server/binder/android/net/UidRange.aidl
new file mode 100644 (file)
index 0000000..55747d0
--- /dev/null
@@ -0,0 +1,24 @@
+/*
+ * 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";
diff --git a/server/binder/android/net/UidRange.cpp b/server/binder/android/net/UidRange.cpp
new file mode 100644 (file)
index 0000000..23774bf
--- /dev/null
@@ -0,0 +1,94 @@
+/*
+ * 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
diff --git a/server/binder/android/net/UidRange.h b/server/binder/android/net/UidRange.h
new file mode 100644 (file)
index 0000000..893dc30
--- /dev/null
@@ -0,0 +1,72 @@
+/*
+ * 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