From 9af93249bdcabaee793bcb7b69d30a6b7c911bfb Mon Sep 17 00:00:00 2001 From: Sandro Montanari Date: Thu, 10 Apr 2025 12:30:05 +0000 Subject: [PATCH] Remove unused DataStore class Bug: 407940468 Test: atest NetworkSecurityUnitTests Flag: com.android.net.ct.flags.certificate_transparency_service Change-Id: I8338087263c3f61bad061ac7687cd20d51685e67 --- .../com/android/server/net/ct/DataStore.java | 116 ------------------ 1 file changed, 116 deletions(-) delete mode 100644 networksecurity/service/src/com/android/server/net/ct/DataStore.java diff --git a/networksecurity/service/src/com/android/server/net/ct/DataStore.java b/networksecurity/service/src/com/android/server/net/ct/DataStore.java deleted file mode 100644 index bd17199cdb..0000000000 --- a/networksecurity/service/src/com/android/server/net/ct/DataStore.java +++ /dev/null @@ -1,116 +0,0 @@ -/* - * 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 android.util.Log; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.util.Optional; -import java.util.Properties; -import java.util.Set; - -/** Class to persist data needed by CT. */ -class DataStore extends Properties { - - private static final String TAG = "CertificateTransparency"; - - private static final long MAX_FILE_SIZE = 20 * 1024; // 20KB - private static final int MAX_KEY_SIZE = 50; - private final File mPropertyFile; - - DataStore(File file) { - super(); - mPropertyFile = file; - } - - void load() { - if (!mPropertyFile.exists()) { - return; - } - - if (!validatePropertyFile()) { - Log.e(TAG, "Invalid property file, not load it!"); - delete(); - return; - } - - try (InputStream in = new FileInputStream(mPropertyFile)) { - load(in); - if (!validateProperties()) { - Log.e(TAG, "Invalid property store, clear it!"); - delete(); - return; - } - } catch (IOException | IllegalArgumentException e) { - Log.e(TAG, "Error loading property store", e); - delete(); - } - } - - private boolean validateProperties() { - Set keys = stringPropertyNames(); - for (String key : keys) { - if (key.length() > MAX_KEY_SIZE) { - Log.e(TAG, "Unexpected Property: " + key); - return false; - } - } - return true; - } - - private boolean validatePropertyFile() { - if (mPropertyFile.length() > MAX_FILE_SIZE) { - Log.e(TAG, "Property file size exceeds " + MAX_FILE_SIZE + "!"); - return false; - } - return true; - } - - void store() { - try (FileOutputStream out = new FileOutputStream(mPropertyFile)) { - store(out, ""); - out.getFD().sync(); - } catch (IOException e) { - Log.e(TAG, "Error storing property store", e); - } - } - - boolean delete() { - clear(); - return mPropertyFile.delete(); - } - - long getPropertyLong(String key, long defaultValue) { - return Optional.ofNullable(getProperty(key)).map(Long::parseLong).orElse(defaultValue); - } - - Object setPropertyLong(String key, long value) { - return setProperty(key, Long.toString(value)); - } - - int getPropertyInt(String key, int defaultValue) { - return Optional.ofNullable(getProperty(key)).map(Integer::parseInt).orElse(defaultValue); - } - - Object setPropertyInt(String key, int value) { - return setProperty(key, Integer.toString(value)); - } -}