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

Commit 4a8cc628 authored by Gabriel Biren's avatar Gabriel Biren Committed by Android (Google) Code Review
Browse files

Merge "Add a removeAll method to ConnectivityBlobStore." into main

parents 50252565 5c05fbb5
Loading
Loading
Loading
Loading
+20 −0
Original line number Diff line number Diff line
@@ -139,6 +139,26 @@ public class ConnectivityBlobStore {
        }
    }

    /**
     * Remove all blobs that are stored in the database.
     *
     * @return True if the operation was successful, false otherwise.
     * @hide
     */
    public boolean removeAll() {
        final int ownerUid = Binder.getCallingUid();
        try {
            final int numRowsRemoved = mDb.delete(TABLENAME, "owner=?" /* whereClause */,
                    new String[] {Integer.toString(ownerUid)} /* whereArgs */);
            Log.i(TAG, "Removed " + numRowsRemoved + " rows during the removeAll operation "
                    + "for uid " + ownerUid);
            return true;
        } catch (SQLException e) {
            Log.e(TAG, "Error while removing all blobs: " + e);
            return false;
        }
    }

    /**
     * Lists the name suffixes stored in the database matching the given prefix, sorted in
     * ascending order.
+18 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.internal.net;

import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
@@ -99,6 +100,23 @@ public class ConnectivityBlobStoreTest {
        assertFalse(connectivityBlobStore.remove(TEST_NAME));
    }

    @Test
    public void testRemoveAll() throws Exception {
        final ConnectivityBlobStore connectivityBlobStore = createConnectivityBlobStore();
        final int numEntries = 5;
        for (int i = 0; i < numEntries; i++) {
            assertTrue(connectivityBlobStore.put(TEST_NAME + i, TEST_BLOB));
        }
        assertEquals(numEntries, connectivityBlobStore.list("").length);

        // Remove all blobs and check that the blob store is empty.
        assertTrue(connectivityBlobStore.removeAll());
        assertEquals(0, connectivityBlobStore.list("").length);

        // Removing all blobs from an empty database should also succeed.
        assertTrue(connectivityBlobStore.removeAll());
    }

    @Test
    public void testMultipleNames() throws Exception {
        final String name1 = TEST_NAME + "1";