blob: 38c6da48f6d731ac5ad79128f5c726f2273bae4f [file] [log] [blame]
Tony Huang9ac5e6e2023-08-24 09:01:44 +00001/*
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
20namespace android::scheduler {
21void SmallAreaDetectionAllowMappings::update(
Tony Huangf3621102023-09-04 17:14:22 +080022 std::vector<std::pair<int32_t, float>>& appIdThresholdMappings) {
Tony Huang9ac5e6e2023-08-24 09:01:44 +000023 std::lock_guard lock(mLock);
24 mMap.clear();
Tony Huangf3621102023-09-04 17:14:22 +080025 for (std::pair<int32_t, float> row : appIdThresholdMappings) {
Tony Huang9ac5e6e2023-08-24 09:01:44 +000026 if (!isValidThreshold(row.second)) continue;
27
28 mMap.emplace(row.first, row.second);
29 }
30}
31
Tony Huangf3621102023-09-04 17:14:22 +080032void SmallAreaDetectionAllowMappings::setThesholdForAppId(int32_t appId, float threshold) {
Tony Huang9ac5e6e2023-08-24 09:01:44 +000033 if (!isValidThreshold(threshold)) return;
34
35 std::lock_guard lock(mLock);
Tony Huangf3621102023-09-04 17:14:22 +080036 mMap.emplace(appId, threshold);
Tony Huang9ac5e6e2023-08-24 09:01:44 +000037}
38
Tony Huangf3621102023-09-04 17:14:22 +080039std::optional<float> SmallAreaDetectionAllowMappings::getThresholdForAppId(int32_t appId) {
Tony Huang9ac5e6e2023-08-24 09:01:44 +000040 std::lock_guard lock(mLock);
Tony Huangf3621102023-09-04 17:14:22 +080041 const auto iter = mMap.find(appId);
Tony Huang9ac5e6e2023-08-24 09:01:44 +000042 if (iter != mMap.end()) {
43 return iter->second;
44 }
45 return std::nullopt;
46}
47} // namespace android::scheduler