1 /* 2 * Copyright (C) 2019 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; 18 19 import static com.android.car.CarStatsLog.CAR_WAKEUP_FROM_SUSPEND_REPORTED__RESUME_TYPE__DISK; 20 import static com.android.car.CarStatsLog.CAR_WAKEUP_FROM_SUSPEND_REPORTED__RESUME_TYPE__RAM; 21 import static com.android.car.CarStatsLog.CAR_WAKEUP_FROM_SUSPEND_REPORTED__RESUME_TYPE__UNSPECIFIED; 22 23 /** 24 * CarStatsLogHelper provides API to send Car events to statd. 25 * 26 * <p>{@link CarStatsLog} is generated in 27 * {@code packages/services/Car/service/Android.bp}. 28 * @hide 29 */ 30 public class CarStatsLogHelper { 31 /** 32 * Logs a power state change event. 33 * @param state an integer defined in CarPowerManagementService.CpmsState 34 */ logPowerState(int state)35 public static void logPowerState(int state) { 36 CarStatsLog.write(CarStatsLog.CAR_POWER_STATE_CHANGED, state); 37 } 38 39 /** Logs a GarageMode start event. */ logGarageModeStart()40 public static void logGarageModeStart() { 41 CarStatsLog.write(CarStatsLog.GARAGE_MODE_INFO, true); 42 } 43 44 /** Logs a GarageMode stop event. */ logGarageModeStop()45 public static void logGarageModeStop() { 46 CarStatsLog.write(CarStatsLog.GARAGE_MODE_INFO, false); 47 } 48 49 /** Logs resume from suspend event */ logResumeFromSuspend(String type, long kernelStartTimeMillis, long carServiceStartTimeMillis, long userPerceivedStartTimeMillis, long deviceStartTimeMillis)50 public static void logResumeFromSuspend(String type, long kernelStartTimeMillis, 51 long carServiceStartTimeMillis, long userPerceivedStartTimeMillis, 52 long deviceStartTimeMillis) { 53 int statsType = switch(type) { 54 case "Suspend-to-Disk" -> CAR_WAKEUP_FROM_SUSPEND_REPORTED__RESUME_TYPE__DISK; 55 case "Suspend-to-RAM" -> CAR_WAKEUP_FROM_SUSPEND_REPORTED__RESUME_TYPE__RAM; 56 default -> CAR_WAKEUP_FROM_SUSPEND_REPORTED__RESUME_TYPE__UNSPECIFIED; 57 }; 58 CarStatsLog.write(CarStatsLog.CAR_WAKEUP_FROM_SUSPEND_REPORTED, statsType, 59 kernelStartTimeMillis, carServiceStartTimeMillis, userPerceivedStartTimeMillis, 60 deviceStartTimeMillis); 61 } 62 } 63