summaryrefslogtreecommitdiff
path: root/common/networkstackclient/src/android
diff options
context:
space:
mode:
authorChalard Jean <jchalard@google.com>2020-05-29 08:24:03 +0000
committerChalard Jean <jchalard@google.com>2020-05-29 08:57:46 +0000
commit530424f31fbc32f549f83619f4ecccd9fc1941fd (patch)
tree9a65d91d4ec11e571cbaba49cc66446945130955 /common/networkstackclient/src/android
parent89e8dcfdee111b3c8baa48878db00bd31b231bcf (diff)
Implement delete methods
Test: New tests in this patch, IpMemoryStore*Tests Bug: 146460486 Change-Id: Ibda8eeb917c05876e06e78ae600acd626ca94749 Merged-In: I8680164cf34bae2fac1f5431c03a3369dd6318ab (cherry picked from commit 4f81f357bce66c9fca13242d83267ae89cd43f1d, aosp/1311637)
Diffstat (limited to 'common/networkstackclient/src/android')
-rw-r--r--common/networkstackclient/src/android/net/IIpMemoryStore.aidl41
-rw-r--r--common/networkstackclient/src/android/net/IpMemoryStoreClient.java59
-rw-r--r--common/networkstackclient/src/android/net/ipmemorystore/IOnStatusAndCountListener.aidl28
-rw-r--r--common/networkstackclient/src/android/net/ipmemorystore/NetworkAttributes.java16
-rw-r--r--common/networkstackclient/src/android/net/ipmemorystore/OnDeleteStatusListener.java57
5 files changed, 199 insertions, 2 deletions
diff --git a/common/networkstackclient/src/android/net/IIpMemoryStore.aidl b/common/networkstackclient/src/android/net/IIpMemoryStore.aidl
index add221a..3bb58bf 100644
--- a/common/networkstackclient/src/android/net/IIpMemoryStore.aidl
+++ b/common/networkstackclient/src/android/net/IIpMemoryStore.aidl
@@ -22,6 +22,7 @@ import android.net.ipmemorystore.IOnBlobRetrievedListener;
import android.net.ipmemorystore.IOnL2KeyResponseListener;
import android.net.ipmemorystore.IOnNetworkAttributesRetrievedListener;
import android.net.ipmemorystore.IOnSameL3NetworkResponseListener;
+import android.net.ipmemorystore.IOnStatusAndCountListener;
import android.net.ipmemorystore.IOnStatusListener;
/** {@hide} */
@@ -39,8 +40,7 @@ oneway interface IIpMemoryStore {
* @param attributes The attributes for this network.
* @param listener A listener that will be invoked to inform of the completion of this call,
* or null if the client is not interested in learning about success/failure.
- * @return (through the listener) The L2 key. This is useful if the L2 key was not specified.
- * If the call failed, the L2 key will be null.
+ * @return (through the listener) A status to indicate success or failure.
*/
void storeNetworkAttributes(String l2Key, in NetworkAttributesParcelable attributes,
IOnStatusListener listener);
@@ -115,4 +115,41 @@ oneway interface IIpMemoryStore {
* Delete all data because a factory reset operation is in progress.
*/
void factoryReset();
+
+ /**
+ * Delete a single entry.
+ *
+ * @param l2key The L2 key of the entry to delete.
+ * @param needWipe Whether the data must be wiped from disk immediately. This makes the
+ * operation vastly more expensive as the database files will have to be copied
+ * and created again from the old files (see sqlite3 VACUUM operation for
+ * details) and makes no functional difference; only pass true if security or
+ * privacy demands this data must be removed from disk immediately.
+ * Note that this can fail for storage reasons. The passed listener will then
+ * receive an appropriate error status with the number of deleted rows.
+ * @param listener A listener that will be invoked to inform of the completion of this call,
+ * or null if the client is not interested in learning about success/failure.
+ * @return (through the listener) A status to indicate success and the number of deleted records
+ */
+ void delete(String l2Key, boolean needWipe, IOnStatusAndCountListener listener);
+
+ /**
+ * Delete all entries in a cluster.
+ *
+ * This method will delete all entries in the memory store that have the cluster attribute
+ * passed as an argument.
+ *
+ * @param cluster The cluster to delete.
+ * @param needWipe Whether the data must be wiped from disk immediately. This makes the
+ * operation vastly more expensive as the database files will have to be copied
+ * and created again from the old files (see sqlite3 VACUUM operation for
+ * details) and makes no functional difference; only pass true if security or
+ * privacy demands this data must be removed from disk immediately.
+ * Note that this can fail for storage reasons. The passed listener will then
+ * receive an appropriate error status with the number of deleted rows.
+ * @param listener A listener that will be invoked to inform of the completion of this call,
+ * or null if the client is not interested in learning about success/failure.
+ * @return (through the listener) A status to indicate success and the number of deleted records
+ */
+ void deleteCluster(String cluster, boolean needWipe, IOnStatusAndCountListener listener);
}
diff --git a/common/networkstackclient/src/android/net/IpMemoryStoreClient.java b/common/networkstackclient/src/android/net/IpMemoryStoreClient.java
index 014b528..f269f9c 100644
--- a/common/networkstackclient/src/android/net/IpMemoryStoreClient.java
+++ b/common/networkstackclient/src/android/net/IpMemoryStoreClient.java
@@ -22,6 +22,7 @@ import android.content.Context;
import android.net.ipmemorystore.Blob;
import android.net.ipmemorystore.NetworkAttributes;
import android.net.ipmemorystore.OnBlobRetrievedListener;
+import android.net.ipmemorystore.OnDeleteStatusListener;
import android.net.ipmemorystore.OnL2KeyResponseListener;
import android.net.ipmemorystore.OnNetworkAttributesRetrievedListener;
import android.net.ipmemorystore.OnSameL3NetworkResponseListener;
@@ -214,6 +215,64 @@ public abstract class IpMemoryStoreClient {
}
/**
+ * Delete a single entry.
+ *
+ * @param l2Key The L2 key of the entry to delete.
+ * @param needWipe Whether the data must be wiped from disk immediately. This makes the
+ * operation vastly more expensive as the database files will have to be copied
+ * and created again from the old files (see sqlite3 VACUUM operation for
+ * details) and makes no functional difference; only pass true if security or
+ * privacy demands this data must be removed from disk immediately.
+ * Note that this can fail for storage reasons. The passed listener will then
+ * receive an appropriate error status with the number of deleted rows.
+ * @param listener A listener that will be invoked to inform of the completion of this call,
+ * or null if the client is not interested in learning about success/failure.
+ * returns (through the listener) A status to indicate success and the number of deleted records
+ */
+ public void delete(@NonNull final String l2Key, final boolean needWipe,
+ @Nullable final OnDeleteStatusListener listener) {
+ try {
+ runWhenServiceReady(service -> ignoringRemoteException(() ->
+ service.delete(l2Key, needWipe, OnDeleteStatusListener.toAIDL(listener))));
+ } catch (ExecutionException m) {
+ ignoringRemoteException("Error deleting from the memory store",
+ () -> listener.onComplete(new Status(Status.ERROR_UNKNOWN),
+ 0 /* deletedRecords */));
+ }
+ }
+
+ /**
+ * Delete all entries in a cluster.
+ *
+ * This method will delete all entries in the memory store that have the cluster attribute
+ * passed as an argument.
+ *
+ * @param cluster The cluster to delete.
+ * @param needWipe Whether the data must be wiped from disk immediately. This makes the
+ * operation vastly more expensive as the database files will have to be copied
+ * and created again from the old files (see sqlite3 VACUUM operation for
+ * details) and makes no functional difference; only pass true if security or
+ * privacy demands this data must be removed from disk immediately.
+ * Note that this can fail for storage reasons. The passed listener will then
+ * receive an appropriate error status with the number of deleted rows.
+ * @param listener A listener that will be invoked to inform of the completion of this call,
+ * or null if the client is not interested in learning about success/failure.
+ * returns (through the listener) A status to indicate success and the number of deleted records
+ */
+ public void deleteCluster(@NonNull final String cluster, final boolean needWipe,
+ @Nullable final OnDeleteStatusListener listener) {
+ try {
+ runWhenServiceReady(service -> ignoringRemoteException(
+ () -> service.deleteCluster(cluster, needWipe,
+ OnDeleteStatusListener.toAIDL(listener))));
+ } catch (ExecutionException m) {
+ ignoringRemoteException("Error deleting from the memory store",
+ () -> listener.onComplete(new Status(Status.ERROR_UNKNOWN),
+ 0 /* deletedRecords */));
+ }
+ }
+
+ /**
* Wipe the data in the database upon network factory reset.
*/
public void factoryReset() {
diff --git a/common/networkstackclient/src/android/net/ipmemorystore/IOnStatusAndCountListener.aidl b/common/networkstackclient/src/android/net/ipmemorystore/IOnStatusAndCountListener.aidl
new file mode 100644
index 0000000..c19b5c1
--- /dev/null
+++ b/common/networkstackclient/src/android/net/ipmemorystore/IOnStatusAndCountListener.aidl
@@ -0,0 +1,28 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.net.ipmemorystore;
+
+import android.net.ipmemorystore.StatusParcelable;
+
+/** {@hide} */
+oneway interface IOnStatusAndCountListener {
+ /**
+ * The operation has completed with the specified status, and supplied the passed count
+ * as call-specific additional data.
+ */
+ void onComplete(in StatusParcelable status, int count);
+}
diff --git a/common/networkstackclient/src/android/net/ipmemorystore/NetworkAttributes.java b/common/networkstackclient/src/android/net/ipmemorystore/NetworkAttributes.java
index 104ac79..2e444fe 100644
--- a/common/networkstackclient/src/android/net/ipmemorystore/NetworkAttributes.java
+++ b/common/networkstackclient/src/android/net/ipmemorystore/NetworkAttributes.java
@@ -218,6 +218,22 @@ public class NetworkAttributes {
private Integer mMtu;
/**
+ * Constructs a new Builder.
+ */
+ public Builder() {}
+
+ /**
+ * Constructs a Builder from the passed NetworkAttributes.
+ */
+ public Builder(@NonNull final NetworkAttributes attributes) {
+ mAssignedAddress = attributes.assignedV4Address;
+ mAssignedAddressExpiry = attributes.assignedV4AddressExpiry;
+ mCluster = attributes.cluster;
+ mDnsAddresses = new ArrayList<>(attributes.dnsAddresses);
+ mMtu = attributes.mtu;
+ }
+
+ /**
* Set the assigned address.
* @param assignedV4Address The assigned address.
* @return This builder.
diff --git a/common/networkstackclient/src/android/net/ipmemorystore/OnDeleteStatusListener.java b/common/networkstackclient/src/android/net/ipmemorystore/OnDeleteStatusListener.java
new file mode 100644
index 0000000..7138877
--- /dev/null
+++ b/common/networkstackclient/src/android/net/ipmemorystore/OnDeleteStatusListener.java
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.net.ipmemorystore;
+
+import android.annotation.NonNull;
+import android.annotation.Nullable;
+
+/**
+ * A listener for the IpMemoryStore to return a status to a client.
+ * @hide
+ */
+public interface OnDeleteStatusListener {
+ /**
+ * The operation has completed with the specified status, and deleted the specified
+ * number of records. The operation can fail with a non-zero count of deleted rows as
+ * wipe requests may fail for lack of storage. See the documentation of each deletion
+ * method for details.
+ */
+ void onComplete(Status status, int deletedRecords);
+
+ /** Converts this OnDeleteStatusListener to a parcelable object */
+ @NonNull
+ static IOnStatusAndCountListener toAIDL(@Nullable final OnDeleteStatusListener listener) {
+ return new IOnStatusAndCountListener.Stub() {
+ @Override
+ public void onComplete(final StatusParcelable statusParcelable, int deletedRecords) {
+ if (null != listener) {
+ listener.onComplete(new Status(statusParcelable), deletedRecords);
+ }
+ }
+
+ @Override
+ public int getInterfaceVersion() {
+ return this.VERSION;
+ }
+
+ @Override
+ public String getInterfaceHash() {
+ return this.HASH;
+ }
+ };
+ }
+}