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

Commit ef995126 authored by Gabriel Biren's avatar Gabriel Biren
Browse files

Add a removeAll method to WifiKeystore.

Bug: 365543479
Flag: android.net.wifi.flags.wifi_keystore_remove_all_api
Test: atest FrameworksWifiNonUpdatableApiTests
Test: Manual test - add several entries to WifiKeystore
      and check that calling removeAll removes them
      from the database
Change-Id: Ibf8e8f8b9588cf64f2d3e746a5f4d5211f16144b
parent 5c05fbb5
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -10652,6 +10652,7 @@ package android.net.wifi {
    method @NonNull public static String[] list(@NonNull String);
    method public static boolean put(@NonNull String, @NonNull byte[]);
    method public static boolean remove(@NonNull String);
    method @FlaggedApi("android.net.wifi.flags.wifi_keystore_remove_all_api") public static boolean removeAll();
  }
  public final class WifiMigration {
+25 −0
Original line number Diff line number Diff line
@@ -15,9 +15,11 @@
 */
package android.net.wifi;

import android.annotation.FlaggedApi;
import android.annotation.NonNull;
import android.annotation.SuppressLint;
import android.annotation.SystemApi;
import android.net.wifi.flags.Flags;
import android.os.Binder;
import android.os.Process;
import android.os.ServiceSpecificException;
@@ -169,4 +171,27 @@ public final class WifiKeystore {
        }
        return new String[0];
    }

    /**
     * Remove all blobs that are stored in the database.
     *
     * @return True if the operation was successful (i.e. all blobs were removed, or the database
     *         was already empty). False if a critical error was encountered (ex. the database file
     *         is corrupted).
     * @hide
     */
    @SystemApi
    @FlaggedApi(Flags.FLAG_WIFI_KEYSTORE_REMOVE_ALL_API)
    public static boolean removeAll() {
        Log.i(TAG, "Removing all blobs from the database");
        final long identity = Binder.clearCallingIdentity();
        try {
            return WifiBlobStore.getInstance().removeAll();
        } catch (Exception e) {
            Log.e(TAG, "Failed to remove all blobs: " + e);
            return false;
        } finally {
            Binder.restoreCallingIdentity(identity);
        }
    }
}
+13 −0
Original line number Diff line number Diff line
@@ -26,8 +26,10 @@ import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.validateMockitoUsage;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoInteractions;
import static org.mockito.Mockito.when;
import static org.mockito.Mockito.withSettings;

@@ -190,4 +192,15 @@ public class WifiKeystoreTest {
        Arrays.sort(retrieved);
        assertArrayEquals(expected, retrieved);
    }

    /**
     * Test that removeAll only affects the WifiBlobStore database.
     */
    @Test
    public void testRemoveAll() throws Exception {
        when(mWifiBlobStore.removeAll()).thenReturn(true);
        assertTrue(WifiKeystore.removeAll());
        verify(mWifiBlobStore, times(1)).removeAll();
        verifyNoInteractions(mLegacyKeystore);
    }
}
+8 −0
Original line number Diff line number Diff line
@@ -56,3 +56,11 @@ flag {
        purpose: PURPOSE_BUGFIX
    }
}

flag {
    name: "wifi_keystore_remove_all_api"
    is_exported: true
    namespace: "wifi"
    description: "Add an API to remove all certificates stored in WifiKeystore"
    bug: "365543479"
}