Loading wifi/java/src/android/net/wifi/WifiKeystore.java +28 −2 Original line number Diff line number Diff line Loading @@ -172,6 +172,26 @@ public final class WifiKeystore { return new String[0]; } /** * Remove all blobs that are stored in Legacy Keystore. * * @return True if the operation was successful, false otherwise. */ private static boolean removeAllFromLegacyKs() { // Assume that the calling identity has already been cleared. try { ILegacyKeystore legacyKeystore = WifiBlobStore.getLegacyKeystore(); String[] legacyAliases = legacyKeystore.list("", Process.WIFI_UID); for (String alias : legacyAliases) { legacyKeystore.remove(alias, Process.WIFI_UID); } return true; } catch (Exception e) { Log.e(TAG, "Failed to remove all blobs from Legacy Keystore: " + e); return false; } } /** * Remove all blobs that are stored in the database. * Loading @@ -183,10 +203,16 @@ public final class WifiKeystore { @SystemApi @FlaggedApi(Flags.FLAG_WIFI_KEYSTORE_REMOVE_ALL_API) public static boolean removeAll() { Log.i(TAG, "Removing all blobs from the database"); Log.i(TAG, "Removing all blobs from " + sPrimaryDbName); final long identity = Binder.clearCallingIdentity(); try { // If supplicant can access WifiBlobStore, then all certificates will be in that // database. Otherwise, all certificates will be in Legacy Keystore. if (WifiBlobStore.supplicantCanAccessBlobstore()) { return WifiBlobStore.getInstance().removeAll(); } else { return removeAllFromLegacyKs(); } } catch (Exception e) { Log.e(TAG, "Failed to remove all blobs: " + e); return false; Loading wifi/tests/src/android/net/wifi/WifiKeystoreTest.java +18 −2 Original line number Diff line number Diff line Loading @@ -194,13 +194,29 @@ public class WifiKeystoreTest { } /** * Test that removeAll only affects the WifiBlobStore database. * Test that removeAll only affects WifiBlobStore if that database is supported. */ @Test public void testRemoveAll() throws Exception { public void testRemoveAll_wifiBlobStore() throws Exception { when(WifiBlobStore.supplicantCanAccessBlobstore()).thenReturn(true); when(mWifiBlobStore.removeAll()).thenReturn(true); assertTrue(WifiKeystore.removeAll()); verify(mWifiBlobStore, times(1)).removeAll(); verifyNoInteractions(mLegacyKeystore); } /** * Test that removeAll only affects Legacy Keystore if WifiBlobStore is not supported. */ @Test public void testRemoveAll_legacyKeystore() throws Exception { String[] legacyAliases = {"alias1", "alias2", "alias3"}; when(WifiBlobStore.supplicantCanAccessBlobstore()).thenReturn(false); when(mLegacyKeystore.list(anyString(), anyInt())).thenReturn(legacyAliases); assertTrue(WifiKeystore.removeAll()); verify(mLegacyKeystore, times(1)).list(anyString(), anyInt()); verify(mLegacyKeystore, times(legacyAliases.length)).remove(anyString(), anyInt()); verifyNoInteractions(mWifiBlobStore); } } Loading
wifi/java/src/android/net/wifi/WifiKeystore.java +28 −2 Original line number Diff line number Diff line Loading @@ -172,6 +172,26 @@ public final class WifiKeystore { return new String[0]; } /** * Remove all blobs that are stored in Legacy Keystore. * * @return True if the operation was successful, false otherwise. */ private static boolean removeAllFromLegacyKs() { // Assume that the calling identity has already been cleared. try { ILegacyKeystore legacyKeystore = WifiBlobStore.getLegacyKeystore(); String[] legacyAliases = legacyKeystore.list("", Process.WIFI_UID); for (String alias : legacyAliases) { legacyKeystore.remove(alias, Process.WIFI_UID); } return true; } catch (Exception e) { Log.e(TAG, "Failed to remove all blobs from Legacy Keystore: " + e); return false; } } /** * Remove all blobs that are stored in the database. * Loading @@ -183,10 +203,16 @@ public final class WifiKeystore { @SystemApi @FlaggedApi(Flags.FLAG_WIFI_KEYSTORE_REMOVE_ALL_API) public static boolean removeAll() { Log.i(TAG, "Removing all blobs from the database"); Log.i(TAG, "Removing all blobs from " + sPrimaryDbName); final long identity = Binder.clearCallingIdentity(); try { // If supplicant can access WifiBlobStore, then all certificates will be in that // database. Otherwise, all certificates will be in Legacy Keystore. if (WifiBlobStore.supplicantCanAccessBlobstore()) { return WifiBlobStore.getInstance().removeAll(); } else { return removeAllFromLegacyKs(); } } catch (Exception e) { Log.e(TAG, "Failed to remove all blobs: " + e); return false; Loading
wifi/tests/src/android/net/wifi/WifiKeystoreTest.java +18 −2 Original line number Diff line number Diff line Loading @@ -194,13 +194,29 @@ public class WifiKeystoreTest { } /** * Test that removeAll only affects the WifiBlobStore database. * Test that removeAll only affects WifiBlobStore if that database is supported. */ @Test public void testRemoveAll() throws Exception { public void testRemoveAll_wifiBlobStore() throws Exception { when(WifiBlobStore.supplicantCanAccessBlobstore()).thenReturn(true); when(mWifiBlobStore.removeAll()).thenReturn(true); assertTrue(WifiKeystore.removeAll()); verify(mWifiBlobStore, times(1)).removeAll(); verifyNoInteractions(mLegacyKeystore); } /** * Test that removeAll only affects Legacy Keystore if WifiBlobStore is not supported. */ @Test public void testRemoveAll_legacyKeystore() throws Exception { String[] legacyAliases = {"alias1", "alias2", "alias3"}; when(WifiBlobStore.supplicantCanAccessBlobstore()).thenReturn(false); when(mLegacyKeystore.list(anyString(), anyInt())).thenReturn(legacyAliases); assertTrue(WifiKeystore.removeAll()); verify(mLegacyKeystore, times(1)).list(anyString(), anyInt()); verify(mLegacyKeystore, times(legacyAliases.length)).remove(anyString(), anyInt()); verifyNoInteractions(mWifiBlobStore); } }