1 /* 2 * Copyright (C) 2014 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 #ifndef NETD_SERVER_UID_RANGES_H 18 #define NETD_SERVER_UID_RANGES_H 19 20 #include "android/net/INetd.h" 21 22 #include <sys/types.h> 23 #include <utility> 24 #include <vector> 25 26 namespace android { 27 namespace net { 28 29 class UidRanges { 30 public: 31 static constexpr int DEFAULT_SUB_PRIORITY = 0; 32 static constexpr int LOWEST_SUB_PRIORITY = 999; 33 UidRanges()34 UidRanges() {} 35 UidRanges(const std::vector<android::net::UidRangeParcel>& ranges); 36 37 bool hasUid(uid_t uid) const; 38 const std::vector<UidRangeParcel>& getRanges() const; 39 40 bool parseFrom(int argc, char* argv[]); 41 std::string toString() const; 42 43 void add(const UidRanges& other); 44 void remove(const UidRanges& other); 45 46 // check if 'mRanges' has uid overlap between elements. 47 bool overlapsSelf() const; 48 // check if this object has uid overlap with the input object. 49 bool overlaps(const UidRanges& other) const; empty()50 bool empty() const { return mRanges.empty(); } 51 52 private: 53 // a utility to check if two UidRangeParcels have uid overlap. 54 bool isOverlapped(const UidRangeParcel& r1, const UidRangeParcel& r2) const; 55 56 std::vector<UidRangeParcel> mRanges; 57 }; 58 59 } // namespace net 60 } // namespace android 61 62 #endif // NETD_SERVER_UID_RANGES_H 63