diff options
author | TreeHugger Robot <treehugger-gerrit@google.com> | 2019-05-28 10:31:21 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2019-05-28 10:31:21 +0000 |
commit | c6e7d0084fe6c8ed4ddfaeaca2051a2431b15e5d (patch) | |
tree | 9bcf16a8df9535843e0815610cd2ef5d1a3907de /src | |
parent | face41674d7d0bff33c354a94e91aff559ff4d72 (diff) | |
parent | f959756f340a0564ae192619cbf909fee36a9a22 (diff) |
Merge "Wipe the data in IpMemoryStore database upon network factory reset." into qt-dev
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. */ |