Tony Huang | 9ac5e6e | 2023-08-24 09:01:44 +0000 | [diff] [blame] | 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 { |
| 21 | void SmallAreaDetectionAllowMappings::update( |
Tony Huang | f362110 | 2023-09-04 17:14:22 +0800 | [diff] [blame] | 22 | std::vector<std::pair<int32_t, float>>& appIdThresholdMappings) { |
Tony Huang | 9ac5e6e | 2023-08-24 09:01:44 +0000 | [diff] [blame] | 23 | std::lock_guard lock(mLock); |
| 24 | mMap.clear(); |
Tony Huang | f362110 | 2023-09-04 17:14:22 +0800 | [diff] [blame] | 25 | for (std::pair<int32_t, float> row : appIdThresholdMappings) { |
Tony Huang | 9ac5e6e | 2023-08-24 09:01:44 +0000 | [diff] [blame] | 26 | if (!isValidThreshold(row.second)) continue; |
| 27 | |
| 28 | mMap.emplace(row.first, row.second); |
| 29 | } |
| 30 | } |
| 31 | |
Jerry Chang | 3667800 | 2023-11-29 16:56:17 +0000 | [diff] [blame] | 32 | void SmallAreaDetectionAllowMappings::setThresholdForAppId(int32_t appId, float threshold) { |
Tony Huang | 9ac5e6e | 2023-08-24 09:01:44 +0000 | [diff] [blame] | 33 | if (!isValidThreshold(threshold)) return; |
| 34 | |
| 35 | std::lock_guard lock(mLock); |
Tony Huang | f362110 | 2023-09-04 17:14:22 +0800 | [diff] [blame] | 36 | mMap.emplace(appId, threshold); |
Tony Huang | 9ac5e6e | 2023-08-24 09:01:44 +0000 | [diff] [blame] | 37 | } |
| 38 | |
Tony Huang | f362110 | 2023-09-04 17:14:22 +0800 | [diff] [blame] | 39 | std::optional<float> SmallAreaDetectionAllowMappings::getThresholdForAppId(int32_t appId) { |
Tony Huang | 9ac5e6e | 2023-08-24 09:01:44 +0000 | [diff] [blame] | 40 | std::lock_guard lock(mLock); |
Tony Huang | f362110 | 2023-09-04 17:14:22 +0800 | [diff] [blame] | 41 | const auto iter = mMap.find(appId); |
Tony Huang | 9ac5e6e | 2023-08-24 09:01:44 +0000 | [diff] [blame] | 42 | if (iter != mMap.end()) { |
| 43 | return iter->second; |
| 44 | } |
| 45 | return std::nullopt; |
| 46 | } |
| 47 | } // namespace android::scheduler |