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.server.healthconnect.logging;
18 
19 import static android.health.HealthFitnessStatsLog.EXERCISE_ROUTE_API_CALLED;
20 import static android.health.HealthFitnessStatsLog.EXERCISE_ROUTE_API_CALLED__OPERATION__OPERATION_READ;
21 import static android.health.HealthFitnessStatsLog.EXERCISE_ROUTE_API_CALLED__OPERATION__OPERATION_UPSERT;
22 
23 import android.annotation.IntDef;
24 import android.annotation.NonNull;
25 import android.health.HealthFitnessStatsLog;
26 
27 import java.lang.annotation.Retention;
28 import java.lang.annotation.RetentionPolicy;
29 import java.util.Objects;
30 
31 /**
32  * Class to log metrics for ExerciseRoutes
33  *
34  * @hide
35  */
36 public class ExerciseRoutesLogger {
37 
38     /**
39      * Operations to supported by ExerciseRoutes logging
40      *
41      * @hide
42      */
43     public static final class Operations {
44         public static final int UPSERT = EXERCISE_ROUTE_API_CALLED__OPERATION__OPERATION_UPSERT;
45         public static final int READ = EXERCISE_ROUTE_API_CALLED__OPERATION__OPERATION_READ;
46 
47         @IntDef({UPSERT, READ})
48         @Retention(RetentionPolicy.SOURCE)
49         public @interface Operation {}
50     }
51 
52     /**
53      * Log exercise route metrics
54      *
55      * @param operation Operation being done on the record
56      * @param packageName Package name of the caller
57      * @param numberOfRecordsWithExerciseRoutes Number of records with Exercise Routes
58      */
log( @perations.Operation int operation, @NonNull String packageName, int numberOfRecordsWithExerciseRoutes)59     public static void log(
60             @Operations.Operation int operation,
61             @NonNull String packageName,
62             int numberOfRecordsWithExerciseRoutes) {
63         Objects.requireNonNull(packageName);
64 
65         if (numberOfRecordsWithExerciseRoutes == 0) {
66             return;
67         }
68 
69         HealthFitnessStatsLog.write(
70                 EXERCISE_ROUTE_API_CALLED,
71                 operation,
72                 packageName,
73                 numberOfRecordsWithExerciseRoutes);
74     }
75 }
76