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

Commit 0fbf7f88 authored by Eric Biggers's avatar Eric Biggers
Browse files

RecoverySnapshotStorage: silence log spam from file not found

This condition is expected before an LSKF is set, so downgrade it from
ERROR level with stacktrace to INFO.  Also switch from Log to Slogf, as
this avoids needing to format the string separately.

Flag: EXEMPT bug fix
Bug: 372499066
Test: atest FrameworksServicesTests:com.android.server.locksettings.recoverablekeystore
Change-Id: I8cdadbf95229e5f23163fb9171c068ced842d93e
parent d2997952
Loading
Loading
Loading
Loading
+7 −5
Original line number Diff line number Diff line
@@ -19,7 +19,6 @@ package com.android.server.locksettings.recoverablekeystore.storage;
import android.annotation.Nullable;
import android.os.Environment;
import android.security.keystore.recovery.KeyChainSnapshot;
import android.util.Log;
import android.util.SparseArray;

import com.android.internal.annotations.GuardedBy;
@@ -29,9 +28,11 @@ import com.android.server.locksettings.recoverablekeystore.serialization
import com.android.server.locksettings.recoverablekeystore.serialization
        .KeyChainSnapshotParserException;
import com.android.server.locksettings.recoverablekeystore.serialization.KeyChainSnapshotSerializer;
import com.android.server.utils.Slogf;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.security.cert.CertificateEncodingException;
@@ -88,9 +89,7 @@ public class RecoverySnapshotStorage {
            // If we fail to write the latest snapshot, we should delete any older snapshot that
            // happens to be around. Otherwise snapshot syncs might end up going 'back in time'.
            snapshotFile.delete();
            Log.e(TAG,
                    String.format(Locale.US, "Error persisting snapshot for %d to disk", uid),
                    e);
            Slogf.e(TAG, e, "Error persisting snapshot for %d to disk", uid);
        }
    }

@@ -107,11 +106,14 @@ public class RecoverySnapshotStorage {
        File snapshotFile = getSnapshotFile(uid);
        try (FileInputStream fileInputStream = new FileInputStream(snapshotFile)) {
            return KeyChainSnapshotDeserializer.deserialize(fileInputStream);
        } catch (FileNotFoundException e) {
            Slogf.i(TAG, "Snapshot for uid %d not found", uid);
            return null;
        } catch (IOException | KeyChainSnapshotParserException e) {
            // If we fail to read the latest snapshot, we should delete it in case it is in some way
            // corrupted. We can regenerate snapshots anyway.
            snapshotFile.delete();
            Log.e(TAG, String.format(Locale.US, "Error reading snapshot for %d from disk", uid), e);
            Slogf.e(TAG, e, "Error reading snapshot for %d from disk", uid);
            return null;
        }
    }