diff options
author | Xiao Ma <xiaom@google.com> | 2019-04-10 19:01:52 +0900 |
---|---|---|
committer | Xiao Ma <xiaom@google.com> | 2019-05-27 15:05:09 +0900 |
commit | c399624c8cdd3d210aba7d2e66bdfd27faa658df (patch) | |
tree | 129f1e09e1de92c709602abbc9d76b99b052fc48 /src | |
parent | d2de1123e32d887021e2b49211c07f8ddc2d0b79 (diff) |
Wipe the data in IpMemoryStore database upon network factory reset.
Bug:128499160
Test: manual
Test: atest FrameworksNetTests NetworkStackTests
Change-Id: Ib563463a861a5d27b1e9b5fbb92342249b573802
Diffstat (limited to 'src')
-rw-r--r-- | src/com/android/server/connectivity/ipmemorystore/IpMemoryStoreDatabase.java | 52 | ||||
-rw-r--r-- | src/com/android/server/connectivity/ipmemorystore/IpMemoryStoreService.java | 4 |
2 files changed, 56 insertions, 0 deletions
diff --git a/src/com/android/server/connectivity/ipmemorystore/IpMemoryStoreDatabase.java b/src/com/android/server/connectivity/ipmemorystore/IpMemoryStoreDatabase.java index 764e2d0..a538a5b 100644 --- a/src/com/android/server/connectivity/ipmemorystore/IpMemoryStoreDatabase.java +++ b/src/com/android/server/connectivity/ipmemorystore/IpMemoryStoreDatabase.java @@ -410,6 +410,7 @@ public class IpMemoryStoreDatabase { private static final String[] DATA_COLUMN = new String[] { PrivateDataContract.COLNAME_DATA }; + @Nullable static byte[] retrieveBlob(@NonNull final SQLiteDatabase db, @NonNull final String key, @NonNull final String clientId, @NonNull final String name) { @@ -432,6 +433,57 @@ public class IpMemoryStoreDatabase { } /** + * Wipe all data in tables when network factory reset occurs. + */ + static void wipeDataUponNetworkReset(@NonNull final SQLiteDatabase db) { + for (int remainingRetries = 3; remainingRetries > 0; --remainingRetries) { + db.beginTransaction(); + try { + db.delete(NetworkAttributesContract.TABLENAME, null, null); + db.delete(PrivateDataContract.TABLENAME, null, null); + final Cursor cursorNetworkAttributes = db.query( + // table name + NetworkAttributesContract.TABLENAME, + // column name + new String[] { NetworkAttributesContract.COLNAME_L2KEY }, + null, // selection + null, // selectionArgs + null, // groupBy + null, // having + null, // orderBy + "1"); // limit + if (0 != cursorNetworkAttributes.getCount()) { + cursorNetworkAttributes.close(); + continue; + } + cursorNetworkAttributes.close(); + final Cursor cursorPrivateData = db.query( + // table name + PrivateDataContract.TABLENAME, + // column name + new String[] { PrivateDataContract.COLNAME_L2KEY }, + null, // selection + null, // selectionArgs + null, // groupBy + null, // having + null, // orderBy + "1"); // limit + if (0 != cursorPrivateData.getCount()) { + cursorPrivateData.close(); + continue; + } + cursorPrivateData.close(); + db.setTransactionSuccessful(); + return; + } catch (SQLiteException e) { + Log.e(TAG, "Could not wipe the data in database", e); + } finally { + db.endTransaction(); + } + } + } + + /** * The following is a horrible hack that is necessary because the Android SQLite API does not * have a way to query a binary blob. This, almost certainly, is an overlook. * diff --git a/src/com/android/server/connectivity/ipmemorystore/IpMemoryStoreService.java b/src/com/android/server/connectivity/ipmemorystore/IpMemoryStoreService.java index 8312dfe..ad2bae8 100644 --- a/src/com/android/server/connectivity/ipmemorystore/IpMemoryStoreService.java +++ b/src/com/android/server/connectivity/ipmemorystore/IpMemoryStoreService.java @@ -410,8 +410,12 @@ public class IpMemoryStoreService extends IIpMemoryStore.Stub { }); } + /** + * Wipe the data in IpMemoryStore database upon network factory reset. + */ @Override public void factoryReset() { + mExecutor.execute(() -> IpMemoryStoreDatabase.wipeDataUponNetworkReset(mDb)); } /** Get db size threshold. */ |