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

Commit 95708256 authored by Joshua McCloskey's avatar Joshua McCloskey
Browse files

Fixed FaceProvider logging.

Previously the FaceProvider would print incorrect statistics related
to errors and their latencies. This change also adds an additional
counter for errors and total attempts.

Test: adb shell dumpsys face
Fixes: 239625968
Change-Id: Id61516997c3b65bf6b50a79ac242e9a37c681e90
parent 1e9a1d54
Loading
Loading
Loading
Loading
+28 −15
Original line number Original line Diff line number Diff line
@@ -70,20 +70,24 @@ public class UsageStats {


    private int mAcceptCount;
    private int mAcceptCount;
    private int mRejectCount;
    private int mRejectCount;
    private SparseIntArray mErrorCount;
    private int mErrorCount;
    private int mAuthAttemptCount;
    private SparseIntArray mErrorFrequencyMap;


    private long mAcceptLatency;
    private long mAcceptLatency;
    private long mRejectLatency;
    private long mRejectLatency;
    private SparseLongArray mErrorLatency;
    private long mErrorLatency;
    private SparseLongArray mErrorLatencyMap;


    public UsageStats(Context context) {
    public UsageStats(Context context) {
        mAuthenticationEvents = new ArrayDeque<>();
        mAuthenticationEvents = new ArrayDeque<>();
        mErrorCount = new SparseIntArray();
        mErrorFrequencyMap = new SparseIntArray();
        mErrorLatency = new SparseLongArray();
        mErrorLatencyMap = new SparseLongArray();
        mContext = context;
        mContext = context;
    }
    }


    public void addEvent(AuthenticationEvent event) {
    public void addEvent(AuthenticationEvent event) {
        mAuthAttemptCount++;
        if (mAuthenticationEvents.size() >= EVENT_LOG_SIZE) {
        if (mAuthenticationEvents.size() >= EVENT_LOG_SIZE) {
            mAuthenticationEvents.removeFirst();
            mAuthenticationEvents.removeFirst();
        }
        }
@@ -96,29 +100,38 @@ public class UsageStats {
            mRejectCount++;
            mRejectCount++;
            mRejectLatency += event.mLatency;
            mRejectLatency += event.mLatency;
        } else {
        } else {
            mErrorCount.put(event.mError, mErrorCount.get(event.mError, 0) + 1);
            mErrorCount++;
            mErrorLatency.put(event.mError, mErrorLatency.get(event.mError, 0L) + event.mLatency);
            mErrorLatency += event.mLatency;
            mErrorFrequencyMap.put(event.mError, mErrorFrequencyMap.get(event.mError, 0) + 1);
            mErrorLatencyMap.put(event.mError,
                    mErrorLatencyMap.get(event.mError, 0L) + event.mLatency);
        }
        }
    }
    }


    public void print(PrintWriter pw) {
    public void print(PrintWriter pw) {
        pw.println("Events since last reboot: " + mAuthenticationEvents.size());
        pw.println("Printing most recent events since last reboot("
                + mAuthenticationEvents.size() + " events)");
        for (AuthenticationEvent event : mAuthenticationEvents) {
        for (AuthenticationEvent event : mAuthenticationEvents) {
            pw.println(event.toString(mContext));
            pw.println(event.toString(mContext));
        }
        }


        // Dump aggregated usage stats
        // Dump aggregated usage stats
        pw.println("Accept\tCount: " + mAcceptCount + "\tLatency: " + mAcceptLatency
        pw.println("");
        pw.println("Accept Count: " + mAcceptCount + "\tLatency: " + mAcceptLatency
                + "\tAverage: " + (mAcceptCount > 0 ? mAcceptLatency / mAcceptCount : 0));
                + "\tAverage: " + (mAcceptCount > 0 ? mAcceptLatency / mAcceptCount : 0));
        pw.println("Reject\tCount: " + mRejectCount + "\tLatency: " + mRejectLatency
        pw.println("Reject Count: " + mRejectCount + "\tLatency: " + mRejectLatency
                + "\tAverage: " + (mRejectCount > 0 ? mRejectLatency / mRejectCount : 0));
                + "\tAverage: " + (mRejectCount > 0 ? mRejectLatency / mRejectCount : 0));

        pw.println("Total Error Count: " + mErrorCount + "\tLatency: " + mErrorLatency
        for (int i = 0; i < mErrorCount.size(); i++) {
                + "\tAverage: " + (mErrorCount > 0 ? mErrorLatency / mErrorCount : 0));
            final int key = mErrorCount.keyAt(i);
        pw.println("Total Attempts: " + mAuthAttemptCount);
            final int count = mErrorCount.get(i);
        pw.println("");

        for (int i = 0; i < mErrorFrequencyMap.size(); i++) {
            final int key = mErrorFrequencyMap.keyAt(i);
            final int count = mErrorFrequencyMap.get(key);
            pw.println("Error" + key + "\tCount: " + count
            pw.println("Error" + key + "\tCount: " + count
                    + "\tLatency: " + mErrorLatency.get(key, 0L)
                    + "\tLatency: " + mErrorLatencyMap.get(key, 0L)
                    + "\tAverage: " + (count > 0 ? mErrorLatency.get(key, 0L) / count : 0)
                    + "\tAverage: " + (count > 0 ? mErrorLatencyMap.get(key, 0L) / count : 0)
                    + "\t" + FaceManager.getErrorString(mContext, key, 0 /* vendorCode */));
                    + "\t" + FaceManager.getErrorString(mContext, key, 0 /* vendorCode */));
        }
        }
    }
    }