Merge "Log enrollment events." into qt-dev am: 4a5819741a am: 27a6731877
am: c19bb589e6
Change-Id: Ib668d45da3f8fb78844db205fa8e2289d22cc17f
diff --git a/service/src/com/android/car/trust/CarTrustAgentEnrollmentService.java b/service/src/com/android/car/trust/CarTrustAgentEnrollmentService.java
index 3093fee..1b5f4ab 100644
--- a/service/src/com/android/car/trust/CarTrustAgentEnrollmentService.java
+++ b/service/src/com/android/car/trust/CarTrustAgentEnrollmentService.java
@@ -19,6 +19,17 @@
import static android.car.trust.CarTrustAgentEnrollmentManager.ENROLLMENT_HANDSHAKE_FAILURE;
import static android.car.trust.CarTrustAgentEnrollmentManager.ENROLLMENT_NOT_ALLOWED;
+import static com.android.car.trust.EventLog.ENCRYPTION_KEY_SAVED;
+import static com.android.car.trust.EventLog.ENROLLMENT_ENCRYPTION_STATE;
+import static com.android.car.trust.EventLog.ENROLLMENT_HANDSHAKE_ACCEPTED;
+import static com.android.car.trust.EventLog.ESCROW_TOKEN_ADDED;
+import static com.android.car.trust.EventLog.RECEIVED_DEVICE_ID;
+import static com.android.car.trust.EventLog.REMOTE_DEVICE_CONNECTED;
+import static com.android.car.trust.EventLog.SHOW_VERIFICATION_CODE;
+import static com.android.car.trust.EventLog.START_ENROLLMENT_ADVERTISING;
+import static com.android.car.trust.EventLog.STOP_ENROLLMENT_ADVERTISING;
+import static com.android.car.trust.EventLog.logEnrollmentEvent;
+
import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.Nullable;
@@ -170,9 +181,8 @@
// Stop any current broadcasts
mTrustedDeviceService.getCarTrustAgentUnlockService().stopUnlockAdvertising();
stopEnrollmentAdvertising();
- if (Log.isLoggable(TAG, Log.DEBUG)) {
- Log.d(TAG, "startEnrollmentAdvertising");
- }
+
+ logEnrollmentEvent(START_ENROLLMENT_ADVERTISING);
addEnrollmentServiceLog("startEnrollmentAdvertising");
mCarTrustAgentBleManager.startEnrollmentAdvertising();
mEnrollmentState = ENROLLMENT_STATE_NONE;
@@ -183,11 +193,9 @@
*/
@Override
public void stopEnrollmentAdvertising() {
+ logEnrollmentEvent(STOP_ENROLLMENT_ADVERTISING);
addEnrollmentServiceLog("stopEnrollmentAdvertising");
mCarTrustAgentBleManager.stopEnrollmentAdvertising();
- if (Log.isLoggable(TAG, Log.DEBUG)) {
- Log.d(TAG, "stopEnrollmentAdvertising");
- }
}
/**
@@ -198,6 +206,7 @@
*/
@Override
public void enrollmentHandshakeAccepted(BluetoothDevice device) {
+ logEnrollmentEvent(ENROLLMENT_HANDSHAKE_ACCEPTED);
addEnrollmentServiceLog("enrollmentHandshakeAccepted");
if (device == null || !device.equals(mRemoteEnrollmentDevice)) {
Log.wtf(TAG,
@@ -352,7 +361,6 @@
}
}
-
/**
* Called after the escrow token has been successfully added to the framework.
*
@@ -382,7 +390,6 @@
}
}
-
/**
* Called after the escrow token has been successfully removed from the framework.
*/
@@ -534,6 +541,7 @@
* @param device the connected device
*/
void onRemoteDeviceConnected(BluetoothDevice device) {
+ logEnrollmentEvent(REMOTE_DEVICE_CONNECTED);
addEnrollmentServiceLog("onRemoteDeviceConnected (addr:" + device.getAddress() + ")");
resetEncryptionState();
mHandle = 0;
@@ -591,6 +599,7 @@
return;
}
notifyDeviceIdReceived(value);
+ logEnrollmentEvent(RECEIVED_DEVICE_ID);
break;
case ENROLLMENT_STATE_UNIQUE_ID:
try {
@@ -648,6 +657,7 @@
mEnrollmentDelegate.addEscrowToken(
mEncryptionKey.decryptData(token), ActivityManager.getCurrentUser());
mEnrollmentState++;
+ logEnrollmentEvent(ESCROW_TOKEN_ADDED);
} catch (SignatureException e) {
Log.e(TAG, "Could not decrypt escrow token", e);
}
@@ -678,9 +688,7 @@
mRemoteEnrollmentDevice, mHandshakeMessage.getNextMessage(),
OperationType.ENCRYPTION_HANDSHAKE, /* isPayloadEncrypted= */ false);
- if (Log.isLoggable(TAG, Log.DEBUG)) {
- Log.d(TAG, "Updated encryption state: " + mEncryptionState);
- }
+ logEnrollmentEvent(ENROLLMENT_ENCRYPTION_STATE, mEncryptionState);
break;
case HandshakeState.IN_PROGRESS:
@@ -739,6 +747,7 @@
Log.e(TAG, "Broadcast verification code failed", e);
}
}
+ logEnrollmentEvent(SHOW_VERIFICATION_CODE);
}
/**
@@ -796,6 +805,7 @@
dispatchEnrollmentFailure(ENROLLMENT_HANDSHAKE_FAILURE);
return;
}
+ logEnrollmentEvent(ENCRYPTION_KEY_SAVED);
mEnrollmentState++;
}
diff --git a/service/src/com/android/car/trust/CarTrustAgentUnlockService.java b/service/src/com/android/car/trust/CarTrustAgentUnlockService.java
index f692a25..ba342dc 100644
--- a/service/src/com/android/car/trust/CarTrustAgentUnlockService.java
+++ b/service/src/com/android/car/trust/CarTrustAgentUnlockService.java
@@ -17,12 +17,12 @@
package com.android.car.trust;
import static com.android.car.trust.EventLog.CLIENT_AUTHENTICATED;
-import static com.android.car.trust.EventLog.ENCRYPTION_STATE;
import static com.android.car.trust.EventLog.RECEIVED_DEVICE_ID;
import static com.android.car.trust.EventLog.REMOTE_DEVICE_CONNECTED;
import static com.android.car.trust.EventLog.START_UNLOCK_ADVERTISING;
import static com.android.car.trust.EventLog.STOP_UNLOCK_ADVERTISING;
import static com.android.car.trust.EventLog.UNLOCK_CREDIENTIALS_RECEIVED;
+import static com.android.car.trust.EventLog.UNLOCK_ENCRYPTION_STATE;
import static com.android.car.trust.EventLog.UNLOCK_SERVICE_INIT;
import static com.android.car.trust.EventLog.WAITING_FOR_CLIENT_AUTH;
import static com.android.car.trust.EventLog.logUnlockEvent;
@@ -380,7 +380,7 @@
mHandshakeMessage.getNextMessage(),
OperationType.ENCRYPTION_HANDSHAKE,
/* isPayloadEncrypted= */ false);
- logUnlockEvent(ENCRYPTION_STATE, mEncryptionState);
+ logUnlockEvent(UNLOCK_ENCRYPTION_STATE, mEncryptionState);
break;
case HandshakeMessage.HandshakeState.IN_PROGRESS:
@@ -398,7 +398,7 @@
// The state is updated after a call to continueHandshake(). Thus, need to check
// if we're in the next stage.
if (mEncryptionState == HandshakeMessage.HandshakeState.VERIFICATION_NEEDED) {
- logUnlockEvent(ENCRYPTION_STATE, mEncryptionState);
+ logUnlockEvent(UNLOCK_ENCRYPTION_STATE, mEncryptionState);
showVerificationCode();
return;
}
diff --git a/service/src/com/android/car/trust/EventLog.java b/service/src/com/android/car/trust/EventLog.java
index d4ff080..41efc7d 100644
--- a/service/src/com/android/car/trust/EventLog.java
+++ b/service/src/com/android/car/trust/EventLog.java
@@ -25,25 +25,38 @@
*/
final class EventLog {
private static final String UNLOCK_TAG = "CarTrustAgentUnlockEvent";
+ private static final String ENROLL_TAG = "CarTrustAgentEnrollmentEvent";
+ // Enrollment events.
+ static final String STOP_ENROLLMENT_ADVERTISING = "STOP_ENROLLMENT_ADVERTISING";
+ static final String START_ENROLLMENT_ADVERTISING = "START_ENROLLMENT_ADVERTISING";
+ static final String ENROLLMENT_HANDSHAKE_ACCEPTED = "ENROLLMENT_HANDSHAKE_ACCEPTED";
+ static final String ENROLLMENT_ENCRYPTION_STATE = "ENROLLMENT_ENCRYPTION_STATE";
+ static final String SHOW_VERIFICATION_CODE = "SHOW_VERIFICATION_CODE";
+ static final String ENCRYPTION_KEY_SAVED = "ENCRYPTION_KEY_SAVED";
+ static final String ESCROW_TOKEN_ADDED = "ESCROW_TOKEN_ADDED";
+
+ // Unlock events.
static final String START_UNLOCK_ADVERTISING = "START_UNLOCK_ADVERTISING";
static final String STOP_UNLOCK_ADVERTISING = "STOP_UNLOCK_ADVERTISING";
static final String UNLOCK_SERVICE_INIT = "UNLOCK_SERVICE_INIT";
- static final String REMOTE_DEVICE_CONNECTED = "REMOTE_DEVICE_CONNECTED";
- static final String RECEIVED_DEVICE_ID = "RECEIVED_DEVICE_ID";
static final String CLIENT_AUTHENTICATED = "CLIENT_AUTHENTICATED";
static final String UNLOCK_CREDIENTIALS_RECEIVED = "UNLOCK_CREDIENTIALS_RECEIVED";
static final String WAITING_FOR_CLIENT_AUTH = "WAITING_FOR_CLIENT_AUTH";
static final String USER_UNLOCKED = "USER_UNLOCKED";
- static final String ENCRYPTION_STATE = "ENCRYPTION_STATE";
+ static final String UNLOCK_ENCRYPTION_STATE = "UNLOCK_ENCRYPTION_STATE";
static final String BLUETOOTH_STATE_CHANGED = "BLUETOOTH_STATE_CHANGED";
+ // Shared events.
+ static final String REMOTE_DEVICE_CONNECTED = "REMOTE_DEVICE_CONNECTED";
+ static final String RECEIVED_DEVICE_ID = "RECEIVED_DEVICE_ID";
+
private EventLog() {
// Do not instantiate.
}
/**
- * Logs timestamp and event.
+ * Logs [timestamp and event] with unlock tag.
* Format is "timestamp: <system time in milli-seconds> - <eventType>
*/
static void logUnlockEvent(String eventType) {
@@ -54,7 +67,7 @@
}
/**
- * Logs timestamp, event, and value.
+ * Logs [timestamp, event, and value] with unlock tag.
* Format is "timestamp: <system time in milli-seconds> - <eventType>: <value>
*/
static void logUnlockEvent(String eventType, int value) {
@@ -63,4 +76,26 @@
System.currentTimeMillis(), eventType, value));
}
}
+
+ /**
+ * Logs [timestamp and event] with enrollment tag.
+ * Format is "timestamp: <system time in milli-seconds> - <eventType>
+ */
+ static void logEnrollmentEvent(String eventType) {
+ if (Log.isLoggable(ENROLL_TAG, Log.INFO)) {
+ Log.i(ENROLL_TAG, String.format(
+ "timestamp: %d - %s", System.currentTimeMillis(), eventType));
+ }
+ }
+
+ /**
+ * Logs [timestamp, event, and value] with enrollment tag.
+ * Format is "timestamp: <system time in milli-seconds> - <eventType>: <value>
+ */
+ static void logEnrollmentEvent(String eventType, int value) {
+ if (Log.isLoggable(ENROLL_TAG, Log.INFO)) {
+ Log.i(ENROLL_TAG, String.format("timestamp: %d - %s: %d",
+ System.currentTimeMillis(), eventType, value));
+ }
+ }
}