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

Commit 96ad5160 authored by Eric Biggers's avatar Eric Biggers
Browse files

LockSettingsStorage: gracefully handle null keys in database

Bug: 261860102
Test: com.android.server.locksettings
Change-Id: I7606dad85826d82d663a701e9e7bccb9d908da98
parent f76de3d6
Loading
Loading
Loading
Loading
+6 −2
Original line number Diff line number Diff line
@@ -62,6 +62,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * Storage for the lock settings service.
@@ -886,12 +887,15 @@ class LockSettingsStorage {
                if (!(obj instanceof CacheKey))
                    return false;
                CacheKey o = (CacheKey) obj;
                return userId == o.userId && type == o.type && key.equals(o.key);
                return userId == o.userId && type == o.type && Objects.equals(key, o.key);
            }

            @Override
            public int hashCode() {
                return key.hashCode() ^ userId ^ type;
                int hashCode = Objects.hashCode(key);
                hashCode = 31 * hashCode + userId;
                hashCode = 31 * hashCode + type;
                return hashCode;
            }
        }
    }
+14 −0
Original line number Diff line number Diff line
@@ -265,6 +265,20 @@ public class LockSettingsStorageTests {
        assertEquals("Cached value didn't match stored value", storage, cached);
    }

    @Test
    public void testNullKey() {
        mStorage.setString(null, "value", 0);

        // Verify that this doesn't throw an exception.
        assertEquals("value", mStorage.readKeyValue(null, null, 0));

        // The read that happens as part of prefetchUser shouldn't throw an exception either.
        mStorage.clearCache();
        mStorage.prefetchUser(0);

        assertEquals("value", mStorage.readKeyValue(null, null, 0));
    }

    @Test
    public void testRemoveUser() {
        mStorage.writeKeyValue("key", "value", 0);