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.annotation.NonNull; 20 import android.content.Context; 21 import android.os.UserHandle; 22 import android.util.Slog; 23 24 import java.util.Objects; 25 26 /** 27 * Class to log Health Connect metrics logged every 24hrs. 28 * 29 * @hide 30 */ 31 public class DailyLoggingService { 32 33 private static final String HEALTH_CONNECT_DAILY_LOGGING_SERVICE = 34 "HealthConnectDailyLoggingService"; 35 36 /** Log daily metrics. */ logDailyMetrics(@onNull Context context, @NonNull UserHandle userHandle)37 public static void logDailyMetrics(@NonNull Context context, @NonNull UserHandle userHandle) { 38 Objects.requireNonNull(context); 39 Objects.requireNonNull(userHandle); 40 41 logDatabaseStats(context); 42 logUsageStats(context, userHandle); 43 } 44 logDatabaseStats(@onNull Context context)45 private static void logDatabaseStats(@NonNull Context context) { 46 try { 47 DatabaseStatsLogger.log(context); 48 } catch (Exception exception) { 49 Slog.e(HEALTH_CONNECT_DAILY_LOGGING_SERVICE, "Failed to log database stats", exception); 50 } 51 } 52 logUsageStats(@onNull Context context, @NonNull UserHandle userHandle)53 private static void logUsageStats(@NonNull Context context, @NonNull UserHandle userHandle) { 54 try { 55 UsageStatsLogger.log(context, userHandle); 56 } catch (Exception exception) { 57 Slog.e(HEALTH_CONNECT_DAILY_LOGGING_SERVICE, "Failed to log usage stats", exception); 58 } 59 } 60 } 61