summaryrefslogtreecommitdiff
path: root/common/networkstackclient/src
diff options
context:
space:
mode:
Diffstat (limited to 'common/networkstackclient/src')
-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/Layer2InformationParcelable.aidl2
-rw-r--r--common/networkstackclient/src/android/net/ip/IIpClient.aidl3
-rw-r--r--common/networkstackclient/src/android/net/ipmemorystore/IOnStatusAndCountListener.aidl28
-rw-r--r--common/networkstackclient/src/android/net/ipmemorystore/NetworkAttributes.java62
-rw-r--r--common/networkstackclient/src/android/net/ipmemorystore/NetworkAttributesParcelable.aidl2
-rw-r--r--common/networkstackclient/src/android/net/ipmemorystore/OnDeleteStatusListener.java57
8 files changed, 226 insertions, 28 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/Layer2InformationParcelable.aidl b/common/networkstackclient/src/android/net/Layer2InformationParcelable.aidl
index 496d291..a8eda0d 100644
--- a/common/networkstackclient/src/android/net/Layer2InformationParcelable.aidl
+++ b/common/networkstackclient/src/android/net/Layer2InformationParcelable.aidl
@@ -20,6 +20,6 @@ import android.net.MacAddress;
parcelable Layer2InformationParcelable {
String l2Key;
- String groupHint;
+ String cluster;
MacAddress bssid;
}
diff --git a/common/networkstackclient/src/android/net/ip/IIpClient.aidl b/common/networkstackclient/src/android/net/ip/IIpClient.aidl
index 0027949..029bdb3 100644
--- a/common/networkstackclient/src/android/net/ip/IIpClient.aidl
+++ b/common/networkstackclient/src/android/net/ip/IIpClient.aidl
@@ -34,7 +34,8 @@ oneway interface IIpClient {
void setMulticastFilter(boolean enabled);
void addKeepalivePacketFilter(int slot, in TcpKeepalivePacketDataParcelable pkt);
void removeKeepalivePacketFilter(int slot);
- void setL2KeyAndGroupHint(in String l2Key, in String groupHint);
+ /* Group hint is the old name for cluster */
+ void setL2KeyAndGroupHint(in String l2Key, in String cluster);
void addNattKeepalivePacketFilter(int slot, in NattKeepalivePacketDataParcelable pkt);
void notifyPreconnectionComplete(boolean success);
void updateLayer2Information(in Layer2InformationParcelable info);
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 818515a..2e444fe 100644
--- a/common/networkstackclient/src/android/net/ipmemorystore/NetworkAttributes.java
+++ b/common/networkstackclient/src/android/net/ipmemorystore/NetworkAttributes.java
@@ -67,11 +67,11 @@ public class NetworkAttributes {
// same L3 network".
private static final float WEIGHT_ASSIGNEDV4ADDREXPIRY = 0.0f;
- // Optionally supplied by the client if it has an opinion on L3 network. For example, this
- // could be a hash of the SSID + security type on WiFi.
+ // Optionally supplied by the client to signify belonging to a notion of a group owned by
+ // the client. For example, this could be a hash of the SSID on WiFi.
@Nullable
- public final String groupHint;
- private static final float WEIGHT_GROUPHINT = 300.0f;
+ public final String cluster;
+ private static final float WEIGHT_CLUSTER = 300.0f;
// The list of DNS server addresses.
@Nullable
@@ -89,7 +89,7 @@ public class NetworkAttributes {
@VisibleForTesting
public static final float TOTAL_WEIGHT = WEIGHT_ASSIGNEDV4ADDR
+ WEIGHT_ASSIGNEDV4ADDREXPIRY
- + WEIGHT_GROUPHINT
+ + WEIGHT_CLUSTER
+ WEIGHT_DNSADDRESSES
+ WEIGHT_MTU;
@@ -98,7 +98,7 @@ public class NetworkAttributes {
public NetworkAttributes(
@Nullable final Inet4Address assignedV4Address,
@Nullable final Long assignedV4AddressExpiry,
- @Nullable final String groupHint,
+ @Nullable final String cluster,
@Nullable final List<InetAddress> dnsAddresses,
@Nullable final Integer mtu) {
if (mtu != null && mtu < 0) throw new IllegalArgumentException("MTU can't be negative");
@@ -107,7 +107,7 @@ public class NetworkAttributes {
}
this.assignedV4Address = assignedV4Address;
this.assignedV4AddressExpiry = assignedV4AddressExpiry;
- this.groupHint = groupHint;
+ this.cluster = cluster;
this.dnsAddresses = null == dnsAddresses ? null :
Collections.unmodifiableList(new ArrayList<>(dnsAddresses));
this.mtu = mtu;
@@ -120,7 +120,7 @@ public class NetworkAttributes {
this((Inet4Address) getByAddressOrNull(parcelable.assignedV4Address),
parcelable.assignedV4AddressExpiry > 0
? parcelable.assignedV4AddressExpiry : null,
- parcelable.groupHint,
+ parcelable.cluster,
blobArrayToInetAddressList(parcelable.dnsAddresses),
parcelable.mtu >= 0 ? parcelable.mtu : null);
}
@@ -168,7 +168,7 @@ public class NetworkAttributes {
(null == assignedV4Address) ? null : assignedV4Address.getAddress();
parcelable.assignedV4AddressExpiry =
(null == assignedV4AddressExpiry) ? 0 : assignedV4AddressExpiry;
- parcelable.groupHint = groupHint;
+ parcelable.cluster = cluster;
parcelable.dnsAddresses = inetAddressListToBlobArray(dnsAddresses);
parcelable.mtu = (null == mtu) ? -1 : mtu;
return parcelable;
@@ -188,7 +188,7 @@ public class NetworkAttributes {
samenessContribution(WEIGHT_ASSIGNEDV4ADDR, assignedV4Address, o.assignedV4Address)
+ samenessContribution(WEIGHT_ASSIGNEDV4ADDREXPIRY, assignedV4AddressExpiry,
o.assignedV4AddressExpiry)
- + samenessContribution(WEIGHT_GROUPHINT, groupHint, o.groupHint)
+ + samenessContribution(WEIGHT_CLUSTER, cluster, o.cluster)
+ samenessContribution(WEIGHT_DNSADDRESSES, dnsAddresses, o.dnsAddresses)
+ samenessContribution(WEIGHT_MTU, mtu, o.mtu);
// The minimum is 0, the max is TOTAL_WEIGHT and should be represented by 1.0, and
@@ -211,13 +211,29 @@ public class NetworkAttributes {
@Nullable
private Long mAssignedAddressExpiry;
@Nullable
- private String mGroupHint;
+ private String mCluster;
@Nullable
private List<InetAddress> mDnsAddresses;
@Nullable
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.
@@ -244,12 +260,12 @@ public class NetworkAttributes {
}
/**
- * Set the group hint.
- * @param groupHint The group hint.
+ * Set the cluster.
+ * @param cluster The cluster.
* @return This builder.
*/
- public Builder setGroupHint(@Nullable final String groupHint) {
- mGroupHint = groupHint;
+ public Builder setCluster(@Nullable final String cluster) {
+ mCluster = cluster;
return this;
}
@@ -287,14 +303,14 @@ public class NetworkAttributes {
*/
public NetworkAttributes build() {
return new NetworkAttributes(mAssignedAddress, mAssignedAddressExpiry,
- mGroupHint, mDnsAddresses, mMtu);
+ mCluster, mDnsAddresses, mMtu);
}
}
/** @hide */
public boolean isEmpty() {
return (null == assignedV4Address) && (null == assignedV4AddressExpiry)
- && (null == groupHint) && (null == dnsAddresses) && (null == mtu);
+ && (null == cluster) && (null == dnsAddresses) && (null == mtu);
}
@Override
@@ -303,7 +319,7 @@ public class NetworkAttributes {
final NetworkAttributes other = (NetworkAttributes) o;
return Objects.equals(assignedV4Address, other.assignedV4Address)
&& Objects.equals(assignedV4AddressExpiry, other.assignedV4AddressExpiry)
- && Objects.equals(groupHint, other.groupHint)
+ && Objects.equals(cluster, other.cluster)
&& Objects.equals(dnsAddresses, other.dnsAddresses)
&& Objects.equals(mtu, other.mtu);
}
@@ -311,7 +327,7 @@ public class NetworkAttributes {
@Override
public int hashCode() {
return Objects.hash(assignedV4Address, assignedV4AddressExpiry,
- groupHint, dnsAddresses, mtu);
+ cluster, dnsAddresses, mtu);
}
/** Pretty print */
@@ -334,11 +350,11 @@ public class NetworkAttributes {
nullFields.add("assignedV4AddressExpiry");
}
- if (null != groupHint) {
- resultJoiner.add("groupHint :");
- resultJoiner.add(groupHint);
+ if (null != cluster) {
+ resultJoiner.add("cluster :");
+ resultJoiner.add(cluster);
} else {
- nullFields.add("groupHint");
+ nullFields.add("cluster");
}
if (null != dnsAddresses) {
diff --git a/common/networkstackclient/src/android/net/ipmemorystore/NetworkAttributesParcelable.aidl b/common/networkstackclient/src/android/net/ipmemorystore/NetworkAttributesParcelable.aidl
index 997eb2b..b710427 100644
--- a/common/networkstackclient/src/android/net/ipmemorystore/NetworkAttributesParcelable.aidl
+++ b/common/networkstackclient/src/android/net/ipmemorystore/NetworkAttributesParcelable.aidl
@@ -31,7 +31,7 @@ import android.net.ipmemorystore.Blob;
parcelable NetworkAttributesParcelable {
byte[] assignedV4Address;
long assignedV4AddressExpiry;
- String groupHint;
+ String cluster;
Blob[] dnsAddresses;
int mtu;
}
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;
+ }
+ };
+ }
+}