Merge "Move the IpMemoryStore to the network stack."
am: 93bf5ef495
Change-Id: I672d07ca2d0a251c246993ab8c7c3075de385570
This commit is contained in:
30
Android.bp
30
Android.bp
@@ -841,6 +841,9 @@ aidl_interface {
|
|||||||
"core/java/android/net/dhcp/IDhcpServerCallbacks.aidl",
|
"core/java/android/net/dhcp/IDhcpServerCallbacks.aidl",
|
||||||
"core/java/android/net/ip/IIpClient.aidl",
|
"core/java/android/net/ip/IIpClient.aidl",
|
||||||
"core/java/android/net/ip/IIpClientCallbacks.aidl",
|
"core/java/android/net/ip/IIpClientCallbacks.aidl",
|
||||||
|
"core/java/android/net/IIpMemoryStore.aidl",
|
||||||
|
"core/java/android/net/IIpMemoryStoreCallbacks.aidl",
|
||||||
|
"core/java/android/net/ipmemorystore/**/*.aidl",
|
||||||
],
|
],
|
||||||
backend: {
|
backend: {
|
||||||
ndk: {
|
ndk: {
|
||||||
@@ -853,13 +856,21 @@ aidl_interface {
|
|||||||
api_dir: "aidl/networkstack",
|
api_dir: "aidl/networkstack",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
aidl_interface {
|
||||||
|
name: "ipmemorystore-aidl-interfaces",
|
||||||
|
local_include_dir: "core/java",
|
||||||
|
srcs: [
|
||||||
|
"core/java/android/net/IIpMemoryStore.aidl",
|
||||||
|
"core/java/android/net/IIpMemoryStoreCallbacks.aidl",
|
||||||
|
"core/java/android/net/ipmemorystore/**/*.aidl",
|
||||||
|
],
|
||||||
|
}
|
||||||
|
|
||||||
aidl_interface {
|
aidl_interface {
|
||||||
name: "networkstack-aidl-framework",
|
name: "networkstack-aidl-framework",
|
||||||
local_include_dir: "core/java",
|
local_include_dir: "core/java",
|
||||||
srcs: [
|
srcs: [
|
||||||
"core/java/android/net/TcpKeepalivePacketDataParcelable.aidl",
|
"core/java/android/net/TcpKeepalivePacketDataParcelable.aidl",
|
||||||
"core/java/android/net/IIpMemoryStore.aidl",
|
|
||||||
"core/java/android/net/ipmemorystore/**/*.aidl",
|
|
||||||
],
|
],
|
||||||
api_dir: "aidl/networkstack",
|
api_dir: "aidl/networkstack",
|
||||||
backend: {
|
backend: {
|
||||||
@@ -870,18 +881,25 @@ aidl_interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
filegroup {
|
filegroup {
|
||||||
name: "framework-networkstack-shared-srcs",
|
name: "framework-annotations",
|
||||||
srcs: [
|
srcs: [
|
||||||
// TODO: remove these annotations as soon as we can use andoid.support.annotations.*
|
|
||||||
"core/java/android/annotation/NonNull.java",
|
"core/java/android/annotation/NonNull.java",
|
||||||
"core/java/android/annotation/Nullable.java",
|
"core/java/android/annotation/Nullable.java",
|
||||||
"core/java/android/annotation/IntDef.java",
|
"core/java/android/annotation/IntDef.java",
|
||||||
"core/java/android/annotation/IntRange.java",
|
"core/java/android/annotation/IntRange.java",
|
||||||
"core/java/android/annotation/UnsupportedAppUsage.java",
|
"core/java/android/annotation/UnsupportedAppUsage.java",
|
||||||
"core/java/android/net/DhcpResults.java",
|
|
||||||
"core/java/android/util/LocalLog.java",
|
|
||||||
"core/java/com/android/internal/annotations/GuardedBy.java",
|
"core/java/com/android/internal/annotations/GuardedBy.java",
|
||||||
"core/java/com/android/internal/annotations/VisibleForTesting.java",
|
"core/java/com/android/internal/annotations/VisibleForTesting.java",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
filegroup {
|
||||||
|
name: "framework-networkstack-shared-srcs",
|
||||||
|
srcs: [
|
||||||
|
// TODO: remove these annotations as soon as we can use andoid.support.annotations.*
|
||||||
|
":framework-annotations",
|
||||||
|
"core/java/android/net/DhcpResults.java",
|
||||||
|
"core/java/android/util/LocalLog.java",
|
||||||
"core/java/com/android/internal/util/HexDump.java",
|
"core/java/com/android/internal/util/HexDump.java",
|
||||||
"core/java/com/android/internal/util/IndentingPrintWriter.java",
|
"core/java/com/android/internal/util/IndentingPrintWriter.java",
|
||||||
"core/java/com/android/internal/util/IState.java",
|
"core/java/com/android/internal/util/IState.java",
|
||||||
|
|||||||
@@ -81,11 +81,9 @@ import android.net.ConnectivityThread;
|
|||||||
import android.net.EthernetManager;
|
import android.net.EthernetManager;
|
||||||
import android.net.IConnectivityManager;
|
import android.net.IConnectivityManager;
|
||||||
import android.net.IEthernetManager;
|
import android.net.IEthernetManager;
|
||||||
import android.net.IIpMemoryStore;
|
|
||||||
import android.net.IIpSecService;
|
import android.net.IIpSecService;
|
||||||
import android.net.INetworkPolicyManager;
|
import android.net.INetworkPolicyManager;
|
||||||
import android.net.ITestNetworkManager;
|
import android.net.ITestNetworkManager;
|
||||||
import android.net.IpMemoryStore;
|
|
||||||
import android.net.IpSecManager;
|
import android.net.IpSecManager;
|
||||||
import android.net.NetworkPolicyManager;
|
import android.net.NetworkPolicyManager;
|
||||||
import android.net.NetworkScoreManager;
|
import android.net.NetworkScoreManager;
|
||||||
@@ -298,17 +296,6 @@ final class SystemServiceRegistry {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
registerService(Context.IP_MEMORY_STORE_SERVICE, IpMemoryStore.class,
|
|
||||||
new CachedServiceFetcher<IpMemoryStore>() {
|
|
||||||
@Override
|
|
||||||
public IpMemoryStore createService(final ContextImpl ctx)
|
|
||||||
throws ServiceNotFoundException {
|
|
||||||
IBinder b = ServiceManager.getServiceOrThrow(
|
|
||||||
Context.IP_MEMORY_STORE_SERVICE);
|
|
||||||
IIpMemoryStore service = IIpMemoryStore.Stub.asInterface(b);
|
|
||||||
return new IpMemoryStore(ctx, service);
|
|
||||||
}});
|
|
||||||
|
|
||||||
registerService(Context.IPSEC_SERVICE, IpSecManager.class,
|
registerService(Context.IPSEC_SERVICE, IpSecManager.class,
|
||||||
new CachedServiceFetcher<IpSecManager>() {
|
new CachedServiceFetcher<IpSecManager>() {
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -3521,14 +3521,6 @@ public abstract class Context {
|
|||||||
*/
|
*/
|
||||||
public static final String NETWORK_STACK_SERVICE = "network_stack";
|
public static final String NETWORK_STACK_SERVICE = "network_stack";
|
||||||
|
|
||||||
/**
|
|
||||||
* Use with {@link #getSystemService(String)} to retrieve a
|
|
||||||
* {@link android.net.IpMemoryStore} to store and read information about
|
|
||||||
* known networks.
|
|
||||||
* @hide
|
|
||||||
*/
|
|
||||||
public static final String IP_MEMORY_STORE_SERVICE = "ipmemorystore";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Use with {@link #getSystemService(String)} to retrieve a
|
* Use with {@link #getSystemService(String)} to retrieve a
|
||||||
* {@link android.net.IpSecManager} for encrypting Sockets or Networks with
|
* {@link android.net.IpSecManager} for encrypting Sockets or Networks with
|
||||||
|
|||||||
24
core/java/android/net/IIpMemoryStoreCallbacks.aidl
Normal file
24
core/java/android/net/IIpMemoryStoreCallbacks.aidl
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
import android.net.IIpMemoryStore;
|
||||||
|
|
||||||
|
/** {@hide} */
|
||||||
|
oneway interface IIpMemoryStoreCallbacks {
|
||||||
|
void onIpMemoryStoreFetched(in IIpMemoryStore ipMemoryStore);
|
||||||
|
}
|
||||||
@@ -15,6 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
package android.net;
|
package android.net;
|
||||||
|
|
||||||
|
import android.net.IIpMemoryStoreCallbacks;
|
||||||
import android.net.INetworkMonitorCallbacks;
|
import android.net.INetworkMonitorCallbacks;
|
||||||
import android.net.Network;
|
import android.net.Network;
|
||||||
import android.net.dhcp.DhcpServingParamsParcel;
|
import android.net.dhcp.DhcpServingParamsParcel;
|
||||||
@@ -27,4 +28,5 @@ oneway interface INetworkStackConnector {
|
|||||||
in IDhcpServerCallbacks cb);
|
in IDhcpServerCallbacks cb);
|
||||||
void makeNetworkMonitor(in Network network, String name, in INetworkMonitorCallbacks cb);
|
void makeNetworkMonitor(in Network network, String name, in INetworkMonitorCallbacks cb);
|
||||||
void makeIpClient(in String ifName, in IIpClientCallbacks callbacks);
|
void makeIpClient(in String ifName, in IIpClientCallbacks callbacks);
|
||||||
}
|
void fetchIpMemoryStore(in IIpMemoryStoreCallbacks cb);
|
||||||
|
}
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ android_library {
|
|||||||
":services-networkstack-shared-srcs",
|
":services-networkstack-shared-srcs",
|
||||||
],
|
],
|
||||||
static_libs: [
|
static_libs: [
|
||||||
|
"ipmemorystore-client",
|
||||||
"netd_aidl_interface-java",
|
"netd_aidl_interface-java",
|
||||||
"networkstack-aidl-interfaces-java",
|
"networkstack-aidl-interfaces-java",
|
||||||
"datastallprotosnano",
|
"datastallprotosnano",
|
||||||
|
|||||||
@@ -0,0 +1,42 @@
|
|||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
import android.annotation.NonNull;
|
||||||
|
import android.content.Context;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* service used to communicate with the ip memory store service in network stack,
|
||||||
|
* which is running in the same module.
|
||||||
|
* @see com.android.server.connectivity.ipmemorystore.IpMemoryStoreService
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
public class NetworkStackIpMemoryStore extends IpMemoryStoreClient {
|
||||||
|
@NonNull private final IIpMemoryStore mService;
|
||||||
|
|
||||||
|
public NetworkStackIpMemoryStore(@NonNull final Context context,
|
||||||
|
@NonNull final IIpMemoryStore service) {
|
||||||
|
super(context);
|
||||||
|
mService = service;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@NonNull
|
||||||
|
protected IIpMemoryStore getService() {
|
||||||
|
return mService;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -29,6 +29,7 @@ import android.net.INetd;
|
|||||||
import android.net.IpPrefix;
|
import android.net.IpPrefix;
|
||||||
import android.net.LinkAddress;
|
import android.net.LinkAddress;
|
||||||
import android.net.LinkProperties;
|
import android.net.LinkProperties;
|
||||||
|
import android.net.NetworkStackIpMemoryStore;
|
||||||
import android.net.ProvisioningConfigurationParcelable;
|
import android.net.ProvisioningConfigurationParcelable;
|
||||||
import android.net.ProxyInfo;
|
import android.net.ProxyInfo;
|
||||||
import android.net.RouteInfo;
|
import android.net.RouteInfo;
|
||||||
@@ -61,6 +62,7 @@ import com.android.internal.util.State;
|
|||||||
import com.android.internal.util.StateMachine;
|
import com.android.internal.util.StateMachine;
|
||||||
import com.android.internal.util.WakeupMessage;
|
import com.android.internal.util.WakeupMessage;
|
||||||
import com.android.server.NetworkObserverRegistry;
|
import com.android.server.NetworkObserverRegistry;
|
||||||
|
import com.android.server.NetworkStackService.NetworkStackServiceManager;
|
||||||
|
|
||||||
import java.io.FileDescriptor;
|
import java.io.FileDescriptor;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
@@ -100,6 +102,7 @@ public class IpClient extends StateMachine {
|
|||||||
// One holds StateMachine logs and the other connectivity packet logs.
|
// One holds StateMachine logs and the other connectivity packet logs.
|
||||||
private static final ConcurrentHashMap<String, SharedLog> sSmLogs = new ConcurrentHashMap<>();
|
private static final ConcurrentHashMap<String, SharedLog> sSmLogs = new ConcurrentHashMap<>();
|
||||||
private static final ConcurrentHashMap<String, LocalLog> sPktLogs = new ConcurrentHashMap<>();
|
private static final ConcurrentHashMap<String, LocalLog> sPktLogs = new ConcurrentHashMap<>();
|
||||||
|
private final NetworkStackIpMemoryStore mIpMemoryStore;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Dump all state machine and connectivity packet logs to the specified writer.
|
* Dump all state machine and connectivity packet logs to the specified writer.
|
||||||
@@ -388,13 +391,14 @@ public class IpClient extends StateMachine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public IpClient(Context context, String ifName, IIpClientCallbacks callback,
|
public IpClient(Context context, String ifName, IIpClientCallbacks callback,
|
||||||
NetworkObserverRegistry observerRegistry) {
|
NetworkObserverRegistry observerRegistry, NetworkStackServiceManager nssManager) {
|
||||||
this(context, ifName, callback, observerRegistry, new Dependencies());
|
this(context, ifName, callback, observerRegistry, nssManager, new Dependencies());
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
IpClient(Context context, String ifName, IIpClientCallbacks callback,
|
IpClient(Context context, String ifName, IIpClientCallbacks callback,
|
||||||
NetworkObserverRegistry observerRegistry, Dependencies deps) {
|
NetworkObserverRegistry observerRegistry, NetworkStackServiceManager nssManager,
|
||||||
|
Dependencies deps) {
|
||||||
super(IpClient.class.getSimpleName() + "." + ifName);
|
super(IpClient.class.getSimpleName() + "." + ifName);
|
||||||
Preconditions.checkNotNull(ifName);
|
Preconditions.checkNotNull(ifName);
|
||||||
Preconditions.checkNotNull(callback);
|
Preconditions.checkNotNull(callback);
|
||||||
@@ -408,6 +412,8 @@ public class IpClient extends StateMachine {
|
|||||||
mShutdownLatch = new CountDownLatch(1);
|
mShutdownLatch = new CountDownLatch(1);
|
||||||
mCm = mContext.getSystemService(ConnectivityManager.class);
|
mCm = mContext.getSystemService(ConnectivityManager.class);
|
||||||
mObserverRegistry = observerRegistry;
|
mObserverRegistry = observerRegistry;
|
||||||
|
mIpMemoryStore =
|
||||||
|
new NetworkStackIpMemoryStore(context, nssManager.getIpMemoryStoreService());
|
||||||
|
|
||||||
sSmLogs.putIfAbsent(mInterfaceName, new SharedLog(MAX_LOG_RECORDS, mTag));
|
sSmLogs.putIfAbsent(mInterfaceName, new SharedLog(MAX_LOG_RECORDS, mTag));
|
||||||
mLog = sSmLogs.get(mInterfaceName);
|
mLog = sSmLogs.get(mInterfaceName);
|
||||||
|
|||||||
@@ -29,6 +29,8 @@ import android.app.Service;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.net.ConnectivityManager;
|
import android.net.ConnectivityManager;
|
||||||
|
import android.net.IIpMemoryStore;
|
||||||
|
import android.net.IIpMemoryStoreCallbacks;
|
||||||
import android.net.INetd;
|
import android.net.INetd;
|
||||||
import android.net.INetworkMonitor;
|
import android.net.INetworkMonitor;
|
||||||
import android.net.INetworkMonitorCallbacks;
|
import android.net.INetworkMonitorCallbacks;
|
||||||
@@ -49,6 +51,7 @@ import android.os.RemoteException;
|
|||||||
import com.android.internal.annotations.GuardedBy;
|
import com.android.internal.annotations.GuardedBy;
|
||||||
import com.android.internal.util.IndentingPrintWriter;
|
import com.android.internal.util.IndentingPrintWriter;
|
||||||
import com.android.server.connectivity.NetworkMonitor;
|
import com.android.server.connectivity.NetworkMonitor;
|
||||||
|
import com.android.server.connectivity.ipmemorystore.IpMemoryStoreService;
|
||||||
|
|
||||||
import java.io.FileDescriptor;
|
import java.io.FileDescriptor;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
@@ -86,7 +89,19 @@ public class NetworkStackService extends Service {
|
|||||||
return makeConnector(this);
|
return makeConnector(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class NetworkStackConnector extends INetworkStackConnector.Stub {
|
/**
|
||||||
|
* An interface for internal clients of the network stack service that can return
|
||||||
|
* or create inline instances of the service it manages.
|
||||||
|
*/
|
||||||
|
public interface NetworkStackServiceManager {
|
||||||
|
/**
|
||||||
|
* Get an instance of the IpMemoryStoreService.
|
||||||
|
*/
|
||||||
|
IIpMemoryStore getIpMemoryStoreService();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class NetworkStackConnector extends INetworkStackConnector.Stub
|
||||||
|
implements NetworkStackServiceManager {
|
||||||
private static final int NUM_VALIDATION_LOG_LINES = 20;
|
private static final int NUM_VALIDATION_LOG_LINES = 20;
|
||||||
private final Context mContext;
|
private final Context mContext;
|
||||||
private final INetd mNetd;
|
private final INetd mNetd;
|
||||||
@@ -94,6 +109,7 @@ public class NetworkStackService extends Service {
|
|||||||
private final ConnectivityManager mCm;
|
private final ConnectivityManager mCm;
|
||||||
@GuardedBy("mIpClients")
|
@GuardedBy("mIpClients")
|
||||||
private final ArrayList<WeakReference<IpClient>> mIpClients = new ArrayList<>();
|
private final ArrayList<WeakReference<IpClient>> mIpClients = new ArrayList<>();
|
||||||
|
private final IpMemoryStoreService mIpMemoryStoreService;
|
||||||
|
|
||||||
private static final int MAX_VALIDATION_LOGS = 10;
|
private static final int MAX_VALIDATION_LOGS = 10;
|
||||||
@GuardedBy("mValidationLogs")
|
@GuardedBy("mValidationLogs")
|
||||||
@@ -116,6 +132,7 @@ public class NetworkStackService extends Service {
|
|||||||
(IBinder) context.getSystemService(Context.NETD_SERVICE));
|
(IBinder) context.getSystemService(Context.NETD_SERVICE));
|
||||||
mObserverRegistry = new NetworkObserverRegistry();
|
mObserverRegistry = new NetworkObserverRegistry();
|
||||||
mCm = context.getSystemService(ConnectivityManager.class);
|
mCm = context.getSystemService(ConnectivityManager.class);
|
||||||
|
mIpMemoryStoreService = new IpMemoryStoreService(context);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
mObserverRegistry.register(mNetd);
|
mObserverRegistry.register(mNetd);
|
||||||
@@ -159,7 +176,7 @@ public class NetworkStackService extends Service {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void makeIpClient(String ifName, IIpClientCallbacks cb) throws RemoteException {
|
public void makeIpClient(String ifName, IIpClientCallbacks cb) throws RemoteException {
|
||||||
final IpClient ipClient = new IpClient(mContext, ifName, cb, mObserverRegistry);
|
final IpClient ipClient = new IpClient(mContext, ifName, cb, mObserverRegistry, this);
|
||||||
|
|
||||||
synchronized (mIpClients) {
|
synchronized (mIpClients) {
|
||||||
final Iterator<WeakReference<IpClient>> it = mIpClients.iterator();
|
final Iterator<WeakReference<IpClient>> it = mIpClients.iterator();
|
||||||
@@ -175,6 +192,17 @@ public class NetworkStackService extends Service {
|
|||||||
cb.onIpClientCreated(ipClient.makeConnector());
|
cb.onIpClientCreated(ipClient.makeConnector());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IIpMemoryStore getIpMemoryStoreService() {
|
||||||
|
return mIpMemoryStoreService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void fetchIpMemoryStore(@NonNull final IIpMemoryStoreCallbacks cb)
|
||||||
|
throws RemoteException {
|
||||||
|
cb.onIpMemoryStoreFetched(mIpMemoryStoreService);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void dump(@NonNull FileDescriptor fd, @NonNull PrintWriter fout,
|
protected void dump(@NonNull FileDescriptor fd, @NonNull PrintWriter fout,
|
||||||
@Nullable String[] args) {
|
@Nullable String[] args) {
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.android.server.net.ipmemorystore;
|
package com.android.server.connectivity.ipmemorystore;
|
||||||
|
|
||||||
import static android.net.shared.Inet4AddressUtils.inet4AddressToIntHTH;
|
import static android.net.shared.Inet4AddressUtils.inet4AddressToIntHTH;
|
||||||
import static android.net.shared.Inet4AddressUtils.intToInet4AddressHTH;
|
import static android.net.shared.Inet4AddressUtils.intToInet4AddressHTH;
|
||||||
@@ -14,14 +14,14 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.android.server.net.ipmemorystore;
|
package com.android.server.connectivity.ipmemorystore;
|
||||||
|
|
||||||
import static android.net.ipmemorystore.Status.ERROR_DATABASE_CANNOT_BE_OPENED;
|
import static android.net.ipmemorystore.Status.ERROR_DATABASE_CANNOT_BE_OPENED;
|
||||||
import static android.net.ipmemorystore.Status.ERROR_GENERIC;
|
import static android.net.ipmemorystore.Status.ERROR_GENERIC;
|
||||||
import static android.net.ipmemorystore.Status.ERROR_ILLEGAL_ARGUMENT;
|
import static android.net.ipmemorystore.Status.ERROR_ILLEGAL_ARGUMENT;
|
||||||
import static android.net.ipmemorystore.Status.SUCCESS;
|
import static android.net.ipmemorystore.Status.SUCCESS;
|
||||||
|
|
||||||
import static com.android.server.net.ipmemorystore.IpMemoryStoreDatabase.EXPIRY_ERROR;
|
import static com.android.server.connectivity.ipmemorystore.IpMemoryStoreDatabase.EXPIRY_ERROR;
|
||||||
|
|
||||||
import android.annotation.NonNull;
|
import android.annotation.NonNull;
|
||||||
import android.annotation.Nullable;
|
import android.annotation.Nullable;
|
||||||
@@ -40,7 +40,6 @@ import android.net.ipmemorystore.NetworkAttributesParcelable;
|
|||||||
import android.net.ipmemorystore.SameL3NetworkResponse;
|
import android.net.ipmemorystore.SameL3NetworkResponse;
|
||||||
import android.net.ipmemorystore.Status;
|
import android.net.ipmemorystore.Status;
|
||||||
import android.net.ipmemorystore.StatusParcelable;
|
import android.net.ipmemorystore.StatusParcelable;
|
||||||
import android.net.ipmemorystore.Utils;
|
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
@@ -14,7 +14,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.android.server.net.ipmemorystore;
|
package com.android.server.connectivity.ipmemorystore;
|
||||||
|
|
||||||
import com.android.internal.annotations.VisibleForTesting;
|
import com.android.internal.annotations.VisibleForTesting;
|
||||||
|
|
||||||
@@ -14,10 +14,11 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package android.net.ipmemorystore;
|
package com.android.server.connectivity.ipmemorystore;
|
||||||
|
|
||||||
import android.annotation.NonNull;
|
import android.annotation.NonNull;
|
||||||
import android.annotation.Nullable;
|
import android.annotation.Nullable;
|
||||||
|
import android.net.ipmemorystore.Blob;
|
||||||
|
|
||||||
/** {@hide} */
|
/** {@hide} */
|
||||||
public class Utils {
|
public class Utils {
|
||||||
@@ -51,6 +51,7 @@ import androidx.test.runner.AndroidJUnit4;
|
|||||||
import com.android.internal.R;
|
import com.android.internal.R;
|
||||||
import com.android.server.NetworkObserver;
|
import com.android.server.NetworkObserver;
|
||||||
import com.android.server.NetworkObserverRegistry;
|
import com.android.server.NetworkObserverRegistry;
|
||||||
|
import com.android.server.NetworkStackService;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@@ -90,6 +91,7 @@ public class IpClientTest {
|
|||||||
@Mock private AlarmManager mAlarm;
|
@Mock private AlarmManager mAlarm;
|
||||||
@Mock private IpClient.Dependencies mDependencies;
|
@Mock private IpClient.Dependencies mDependencies;
|
||||||
@Mock private ContentResolver mContentResolver;
|
@Mock private ContentResolver mContentResolver;
|
||||||
|
@Mock private NetworkStackService.NetworkStackServiceManager mNetworkStackServiceManager;
|
||||||
|
|
||||||
private NetworkObserver mObserver;
|
private NetworkObserver mObserver;
|
||||||
private InterfaceParams mIfParams;
|
private InterfaceParams mIfParams;
|
||||||
@@ -118,7 +120,8 @@ public class IpClientTest {
|
|||||||
|
|
||||||
private IpClient makeIpClient(String ifname) throws Exception {
|
private IpClient makeIpClient(String ifname) throws Exception {
|
||||||
setTestInterfaceParams(ifname);
|
setTestInterfaceParams(ifname);
|
||||||
final IpClient ipc = new IpClient(mContext, ifname, mCb, mObserverRegistry, mDependencies);
|
final IpClient ipc = new IpClient(mContext, ifname, mCb, mObserverRegistry,
|
||||||
|
mNetworkStackServiceManager, mDependencies);
|
||||||
verify(mNetd, timeout(TEST_TIMEOUT_MS).times(1)).interfaceSetEnableIPv6(ifname, false);
|
verify(mNetd, timeout(TEST_TIMEOUT_MS).times(1)).interfaceSetEnableIPv6(ifname, false);
|
||||||
verify(mNetd, timeout(TEST_TIMEOUT_MS).times(1)).interfaceClearAddrs(ifname);
|
verify(mNetd, timeout(TEST_TIMEOUT_MS).times(1)).interfaceClearAddrs(ifname);
|
||||||
ArgumentCaptor<NetworkObserver> arg = ArgumentCaptor.forClass(NetworkObserver.class);
|
ArgumentCaptor<NetworkObserver> arg = ArgumentCaptor.forClass(NetworkObserver.class);
|
||||||
@@ -142,8 +145,8 @@ public class IpClientTest {
|
|||||||
public void testNullInterfaceNameMostDefinitelyThrows() throws Exception {
|
public void testNullInterfaceNameMostDefinitelyThrows() throws Exception {
|
||||||
setTestInterfaceParams(null);
|
setTestInterfaceParams(null);
|
||||||
try {
|
try {
|
||||||
final IpClient ipc = new IpClient(
|
final IpClient ipc = new IpClient(mContext, null, mCb, mObserverRegistry,
|
||||||
mContext, null, mCb, mObserverRegistry, mDependencies);
|
mNetworkStackServiceManager, mDependencies);
|
||||||
ipc.shutdown();
|
ipc.shutdown();
|
||||||
fail();
|
fail();
|
||||||
} catch (NullPointerException npe) {
|
} catch (NullPointerException npe) {
|
||||||
@@ -156,8 +159,8 @@ public class IpClientTest {
|
|||||||
final String ifname = "lo";
|
final String ifname = "lo";
|
||||||
setTestInterfaceParams(ifname);
|
setTestInterfaceParams(ifname);
|
||||||
try {
|
try {
|
||||||
final IpClient ipc = new IpClient(
|
final IpClient ipc = new IpClient(mContext, ifname, null, mObserverRegistry,
|
||||||
mContext, ifname, null, mObserverRegistry, mDependencies);
|
mNetworkStackServiceManager, mDependencies);
|
||||||
ipc.shutdown();
|
ipc.shutdown();
|
||||||
fail();
|
fail();
|
||||||
} catch (NullPointerException npe) {
|
} catch (NullPointerException npe) {
|
||||||
@@ -168,16 +171,16 @@ public class IpClientTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testInvalidInterfaceDoesNotThrow() throws Exception {
|
public void testInvalidInterfaceDoesNotThrow() throws Exception {
|
||||||
setTestInterfaceParams(TEST_IFNAME);
|
setTestInterfaceParams(TEST_IFNAME);
|
||||||
final IpClient ipc = new IpClient(
|
final IpClient ipc = new IpClient(mContext, TEST_IFNAME, mCb, mObserverRegistry,
|
||||||
mContext, TEST_IFNAME, mCb, mObserverRegistry, mDependencies);
|
mNetworkStackServiceManager, mDependencies);
|
||||||
ipc.shutdown();
|
ipc.shutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testInterfaceNotFoundFailsImmediately() throws Exception {
|
public void testInterfaceNotFoundFailsImmediately() throws Exception {
|
||||||
setTestInterfaceParams(null);
|
setTestInterfaceParams(null);
|
||||||
final IpClient ipc = new IpClient(
|
final IpClient ipc = new IpClient(mContext, TEST_IFNAME, mCb, mObserverRegistry,
|
||||||
mContext, TEST_IFNAME, mCb, mObserverRegistry, mDependencies);
|
mNetworkStackServiceManager, mDependencies);
|
||||||
ipc.startProvisioning(new ProvisioningConfiguration());
|
ipc.startProvisioning(new ProvisioningConfiguration());
|
||||||
verify(mCb, times(1)).onProvisioningFailure(any());
|
verify(mCb, times(1)).onProvisioningFailure(any());
|
||||||
ipc.shutdown();
|
ipc.shutdown();
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.android.server.net.ipmemorystore;
|
package com.android.server.connectivity.ipmemorystore;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
@@ -14,9 +14,9 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.android.server.net.ipmemorystore;
|
package com.android.server.connectivity.ipmemorystore;
|
||||||
|
|
||||||
import static com.android.server.net.ipmemorystore.RelevanceUtils.CAPPED_RELEVANCE;
|
import static com.android.server.connectivity.ipmemorystore.RelevanceUtils.CAPPED_RELEVANCE;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
@@ -23,7 +23,6 @@ java_library {
|
|||||||
"services.companion",
|
"services.companion",
|
||||||
"services.coverage",
|
"services.coverage",
|
||||||
"services.devicepolicy",
|
"services.devicepolicy",
|
||||||
"services.ipmemorystore",
|
|
||||||
"services.midi",
|
"services.midi",
|
||||||
"services.net",
|
"services.net",
|
||||||
"services.print",
|
"services.print",
|
||||||
|
|||||||
@@ -1,4 +0,0 @@
|
|||||||
java_library_static {
|
|
||||||
name: "services.ipmemorystore",
|
|
||||||
srcs: ["java/**/*.java"],
|
|
||||||
}
|
|
||||||
@@ -98,7 +98,6 @@ import com.android.server.media.MediaUpdateService;
|
|||||||
import com.android.server.media.projection.MediaProjectionManagerService;
|
import com.android.server.media.projection.MediaProjectionManagerService;
|
||||||
import com.android.server.net.NetworkPolicyManagerService;
|
import com.android.server.net.NetworkPolicyManagerService;
|
||||||
import com.android.server.net.NetworkStatsService;
|
import com.android.server.net.NetworkStatsService;
|
||||||
import com.android.server.net.ipmemorystore.IpMemoryStoreService;
|
|
||||||
import com.android.server.net.watchlist.NetworkWatchlistService;
|
import com.android.server.net.watchlist.NetworkWatchlistService;
|
||||||
import com.android.server.notification.NotificationManagerService;
|
import com.android.server.notification.NotificationManagerService;
|
||||||
import com.android.server.oemlock.OemLockService;
|
import com.android.server.oemlock.OemLockService;
|
||||||
@@ -1135,14 +1134,6 @@ public final class SystemServer {
|
|||||||
}
|
}
|
||||||
traceEnd();
|
traceEnd();
|
||||||
|
|
||||||
traceBeginAndSlog("StartIpMemoryStoreService");
|
|
||||||
try {
|
|
||||||
ServiceManager.addService(Context.IP_MEMORY_STORE_SERVICE,
|
|
||||||
new IpMemoryStoreService(context));
|
|
||||||
} catch (Throwable e) {
|
|
||||||
reportWtf("starting IP Memory Store Service", e);
|
|
||||||
}
|
|
||||||
traceEnd();
|
|
||||||
|
|
||||||
traceBeginAndSlog("StartIpSecService");
|
traceBeginAndSlog("StartIpSecService");
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -7,6 +7,19 @@ java_library_static {
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
java_library_static {
|
||||||
|
name: "ipmemorystore-client",
|
||||||
|
sdk_version: "system_current",
|
||||||
|
srcs: [
|
||||||
|
":framework-annotations",
|
||||||
|
"java/android/net/IpMemoryStoreClient.java",
|
||||||
|
"java/android/net/ipmemorystore/**.java",
|
||||||
|
],
|
||||||
|
static_libs: [
|
||||||
|
"ipmemorystore-aidl-interfaces-java",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
filegroup {
|
filegroup {
|
||||||
name: "services-networkstack-shared-srcs",
|
name: "services-networkstack-shared-srcs",
|
||||||
srcs: [
|
srcs: [
|
||||||
|
|||||||
62
services/net/java/android/net/IpMemoryStore.java
Normal file
62
services/net/java/android/net/IpMemoryStore.java
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
import android.annotation.NonNull;
|
||||||
|
import android.content.Context;
|
||||||
|
|
||||||
|
import com.android.internal.annotations.VisibleForTesting;
|
||||||
|
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
import java.util.concurrent.ExecutionException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Manager class used to communicate with the ip memory store service in the network stack,
|
||||||
|
* which is running in a separate module.
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
public class IpMemoryStore extends IpMemoryStoreClient {
|
||||||
|
private final CompletableFuture<IIpMemoryStore> mService;
|
||||||
|
|
||||||
|
public IpMemoryStore(@NonNull final Context context) {
|
||||||
|
super(context);
|
||||||
|
mService = new CompletableFuture<>();
|
||||||
|
getNetworkStackClient().fetchIpMemoryStore(
|
||||||
|
new IIpMemoryStoreCallbacks.Stub() {
|
||||||
|
@Override
|
||||||
|
public void onIpMemoryStoreFetched(final IIpMemoryStore memoryStore) {
|
||||||
|
mService.complete(memoryStore);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected IIpMemoryStore getService() throws InterruptedException, ExecutionException {
|
||||||
|
return mService.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
@VisibleForTesting
|
||||||
|
protected NetworkStackClient getNetworkStackClient() {
|
||||||
|
return NetworkStackClient.getInstance();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Gets an instance of the memory store */
|
||||||
|
@NonNull
|
||||||
|
public static IpMemoryStore getMemoryStore(final Context context) {
|
||||||
|
return new IpMemoryStore(context);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2018 The Android Open Source Project
|
* Copyright (C) 2019 The Android Open Source Project
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -18,7 +18,6 @@ package android.net;
|
|||||||
|
|
||||||
import android.annotation.NonNull;
|
import android.annotation.NonNull;
|
||||||
import android.annotation.Nullable;
|
import android.annotation.Nullable;
|
||||||
import android.annotation.SystemService;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.net.ipmemorystore.Blob;
|
import android.net.ipmemorystore.Blob;
|
||||||
import android.net.ipmemorystore.IOnBlobRetrievedListener;
|
import android.net.ipmemorystore.IOnBlobRetrievedListener;
|
||||||
@@ -27,23 +26,34 @@ import android.net.ipmemorystore.IOnNetworkAttributesRetrieved;
|
|||||||
import android.net.ipmemorystore.IOnSameNetworkResponseListener;
|
import android.net.ipmemorystore.IOnSameNetworkResponseListener;
|
||||||
import android.net.ipmemorystore.IOnStatusListener;
|
import android.net.ipmemorystore.IOnStatusListener;
|
||||||
import android.net.ipmemorystore.NetworkAttributes;
|
import android.net.ipmemorystore.NetworkAttributes;
|
||||||
|
import android.net.ipmemorystore.Status;
|
||||||
|
import android.net.ipmemorystore.StatusParcelable;
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
import com.android.internal.util.Preconditions;
|
import java.util.concurrent.ExecutionException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The interface for system components to access the IP memory store.
|
* service used to communicate with the ip memory store service in network stack,
|
||||||
* @see com.android.server.net.ipmemorystore.IpMemoryStoreService
|
* which is running in a separate module.
|
||||||
* @hide
|
* @hide
|
||||||
*/
|
*/
|
||||||
@SystemService(Context.IP_MEMORY_STORE_SERVICE)
|
public abstract class IpMemoryStoreClient {
|
||||||
public class IpMemoryStore {
|
private static final String TAG = IpMemoryStoreClient.class.getSimpleName();
|
||||||
@NonNull final Context mContext;
|
private final Context mContext;
|
||||||
@NonNull final IIpMemoryStore mService;
|
|
||||||
|
|
||||||
public IpMemoryStore(@NonNull final Context context, @NonNull final IIpMemoryStore service) {
|
public IpMemoryStoreClient(@NonNull final Context context) {
|
||||||
mContext = Preconditions.checkNotNull(context, "missing context");
|
if (context == null) throw new IllegalArgumentException("missing context");
|
||||||
mService = Preconditions.checkNotNull(service, "missing IIpMemoryStore");
|
mContext = context;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
protected abstract IIpMemoryStore getService() throws InterruptedException, ExecutionException;
|
||||||
|
|
||||||
|
protected StatusParcelable internalErrorStatus() {
|
||||||
|
final StatusParcelable error = new StatusParcelable();
|
||||||
|
error.resultCode = Status.ERROR_UNKNOWN;
|
||||||
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -66,9 +76,13 @@ public class IpMemoryStore {
|
|||||||
@NonNull final NetworkAttributes attributes,
|
@NonNull final NetworkAttributes attributes,
|
||||||
@Nullable final IOnStatusListener listener) {
|
@Nullable final IOnStatusListener listener) {
|
||||||
try {
|
try {
|
||||||
mService.storeNetworkAttributes(l2Key, attributes.toParcelable(), listener);
|
try {
|
||||||
|
getService().storeNetworkAttributes(l2Key, attributes.toParcelable(), listener);
|
||||||
|
} catch (InterruptedException | ExecutionException m) {
|
||||||
|
listener.onComplete(internalErrorStatus());
|
||||||
|
}
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
throw e.rethrowFromSystemServer();
|
Log.e(TAG, "Error storing network attributes", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -87,9 +101,13 @@ public class IpMemoryStore {
|
|||||||
@NonNull final String name, @NonNull final Blob data,
|
@NonNull final String name, @NonNull final Blob data,
|
||||||
@Nullable final IOnStatusListener listener) {
|
@Nullable final IOnStatusListener listener) {
|
||||||
try {
|
try {
|
||||||
mService.storeBlob(l2Key, clientId, name, data, listener);
|
try {
|
||||||
|
getService().storeBlob(l2Key, clientId, name, data, listener);
|
||||||
|
} catch (InterruptedException | ExecutionException m) {
|
||||||
|
listener.onComplete(internalErrorStatus());
|
||||||
|
}
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
throw e.rethrowFromSystemServer();
|
Log.e(TAG, "Error storing blob", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -110,9 +128,13 @@ public class IpMemoryStore {
|
|||||||
public void findL2Key(@NonNull final NetworkAttributes attributes,
|
public void findL2Key(@NonNull final NetworkAttributes attributes,
|
||||||
@NonNull final IOnL2KeyResponseListener listener) {
|
@NonNull final IOnL2KeyResponseListener listener) {
|
||||||
try {
|
try {
|
||||||
mService.findL2Key(attributes.toParcelable(), listener);
|
try {
|
||||||
|
getService().findL2Key(attributes.toParcelable(), listener);
|
||||||
|
} catch (InterruptedException | ExecutionException m) {
|
||||||
|
listener.onL2KeyResponse(internalErrorStatus(), null);
|
||||||
|
}
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
throw e.rethrowFromSystemServer();
|
Log.e(TAG, "Error finding L2 Key", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -128,9 +150,13 @@ public class IpMemoryStore {
|
|||||||
public void isSameNetwork(@NonNull final String l2Key1, @NonNull final String l2Key2,
|
public void isSameNetwork(@NonNull final String l2Key1, @NonNull final String l2Key2,
|
||||||
@NonNull final IOnSameNetworkResponseListener listener) {
|
@NonNull final IOnSameNetworkResponseListener listener) {
|
||||||
try {
|
try {
|
||||||
mService.isSameNetwork(l2Key1, l2Key2, listener);
|
try {
|
||||||
|
getService().isSameNetwork(l2Key1, l2Key2, listener);
|
||||||
|
} catch (InterruptedException | ExecutionException m) {
|
||||||
|
listener.onSameNetworkResponse(internalErrorStatus(), null);
|
||||||
|
}
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
throw e.rethrowFromSystemServer();
|
Log.e(TAG, "Error checking for network sameness", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -146,9 +172,13 @@ public class IpMemoryStore {
|
|||||||
public void retrieveNetworkAttributes(@NonNull final String l2Key,
|
public void retrieveNetworkAttributes(@NonNull final String l2Key,
|
||||||
@NonNull final IOnNetworkAttributesRetrieved listener) {
|
@NonNull final IOnNetworkAttributesRetrieved listener) {
|
||||||
try {
|
try {
|
||||||
mService.retrieveNetworkAttributes(l2Key, listener);
|
try {
|
||||||
|
getService().retrieveNetworkAttributes(l2Key, listener);
|
||||||
|
} catch (InterruptedException | ExecutionException m) {
|
||||||
|
listener.onNetworkAttributesRetrieved(internalErrorStatus(), null, null);
|
||||||
|
}
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
throw e.rethrowFromSystemServer();
|
Log.e(TAG, "Error retrieving network attributes", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -166,14 +196,13 @@ public class IpMemoryStore {
|
|||||||
public void retrieveBlob(@NonNull final String l2Key, @NonNull final String clientId,
|
public void retrieveBlob(@NonNull final String l2Key, @NonNull final String clientId,
|
||||||
@NonNull final String name, @NonNull final IOnBlobRetrievedListener listener) {
|
@NonNull final String name, @NonNull final IOnBlobRetrievedListener listener) {
|
||||||
try {
|
try {
|
||||||
mService.retrieveBlob(l2Key, clientId, name, listener);
|
try {
|
||||||
|
getService().retrieveBlob(l2Key, clientId, name, listener);
|
||||||
|
} catch (InterruptedException | ExecutionException m) {
|
||||||
|
listener.onBlobRetrieved(internalErrorStatus(), null, null, null);
|
||||||
|
}
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
throw e.rethrowFromSystemServer();
|
Log.e(TAG, "Error retrieving blob", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Gets an instance of the memory store */
|
|
||||||
public static IpMemoryStore getMemoryStore(final Context context) {
|
|
||||||
return (IpMemoryStore) context.getSystemService(Context.IP_MEMORY_STORE_SERVICE);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -130,6 +130,21 @@ public class NetworkStackClient {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get an instance of the IpMemoryStore.
|
||||||
|
*
|
||||||
|
* <p>The IpMemoryStore will be returned asynchronously through the provided callbacks.
|
||||||
|
*/
|
||||||
|
public void fetchIpMemoryStore(IIpMemoryStoreCallbacks cb) {
|
||||||
|
requestConnector(connector -> {
|
||||||
|
try {
|
||||||
|
connector.fetchIpMemoryStore(cb);
|
||||||
|
} catch (RemoteException e) {
|
||||||
|
e.rethrowFromSystemServer();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
private class NetworkStackConnection implements ServiceConnection {
|
private class NetworkStackConnection implements ServiceConnection {
|
||||||
@Override
|
@Override
|
||||||
public void onServiceConnected(ComponentName name, IBinder service) {
|
public void onServiceConnected(ComponentName name, IBinder service) {
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ public class Status {
|
|||||||
public static final int ERROR_ILLEGAL_ARGUMENT = -2;
|
public static final int ERROR_ILLEGAL_ARGUMENT = -2;
|
||||||
public static final int ERROR_DATABASE_CANNOT_BE_OPENED = -3;
|
public static final int ERROR_DATABASE_CANNOT_BE_OPENED = -3;
|
||||||
public static final int ERROR_STORAGE = -4;
|
public static final int ERROR_STORAGE = -4;
|
||||||
|
public static final int ERROR_UNKNOWN = -5;
|
||||||
|
|
||||||
public final int resultCode;
|
public final int resultCode;
|
||||||
|
|
||||||
@@ -13,7 +13,6 @@ android_test {
|
|||||||
"mockito-target-minus-junit4",
|
"mockito-target-minus-junit4",
|
||||||
"platform-test-annotations",
|
"platform-test-annotations",
|
||||||
"services.core",
|
"services.core",
|
||||||
"services.ipmemorystore",
|
|
||||||
"services.net",
|
"services.net",
|
||||||
],
|
],
|
||||||
libs: [
|
libs: [
|
||||||
|
|||||||
@@ -16,6 +16,9 @@
|
|||||||
|
|
||||||
package android.net;
|
package android.net;
|
||||||
|
|
||||||
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
|
import static org.mockito.Mockito.doAnswer;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
import androidx.test.filters.SmallTest;
|
import androidx.test.filters.SmallTest;
|
||||||
@@ -33,13 +36,25 @@ public class IpMemoryStoreTest {
|
|||||||
@Mock
|
@Mock
|
||||||
Context mMockContext;
|
Context mMockContext;
|
||||||
@Mock
|
@Mock
|
||||||
|
NetworkStackClient mNetworkStackClient;
|
||||||
|
@Mock
|
||||||
IIpMemoryStore mMockService;
|
IIpMemoryStore mMockService;
|
||||||
IpMemoryStore mStore;
|
IpMemoryStore mStore;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
mStore = new IpMemoryStore(mMockContext, mMockService);
|
doAnswer(invocation -> {
|
||||||
|
((IIpMemoryStoreCallbacks) invocation.getArgument(0))
|
||||||
|
.onIpMemoryStoreFetched(mMockService);
|
||||||
|
return null;
|
||||||
|
}).when(mNetworkStackClient).fetchIpMemoryStore(any());
|
||||||
|
mStore = new IpMemoryStore(mMockContext) {
|
||||||
|
@Override
|
||||||
|
protected NetworkStackClient getNetworkStackClient() {
|
||||||
|
return mNetworkStackClient;
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
Reference in New Issue
Block a user