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

Commit a149ca17 authored by Weichin Weng's avatar Weichin Weng Committed by Gerrit Code Review
Browse files

Merge "Common Criteria mode: Handle IOException when call newInputStream"

parents cd8f8ca4 b3659cbe
Loading
Loading
Loading
Loading
+27 −14
Original line number Diff line number Diff line
@@ -213,6 +213,7 @@ public class BluetoothKeystoreService {
    @VisibleForTesting
    public void cleanupForCommonCriteriaModeEnable() {
        try {
            Thread.sleep(100);
            setEncryptKeyOrRemoveKey(CONFIG_FILE_PREFIX, CONFIG_FILE_HASH);
        } catch (InterruptedException e) {
            reportBluetoothKeystoreException(e, "Interrupted while operating.");
@@ -523,7 +524,7 @@ public class BluetoothKeystoreService {
     */
    @VisibleForTesting
    public boolean compareFileHash(String hashFilePathString)
            throws IOException, NoSuchAlgorithmException {
            throws InterruptedException, IOException, NoSuchAlgorithmException {
        if (!Files.exists(Paths.get(hashFilePathString))) {
            infoLog("compareFileHash: File does not exist, path: " + hashFilePathString);
            return false;
@@ -558,13 +559,15 @@ public class BluetoothKeystoreService {
    }

    private void readHashFile(String filePathString, String prefixString)
            throws IOException, NoSuchAlgorithmException {
            throws InterruptedException, NoSuchAlgorithmException {
        byte[] dataBuffer = new byte[BUFFER_SIZE];
        int bytesRead  = 0;

        boolean successful = false;
        int counter = 0;
        while (!successful && counter < TRY_MAX) {
            try {
                MessageDigest messageDigest = MessageDigest.getInstance("SHA-256");
                InputStream fileStream = Files.newInputStream(Paths.get(filePathString));

                while ((bytesRead = fileStream.read(dataBuffer)) != -1) {
                    messageDigest.update(dataBuffer, 0, bytesRead);
                }
@@ -577,6 +580,16 @@ public class BluetoothKeystoreService {
                }

                mNameDecryptKey.put(prefixString, hashString.toString());
                successful = true;
            } catch (IOException e) {
                infoLog("Fail to open file, try again. counter: " + counter);
                Thread.sleep(50);
                counter++;
            }
        }
        if (counter > 3) {
            errorLog("Fail to open file");
        }
    }

    private void readChecksumFile(String filePathString, String prefixString) throws IOException {
+1 −1
Original line number Diff line number Diff line
@@ -214,7 +214,7 @@ public final class BluetoothKeystoreServiceTest {
    private boolean compareFileHash(String hashFilePathString) {
        try {
            return mBluetoothKeystoreService.compareFileHash(hashFilePathString);
        } catch (IOException | NoSuchAlgorithmException e) {
        } catch (InterruptedException | IOException | NoSuchAlgorithmException e) {
            return false;
        }
    }