Reduce the visibility of logging to statsd to package-private

This change makes CTLogger into a public interface and reduces the
visibility of the actual implementation to package-private, as it was only made
public to allow for testing via mocking.

Flag: com.android.net.ct.flags.certificate_transparency_service
Bug: 378626065
Test: atest NetworkSecurityUnitTests
Change-Id: Ifeab50244219396ba3d3fc7f87b8d6e31ff726c9
This commit is contained in:
Bessie Jiang 2025-01-02 13:22:52 +00:00
commit 2435f1a245
4 changed files with 50 additions and 23 deletions

View file

@ -313,7 +313,6 @@ class CertificateTransparencyDownloader extends BroadcastReceiver {
status.reason());
} else {
// TODO(b/384935059): handle blocked domain logging
// TODO(b/384936292): add additionalchecks for pending wifi status
mLogger.logCTLogListUpdateFailedEvent(
downloadStatusToFailureReason(status.reason()), failureCount);
}

View file

@ -16,12 +16,8 @@
package com.android.server.net.ct;
import static com.android.server.net.ct.CertificateTransparencyStatsLog.CERTIFICATE_TRANSPARENCY_LOG_LIST_UPDATE_FAILED;
/** Helper class to interface with logging to statsd. */
public class CertificateTransparencyLogger {
public CertificateTransparencyLogger() {}
/** Interface with logging to statsd for Certificate Transparency. */
public interface CertificateTransparencyLogger {
/**
* Logs a CTLogListUpdateFailed event to statsd, when no HTTP error status code is present.
@ -29,9 +25,7 @@ public class CertificateTransparencyLogger {
* @param failureReason reason why the log list wasn't updated (e.g. DownloadManager failures)
* @param failureCount number of consecutive log list update failures
*/
public void logCTLogListUpdateFailedEvent(int failureReason, int failureCount) {
logCTLogListUpdateFailedEvent(failureReason, failureCount, /* httpErrorStatusCode= */ 0);
}
void logCTLogListUpdateFailedEvent(int failureReason, int failureCount);
/**
* Logs a CTLogListUpdateFailed event to statsd, when an HTTP error status code is provided.
@ -40,13 +34,7 @@ public class CertificateTransparencyLogger {
* @param failureCount number of consecutive log list update failures
* @param httpErrorStatusCode if relevant, the HTTP error status code from DownloadManager
*/
public void logCTLogListUpdateFailedEvent(
int failureReason, int failureCount, int httpErrorStatusCode) {
CertificateTransparencyStatsLog.write(
CERTIFICATE_TRANSPARENCY_LOG_LIST_UPDATE_FAILED,
failureReason,
failureCount,
httpErrorStatusCode
);
}
}
void logCTLogListUpdateFailedEvent(
int failureReason, int failureCount, int httpErrorStatusCode);
}

View file

@ -0,0 +1,40 @@
/*
* Copyright (C) 2024 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.server.net.ct;
import static com.android.server.net.ct.CertificateTransparencyStatsLog.CERTIFICATE_TRANSPARENCY_LOG_LIST_UPDATE_FAILED;
/** Implementation for logging to statsd for Certificate Transparency. */
class CertificateTransparencyLoggerImpl implements CertificateTransparencyLogger {
@Override
public void logCTLogListUpdateFailedEvent(int failureReason, int failureCount) {
logCTLogListUpdateFailedEvent(failureReason, failureCount, /* httpErrorStatusCode= */ 0);
}
@Override
public void logCTLogListUpdateFailedEvent(
int failureReason, int failureCount, int httpErrorStatusCode) {
CertificateTransparencyStatsLog.write(
CERTIFICATE_TRANSPARENCY_LOG_LIST_UPDATE_FAILED,
failureReason,
failureCount,
httpErrorStatusCode
);
}
}

View file

@ -18,18 +18,18 @@ package com.android.server.net.ct;
import static android.security.Flags.certificateTransparencyConfiguration;
import static com.android.net.ct.flags.Flags.certificateTransparencyJob;
import static com.android.net.ct.flags.Flags.certificateTransparencyService;
import android.annotation.RequiresApi;
import android.content.Context;
import android.net.ct.ICertificateTransparencyManager;
import android.os.Build;
import android.util.Log;
import android.provider.DeviceConfig;
import android.provider.DeviceConfig.Properties;
import android.util.Log;
import com.android.server.SystemService;
import java.util.concurrent.Executors;
/** Implementation of the Certificate Transparency service. */
@ -62,7 +62,7 @@ public class CertificateTransparencyService extends ICertificateTransparencyMana
downloadHelper,
signatureVerifier,
new CertificateTransparencyInstaller(),
new CertificateTransparencyLogger());
new CertificateTransparencyLoggerImpl());
mCertificateTransparencyJob =
new CertificateTransparencyJob(context, dataStore, downloader);
}