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.health.HealthFitnessStatsLog; 25 26 import java.lang.annotation.Retention; 27 import java.lang.annotation.RetentionPolicy; 28 import java.util.Objects; 29 30 /** 31 * Class to log metrics for ExerciseRoutes 32 * 33 * @hide 34 */ 35 public class ExerciseRoutesLogger { 36 37 /** 38 * Operations to supported by ExerciseRoutes logging 39 * 40 * @hide 41 */ 42 public static final class Operations { 43 public static final int UPSERT = EXERCISE_ROUTE_API_CALLED__OPERATION__OPERATION_UPSERT; 44 public static final int READ = EXERCISE_ROUTE_API_CALLED__OPERATION__OPERATION_READ; 45 46 @IntDef({UPSERT, READ}) 47 @Retention(RetentionPolicy.SOURCE) 48 public @interface Operation {} 49 } 50 51 /** 52 * Log exercise route metrics 53 * 54 * @param statsLog the log to write to 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( HealthFitnessStatsLog statsLog, @Operations.Operation int operation, String packageName, int numberOfRecordsWithExerciseRoutes)59 public static void log( 60 HealthFitnessStatsLog statsLog, 61 @Operations.Operation int operation, 62 String packageName, 63 int numberOfRecordsWithExerciseRoutes) { 64 Objects.requireNonNull(packageName); 65 66 if (numberOfRecordsWithExerciseRoutes == 0) { 67 return; 68 } 69 70 statsLog.write( 71 EXERCISE_ROUTE_API_CALLED, 72 operation, 73 packageName, 74 numberOfRecordsWithExerciseRoutes); 75 } 76 } 77