• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 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 
17 package com.android.car.internal.property;
18 
19 import android.car.hardware.CarPropertyConfig;
20 import android.car.hardware.property.CarPropertyManager;
21 
22 /**
23  * Common utility functions used by {@link CarPropertyManager} stack to sanitize input arguments.
24  *
25  * @hide
26  */
27 public class InputSanitizationUtils {
28 
29     /**
30      * Sanitizes the {@code updateRateHz} passed to {@link
31      * CarPropertyManager#registerCallback(CarPropertyManager.CarPropertyEventCallback, int, float)}
32      * and similar functions.
33      */
sanitizeUpdateRateHz( CarPropertyConfig<?> carPropertyConfig, float updateRateHz)34     public static float sanitizeUpdateRateHz(
35             CarPropertyConfig<?> carPropertyConfig, float updateRateHz) {
36         float sanitizedUpdateRateHz = updateRateHz;
37         if (carPropertyConfig.getChangeMode()
38                 != CarPropertyConfig.VEHICLE_PROPERTY_CHANGE_MODE_CONTINUOUS) {
39             sanitizedUpdateRateHz = CarPropertyManager.SENSOR_RATE_ONCHANGE;
40         } else if (sanitizedUpdateRateHz > carPropertyConfig.getMaxSampleRate()) {
41             sanitizedUpdateRateHz = carPropertyConfig.getMaxSampleRate();
42         } else if (sanitizedUpdateRateHz < carPropertyConfig.getMinSampleRate()) {
43             sanitizedUpdateRateHz = carPropertyConfig.getMinSampleRate();
44         }
45         return sanitizedUpdateRateHz;
46     }
47 }
48