Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f1c5e408 authored by William Escande's avatar William Escande
Browse files

ErrorProne: BluetoothKeystoreService

In btservice/bluetoothKeystore/BluetoothKeystoreService.java:
```
576: warning: Private method 'readChecksumFile' is never used.
    private void readChecksumFile([...]) throws IOException {
                 ^
95: warning: The field 'CONFIG_FILE_CHECKSUM_PATH' is never read.
    private static final String CONFIG_FILE_CHECKSUM_PATH =
                                ^
97: warning: The field 'CONFIG_BACKUP_CHECKSUM_PATH' is never read.
    private static final String CONFIG_BACKUP_CHECKSUM_PATH =
                                ^
452|453: warning: It is very rare for LinkedList to out-perform ArrayList or ArrayDeque.
Avoid it unless you're willing to invest a lot of time into benchmarking.
Caveat: LinkedList supports null elements, but ArrayDeque does not.
        List<String> configEncryptedLines = new LinkedList<>();
                                            ^
557: warning: StringBuffer performs synchronization that is usually unnecessary;
prefer StringBuilder.
                StringBuffer hashString = new StringBuffer();
                                          ^
732: warning: Parameter name `data` is unknown.
     * @param data String as base64 to be decrypted.
       ^
```

Bug: 236759221
Test: m RUN_ERROR_PRONE=true Bluetooth
Change-Id: Ic5ff3df5391ef4596b1ba15a78485d532385851c
parent af190f9f
Loading
Loading
Loading
Loading
+5 −19
Original line number Diff line number Diff line
@@ -31,7 +31,6 @@ import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.KeyStore;
@@ -42,9 +41,9 @@ import java.security.NoSuchProviderException;
import java.security.ProviderException;
import java.security.UnrecoverableEntryException;
import java.security.cert.CertificateException;
import java.util.ArrayList;
import java.util.Base64;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
@@ -92,10 +91,6 @@ public class BluetoothKeystoreService {

    private static final String CONFIG_FILE_PATH = "/data/misc/bluedroid/bt_config.conf";
    private static final String CONFIG_BACKUP_PATH = "/data/misc/bluedroid/bt_config.bak";
    private static final String CONFIG_FILE_CHECKSUM_PATH =
            "/data/misc/bluedroid/bt_config.conf.encrypted-checksum";
    private static final String CONFIG_BACKUP_CHECKSUM_PATH =
            "/data/misc/bluedroid/bt_config.bak.encrypted-checksum";

    private static final int BUFFER_SIZE = 400 * 10;

@@ -449,8 +444,8 @@ public class BluetoothKeystoreService {
    @VisibleForTesting
    public void saveEncryptedKey() {
        stopThread();
        List<String> configEncryptedLines = new LinkedList<>();
        List<String> keyEncryptedLines = new LinkedList<>();
        List<String> configEncryptedLines = new ArrayList<>();
        List<String> keyEncryptedLines = new ArrayList<>();
        for (String key : mNameEncryptKey.keySet()) {
            if (key.equals(CONFIG_FILE_PREFIX) || key.equals(CONFIG_BACKUP_PREFIX)) {
                configEncryptedLines.add(getEncryptedKeyData(key));
@@ -554,7 +549,7 @@ public class BluetoothKeystoreService {
                }

                byte[] messageDigestBytes = messageDigest.digest();
                StringBuffer hashString = new StringBuffer();
                StringBuilder hashString = new StringBuilder();
                for (int index = 0; index < messageDigestBytes.length; index++) {
                    hashString.append(Integer.toString((
                            messageDigestBytes[index] & 0xff) + 0x100, 16).substring(1));
@@ -573,15 +568,6 @@ public class BluetoothKeystoreService {
        }
    }

    private void readChecksumFile(String filePathString, String prefixString) throws IOException {
        if (!Files.exists(Paths.get(filePathString))) {
            return;
        }
        byte[] allBytes = Files.readAllBytes(Paths.get(filePathString));
        String checksumDataBase64 = mEncoder.encodeToString(allBytes);
        mNameEncryptKey.put(prefixString, checksumDataBase64);
    }

    /**
     * Parses a file to search for the key and put it into the pending compute queue
     */
@@ -729,7 +715,7 @@ public class BluetoothKeystoreService {
    /**
     * Decrypt the original data blob from the provided {@link EncryptedData}.
     *
     * @param data String as base64 to be decrypted.
     * @param encryptedDataBase64 String as base64 to be decrypted.
     * @return String.
     */
    private @Nullable String decrypt(String encryptedDataBase64) {