1 /*
2 * Copyright 2023 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 #include <sys/types.h>
17
18 #include "SmallAreaDetectionAllowMappings.h"
19
20 namespace android::scheduler {
update(std::vector<std::pair<int32_t,float>> & appIdThresholdMappings)21 void SmallAreaDetectionAllowMappings::update(
22 std::vector<std::pair<int32_t, float>>& appIdThresholdMappings) {
23 std::lock_guard lock(mLock);
24 mMap.clear();
25 for (std::pair<int32_t, float> row : appIdThresholdMappings) {
26 if (!isValidThreshold(row.second)) continue;
27
28 mMap.emplace(row.first, row.second);
29 }
30 }
31
setThresholdForAppId(int32_t appId,float threshold)32 void SmallAreaDetectionAllowMappings::setThresholdForAppId(int32_t appId, float threshold) {
33 if (!isValidThreshold(threshold)) return;
34
35 std::lock_guard lock(mLock);
36 mMap.emplace(appId, threshold);
37 }
38
getThresholdForAppId(int32_t appId)39 std::optional<float> SmallAreaDetectionAllowMappings::getThresholdForAppId(int32_t appId) {
40 std::lock_guard lock(mLock);
41 const auto iter = mMap.find(appId);
42 if (iter != mMap.end()) {
43 return iter->second;
44 }
45 return std::nullopt;
46 }
47 } // namespace android::scheduler
48