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

Commit 2e10d639 authored by Eric Biggers's avatar Eric Biggers
Browse files

Remove HardwareAuthToken support from FakeStorageManager

There is no longer any need for FakeStorageManager to keep track of
hardware auth tokens, since they aren't used for real anymore.

Test: atest com.android.server.locksettings
Bug: 184723544
Change-Id: Ida3a989ecea974fe79568e381cf0e6ff3fe1f1eb
parent a3f857f1
Loading
Loading
Loading
Loading
+0 −2
Original line number Diff line number Diff line
@@ -221,7 +221,6 @@ public abstract class BaseLockSettingsServiceTests {
                Object[] args = invocation.getArguments();
                mStorageManager.addUserKeyAuth((int) args[0] /* userId */,
                        (int) args[1] /* serialNumber */,
                        (byte[]) args[2] /* token */,
                        (byte[]) args[3] /* secret */);
                return null;
            }
@@ -233,7 +232,6 @@ public abstract class BaseLockSettingsServiceTests {
                Object[] args = invocation.getArguments();
                mStorageManager.clearUserKeyAuth((int) args[0] /* userId */,
                        (int) args[1] /* serialNumber */,
                        (byte[]) args[2] /* token */,
                        (byte[]) args[3] /* secret */);
                return null;
            }
+19 −20
Original line number Diff line number Diff line
@@ -19,7 +19,6 @@ package com.android.server.locksettings;
import android.os.IProgressListener;
import android.os.RemoteException;
import android.util.ArrayMap;
import android.util.Pair;


import junit.framework.AssertionFailedError;
@@ -29,56 +28,56 @@ import java.util.Arrays;

public class FakeStorageManager {

    private ArrayMap<Integer, ArrayList<Pair<byte[], byte[]>>> mAuth = new ArrayMap<>();
    private ArrayMap<Integer, ArrayList<byte[]>> mAuth = new ArrayMap<>();
    private boolean mIgnoreBadUnlock;

    public void addUserKeyAuth(int userId, int serialNumber, byte[] token, byte[] secret) {
        getUserAuth(userId).add(new Pair<>(token, secret));
    public void addUserKeyAuth(int userId, int serialNumber, byte[] secret) {
        getUserAuth(userId).add(secret);
    }

    public void clearUserKeyAuth(int userId, int serialNumber, byte[] token, byte[] secret) {
        ArrayList<Pair<byte[], byte[]>> auths = getUserAuth(userId);
        if (token == null && secret == null) {
    public void clearUserKeyAuth(int userId, int serialNumber, byte[] secret) {
        ArrayList<byte[]> auths = getUserAuth(userId);
        if (secret == null) {
            return;
        }
        auths.remove(new Pair<>(token, secret));
        auths.add(new Pair<>(null, null));
        auths.remove(secret);
        auths.add(null);
    }

    public void fixateNewestUserKeyAuth(int userId) {
        ArrayList<Pair<byte[], byte[]>> auths = mAuth.get(userId);
        Pair<byte[], byte[]> latest = auths.get(auths.size() - 1);
        ArrayList<byte[]> auths = mAuth.get(userId);
        byte[] latest = auths.get(auths.size() - 1);
        auths.clear();
        auths.add(latest);
    }

    private ArrayList<Pair<byte[], byte[]>> getUserAuth(int userId) {
    private ArrayList<byte[]> getUserAuth(int userId) {
        if (!mAuth.containsKey(userId)) {
            ArrayList<Pair<byte[], byte[]>> auths = new ArrayList<Pair<byte[], byte[]>>();
            auths.add(new Pair(null, null));
            ArrayList<byte[]> auths = new ArrayList<>();
            auths.add(null);
            mAuth.put(userId, auths);
        }
        return mAuth.get(userId);
    }

    public byte[] getUserUnlockToken(int userId) {
        ArrayList<Pair<byte[], byte[]>> auths = getUserAuth(userId);
        ArrayList<byte[]> auths = getUserAuth(userId);
        if (auths.size() != 1) {
            throw new AssertionFailedError("More than one secret exists");
        }
        return auths.get(0).second;
        return auths.get(0);
    }

    public void unlockUser(int userId, byte[] secret, IProgressListener listener)
            throws RemoteException {
        listener.onStarted(userId, null);
        listener.onFinished(userId, null);
        ArrayList<Pair<byte[], byte[]>> auths = getUserAuth(userId);
        ArrayList<byte[]> auths = getUserAuth(userId);
        if (auths.size() > 1) {
            throw new AssertionFailedError("More than one secret exists");
        }
        Pair<byte[], byte[]> auth = auths.get(0);
        if (!Arrays.equals(secret, auth.second)) {
        byte[] auth = auths.get(0);
        if (!Arrays.equals(secret, auth)) {
            if (!mIgnoreBadUnlock) {
                throw new AssertionFailedError("Invalid secret to unlock user " + userId);
            }