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.trust; 18 19 import android.util.Log; 20 21 /** 22 * Helper class for logging trusted device related events, e.g. unlock process. 23 * 24 * Events are logged with timestamp in fixed format for parsing and further analyzing. 25 */ 26 final class EventLog { 27 private static final String UNLOCK_TAG = "CarTrustAgentUnlockEvent"; 28 private static final String ENROLL_TAG = "CarTrustAgentEnrollmentEvent"; 29 30 // Enrollment events. 31 static final String STOP_ENROLLMENT_ADVERTISING = "STOP_ENROLLMENT_ADVERTISING"; 32 static final String START_ENROLLMENT_ADVERTISING = "START_ENROLLMENT_ADVERTISING"; 33 static final String ENROLLMENT_HANDSHAKE_ACCEPTED = "ENROLLMENT_HANDSHAKE_ACCEPTED"; 34 static final String ENROLLMENT_ENCRYPTION_STATE = "ENROLLMENT_ENCRYPTION_STATE"; 35 static final String SHOW_VERIFICATION_CODE = "SHOW_VERIFICATION_CODE"; 36 static final String ENCRYPTION_KEY_SAVED = "ENCRYPTION_KEY_SAVED"; 37 static final String ESCROW_TOKEN_ADDED = "ESCROW_TOKEN_ADDED"; 38 39 // Unlock events. 40 static final String START_UNLOCK_ADVERTISING = "START_UNLOCK_ADVERTISING"; 41 static final String STOP_UNLOCK_ADVERTISING = "STOP_UNLOCK_ADVERTISING"; 42 static final String UNLOCK_SERVICE_INIT = "UNLOCK_SERVICE_INIT"; 43 static final String CLIENT_AUTHENTICATED = "CLIENT_AUTHENTICATED"; 44 static final String UNLOCK_CREDENTIALS_RECEIVED = "UNLOCK_CREDENTIALS_RECEIVED"; 45 static final String WAITING_FOR_CLIENT_AUTH = "WAITING_FOR_CLIENT_AUTH"; 46 static final String USER_UNLOCKED = "USER_UNLOCKED"; 47 static final String UNLOCK_ENCRYPTION_STATE = "UNLOCK_ENCRYPTION_STATE"; 48 static final String BLUETOOTH_STATE_CHANGED = "BLUETOOTH_STATE_CHANGED"; 49 50 // Shared events. 51 static final String REMOTE_DEVICE_CONNECTED = "REMOTE_DEVICE_CONNECTED"; 52 static final String RECEIVED_DEVICE_ID = "RECEIVED_DEVICE_ID"; 53 EventLog()54 private EventLog() { 55 // Do not instantiate. 56 } 57 58 /** 59 * Logs [timestamp and event] with unlock tag. 60 * Format is "timestamp: <system time in milli-seconds> - <eventType> 61 */ logUnlockEvent(String eventType)62 static void logUnlockEvent(String eventType) { 63 if (Log.isLoggable(UNLOCK_TAG, Log.INFO)) { 64 Log.i(UNLOCK_TAG, 65 String.format("timestamp: %d - %s", System.currentTimeMillis(), eventType)); 66 } 67 } 68 69 /** 70 * Logs [timestamp, event, and value] with unlock tag. 71 * Format is "timestamp: <system time in milli-seconds> - <eventType>: <value> 72 */ logUnlockEvent(String eventType, int value)73 static void logUnlockEvent(String eventType, int value) { 74 if (Log.isLoggable(UNLOCK_TAG, Log.INFO)) { 75 Log.i(UNLOCK_TAG, String.format("timestamp: %d - %s: %d", 76 System.currentTimeMillis(), eventType, value)); 77 } 78 } 79 80 /** 81 * Logs [timestamp and event] with enrollment tag. 82 * Format is "timestamp: <system time in milli-seconds> - <eventType> 83 */ logEnrollmentEvent(String eventType)84 static void logEnrollmentEvent(String eventType) { 85 if (Log.isLoggable(ENROLL_TAG, Log.INFO)) { 86 Log.i(ENROLL_TAG, String.format( 87 "timestamp: %d - %s", System.currentTimeMillis(), eventType)); 88 } 89 } 90 91 /** 92 * Logs [timestamp, event, and value] with enrollment tag. 93 * Format is "timestamp: <system time in milli-seconds> - <eventType>: <value> 94 */ logEnrollmentEvent(String eventType, int value)95 static void logEnrollmentEvent(String eventType, int value) { 96 if (Log.isLoggable(ENROLL_TAG, Log.INFO)) { 97 Log.i(ENROLL_TAG, String.format("timestamp: %d - %s: %d", 98 System.currentTimeMillis(), eventType, value)); 99 } 100 } 101 } 102