2 * Copyright (C) 2013 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 #include "UidMarkMap.h"
19 UidMarkMap::UidMarkEntry::UidMarkEntry(int start, int end, int new_mark) :
25 bool UidMarkMap::add(int uid_start, int uid_end, int mark) {
26 android::RWLock::AutoWLock lock(mRWLock);
27 if (uid_start > uid_end) {
30 android::netd::List<UidMarkEntry*>::iterator it;
31 for (it = mMap.begin(); it != mMap.end(); it++) {
32 UidMarkEntry *entry = *it;
33 if (entry->uid_start <= uid_end && uid_start <= entry->uid_end) {
38 UidMarkEntry *e = new UidMarkEntry(uid_start, uid_end, mark);
43 bool UidMarkMap::remove(int uid_start, int uid_end, int mark) {
44 android::RWLock::AutoWLock lock(mRWLock);
45 android::netd::List<UidMarkEntry*>::iterator it;
46 for (it = mMap.begin(); it != mMap.end(); it++) {
47 UidMarkEntry *entry = *it;
48 if (entry->uid_start == uid_start && entry->uid_end == uid_end && entry->mark == mark) {
57 int UidMarkMap::getMark(int uid) {
58 android::RWLock::AutoRLock lock(mRWLock);
59 android::netd::List<UidMarkEntry*>::iterator it;
60 for (it = mMap.begin(); it != mMap.end(); it++) {
61 UidMarkEntry *entry = *it;
62 if (entry->uid_start <= uid && entry->uid_end >= uid) {
69 bool UidMarkMap::anyRulesForMark(int mark) {
70 android::RWLock::AutoRLock lock(mRWLock);
71 android::netd::List<UidMarkEntry*>::iterator it;
72 for (it = mMap.begin(); it != mMap.end(); it++) {
73 UidMarkEntry *entry = *it;
74 if (entry->mark == mark) {