1 /* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 #include "net_settings.h" 16 17 namespace OHOS { 18 namespace NetManagerStandard { 19 static constexpr uint32_t DEFAULT_SYSTEM_UID = 456; NetSettings()20NetSettings::NetSettings() 21 { 22 AddSystemUid(DEFAULT_SYSTEM_UID); 23 } 24 ~NetSettings()25NetSettings::~NetSettings() {} 26 GetInstance()27NetSettings &NetSettings::GetInstance() 28 { 29 static NetSettings gNetSettings; 30 return gNetSettings; 31 } 32 IsUidForeground(uint32_t uid)33bool NetSettings::IsUidForeground(uint32_t uid) 34 { 35 return foregroundUid_ == uid; 36 } 37 SetForegroundUid(uint32_t uid)38void NetSettings::SetForegroundUid(uint32_t uid) 39 { 40 foregroundUid_ = uid; 41 } 42 IsSystem(uint32_t uid)43bool NetSettings::IsSystem(uint32_t uid) 44 { 45 return std::find(systemUids_.begin(), systemUids_.end(), uid) != systemUids_.end(); 46 } 47 AddSystemUid(uint32_t uid)48void NetSettings::AddSystemUid(uint32_t uid) 49 { 50 systemUids_.push_back(uid); 51 } 52 RemoveSystemUid(uint32_t uid)53void NetSettings::RemoveSystemUid(uint32_t uid) 54 { 55 if (uid == 0) { 56 systemUids_.clear(); 57 return; 58 } 59 60 for (auto it = systemUids_.begin(); it != systemUids_.end(); it++) { 61 if (*it == uid) { 62 systemUids_.erase(it); 63 return; 64 } 65 } 66 } 67 } // namespace NetManagerStandard 68 } // namespace OHOS 69