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.server.healthconnect.logging; 18 19 import android.health.HealthFitnessStatsLog; 20 import android.util.Slog; 21 22 import com.android.server.healthconnect.storage.datatypehelpers.DatabaseStatsCollector; 23 24 /** 25 * Class to log Health Connect metrics logged every 24hrs. 26 * 27 * @hide 28 */ 29 public class DailyLoggingService { 30 31 private static final String HEALTH_CONNECT_DAILY_LOGGING_SERVICE = 32 "HealthConnectDailyLoggingService"; 33 34 /** Log daily metrics. */ logDailyMetrics( UsageStatsCollector usageStatsCollector, DatabaseStatsCollector databaseStatsCollector, EcosystemStatsCollector ecosystemStatsCollector, HealthFitnessStatsLog statsLog)35 public static void logDailyMetrics( 36 UsageStatsCollector usageStatsCollector, 37 DatabaseStatsCollector databaseStatsCollector, 38 EcosystemStatsCollector ecosystemStatsCollector, 39 HealthFitnessStatsLog statsLog) { 40 UsageStatsLogger usageStatsLogger = new UsageStatsLogger(statsLog); 41 DatabaseStatsLogger databaseStatsLogger = new DatabaseStatsLogger(statsLog); 42 EcosystemStatsLogger ecosystemStatsLogger = new EcosystemStatsLogger(statsLog); 43 logDatabaseStats(databaseStatsCollector, usageStatsCollector, databaseStatsLogger); 44 logUsageStats(usageStatsCollector, usageStatsLogger); 45 logEcosystemStats(ecosystemStatsCollector, ecosystemStatsLogger); 46 } 47 logDatabaseStats( DatabaseStatsCollector databaseStatsCollector, UsageStatsCollector usageStatsCollector, DatabaseStatsLogger databaseStatsLogger)48 private static void logDatabaseStats( 49 DatabaseStatsCollector databaseStatsCollector, 50 UsageStatsCollector usageStatsCollector, 51 DatabaseStatsLogger databaseStatsLogger) { 52 try { 53 databaseStatsLogger.log(databaseStatsCollector, usageStatsCollector); 54 } catch (Exception exception) { 55 Slog.e(HEALTH_CONNECT_DAILY_LOGGING_SERVICE, "Failed to log database stats", exception); 56 } 57 } 58 logUsageStats( UsageStatsCollector usageStatsCollector, UsageStatsLogger usageStatsLogger)59 private static void logUsageStats( 60 UsageStatsCollector usageStatsCollector, UsageStatsLogger usageStatsLogger) { 61 try { 62 usageStatsLogger.log(usageStatsCollector); 63 } catch (Exception exception) { 64 Slog.e(HEALTH_CONNECT_DAILY_LOGGING_SERVICE, "Failed to log usage stats", exception); 65 } 66 } 67 logEcosystemStats( EcosystemStatsCollector ecosystemStatsCollector, EcosystemStatsLogger ecosystemStatsLogger)68 private static void logEcosystemStats( 69 EcosystemStatsCollector ecosystemStatsCollector, 70 EcosystemStatsLogger ecosystemStatsLogger) { 71 try { 72 ecosystemStatsLogger.log(ecosystemStatsCollector); 73 } catch (Exception exception) { 74 Slog.e( 75 HEALTH_CONNECT_DAILY_LOGGING_SERVICE, 76 "Failed to log ecosystem stats", 77 exception); 78 } 79 } 80 } 81