summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorXiao Ma <xiaom@google.com>2019-05-28 00:52:00 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2019-05-28 00:52:00 +0000
commitc6459965d0b3dbd30a1427834813758bcbe9ffdd (patch)
treefbb540fc76e95dc1d96c8981253db464d242f9fc /src
parent3ee398ee490a5071bbfa5b493cae9bf798546eae (diff)
parentc399624c8cdd3d210aba7d2e66bdfd27faa658df (diff)
Merge "Wipe the data in IpMemoryStore database upon network factory reset."
Diffstat (limited to 'src')
-rw-r--r--src/com/android/server/connectivity/ipmemorystore/IpMemoryStoreDatabase.java52
-rw-r--r--src/com/android/server/connectivity/ipmemorystore/IpMemoryStoreService.java4
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. */