• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 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 
17 package com.android.car.hal.property;
18 
19 import static com.android.car.internal.ExcludeFromCodeCoverageGeneratedReport.PRIVATE_CONSTRUCTOR;
20 
21 import android.hardware.automotive.vehicle.EnumForVehicleProperty;
22 
23 import com.android.car.internal.ExcludeFromCodeCoverageGeneratedReport;
24 import com.android.car.internal.util.ConstantDebugUtils;
25 
26 /**
27  * Utility class for converting HAL values to readable names.
28  */
29 public final class HalValueDebugUtils {
30     /**
31      * HalValueDebugUtils only contains static fields and methods and must never be
32      * instantiated.
33      */
34     @ExcludeFromCodeCoverageGeneratedReport(reason = PRIVATE_CONSTRUCTOR)
HalValueDebugUtils()35     private HalValueDebugUtils() {
36         throw new UnsupportedOperationException("Must never be called");
37     }
38 
39     /**
40      * Gets a user-friendly string representation of a {@code value} for the given
41      * {@code propertyId}.
42      */
toDebugString(int propertyId, Object value)43     public static String toDebugString(int propertyId, Object value) {
44         if (value instanceof Integer && EnumForVehicleProperty.values.containsKey(propertyId)) {
45             for (int i = 0; i < EnumForVehicleProperty.values.get(propertyId).size(); i++) {
46                 Class<?> enumClazz = EnumForVehicleProperty.values.get(propertyId).get(i);
47                 String valueName = ConstantDebugUtils.toName(enumClazz,
48                         ((Integer) value).intValue());
49                 if (valueName != null) {
50                     return valueName;
51                 }
52             }
53         }
54         return value.toString();
55     }
56 }
57