Merge "Fixes for tetheroffload crashes"

This commit is contained in:
Treehugger Robot
2017-06-16 13:49:56 +00:00
committed by Gerrit Code Review
4 changed files with 23 additions and 14 deletions

View File

@@ -161,6 +161,7 @@ public class OffloadController {
} }
} }
return mHwInterface.setUpstreamParameters(iface, v4addr, v4gateway, v6gateways); return mHwInterface.setUpstreamParameters(
iface, v4addr, v4gateway, (v6gateways.isEmpty() ? null : v6gateways));
} }
} }

View File

@@ -16,6 +16,8 @@
package com.android.server.connectivity.tethering; package com.android.server.connectivity.tethering;
import static com.android.internal.util.BitUtils.uint16;
import android.hardware.tetheroffload.control.V1_0.IOffloadControl; import android.hardware.tetheroffload.control.V1_0.IOffloadControl;
import android.hardware.tetheroffload.control.V1_0.ITetheringOffloadCallback; import android.hardware.tetheroffload.control.V1_0.ITetheringOffloadCallback;
import android.hardware.tetheroffload.control.V1_0.NatTimeoutUpdate; import android.hardware.tetheroffload.control.V1_0.NatTimeoutUpdate;
@@ -33,6 +35,9 @@ import java.util.ArrayList;
*/ */
public class OffloadHardwareInterface { public class OffloadHardwareInterface {
private static final String TAG = OffloadHardwareInterface.class.getSimpleName(); private static final String TAG = OffloadHardwareInterface.class.getSimpleName();
private static final String NO_INTERFACE_NAME = "";
private static final String NO_IPV4_ADDRESS = "";
private static final String NO_IPV4_GATEWAY = "";
private static native boolean configOffload(); private static native boolean configOffload();
@@ -107,6 +112,11 @@ public class OffloadHardwareInterface {
public boolean setUpstreamParameters( public boolean setUpstreamParameters(
String iface, String v4addr, String v4gateway, ArrayList<String> v6gws) { String iface, String v4addr, String v4gateway, ArrayList<String> v6gws) {
iface = iface != null ? iface : NO_INTERFACE_NAME;
v4addr = v4addr != null ? v4addr : NO_IPV4_ADDRESS;
v4gateway = v4gateway != null ? v4gateway : NO_IPV4_GATEWAY;
v6gws = v6gws != null ? v6gws : new ArrayList<>();
final CbResults results = new CbResults(); final CbResults results = new CbResults();
try { try {
mOffloadControl.setUpstreamParameters( mOffloadControl.setUpstreamParameters(
@@ -143,8 +153,8 @@ public class OffloadHardwareInterface {
handler.post(() -> { handler.post(() -> {
controlCb.onNatTimeoutUpdate( controlCb.onNatTimeoutUpdate(
params.proto, params.proto,
params.src.addr, params.src.port, params.src.addr, uint16(params.src.port),
params.dst.addr, params.dst.port); params.dst.addr, uint16(params.dst.port));
}); });
} }
} }

View File

@@ -71,7 +71,7 @@ int conntrackSocket(unsigned groups) {
// auto-close it (otherwise there would be double-close problems). // auto-close it (otherwise there would be double-close problems).
// //
// Rely upon the compiler to eliminate the constexprs used for clarity. // Rely upon the compiler to eliminate the constexprs used for clarity.
hidl_handle&& handleFromFileDescriptor(base::unique_fd fd) { hidl_handle handleFromFileDescriptor(base::unique_fd fd) {
hidl_handle h; hidl_handle h;
NATIVE_HANDLE_DECLARE_STORAGE(storage, 0, 0); NATIVE_HANDLE_DECLARE_STORAGE(storage, 0, 0);
@@ -83,7 +83,7 @@ hidl_handle&& handleFromFileDescriptor(base::unique_fd fd) {
static constexpr bool kTakeOwnership = true; static constexpr bool kTakeOwnership = true;
h.setTo(nh, kTakeOwnership); h.setTo(nh, kTakeOwnership);
return std::move(h); return h;
} }
} // namespace } // namespace
@@ -116,13 +116,14 @@ static jboolean android_server_connectivity_tethering_OffloadHardwareInterface_c
bool rval; bool rval;
hidl_string msg; hidl_string msg;
configInterface->setHandles(h1, h2, const auto status = configInterface->setHandles(h1, h2,
[&rval, &msg](bool success, const hidl_string& errMsg) { [&rval, &msg](bool success, const hidl_string& errMsg) {
rval = success; rval = success;
msg = errMsg; msg = errMsg;
}); });
if (!rval) { if (!status.isOk() || !rval) {
ALOGE("IOffloadConfig::setHandles() error: %s", msg.c_str()); ALOGE("IOffloadConfig::setHandles() error: '%s' / '%s'",
status.description().c_str(), msg.c_str());
} }
return rval; return rval;

View File

@@ -155,8 +155,7 @@ public class OffloadControllerTest {
lp.setInterfaceName(testIfName); lp.setInterfaceName(testIfName);
offload.setUpstreamLinkProperties(lp); offload.setUpstreamLinkProperties(lp);
inOrder.verify(mHardware, times(1)).setUpstreamParameters( inOrder.verify(mHardware, times(1)).setUpstreamParameters(
eq(testIfName), eq(null), eq(null), mStringArrayCaptor.capture()); eq(testIfName), eq(null), eq(null), eq(null));
assertTrue(mStringArrayCaptor.getValue().isEmpty());
inOrder.verifyNoMoreInteractions(); inOrder.verifyNoMoreInteractions();
final String ipv4Addr = "192.0.2.5"; final String ipv4Addr = "192.0.2.5";
@@ -164,16 +163,14 @@ public class OffloadControllerTest {
lp.addLinkAddress(new LinkAddress(linkAddr)); lp.addLinkAddress(new LinkAddress(linkAddr));
offload.setUpstreamLinkProperties(lp); offload.setUpstreamLinkProperties(lp);
inOrder.verify(mHardware, times(1)).setUpstreamParameters( inOrder.verify(mHardware, times(1)).setUpstreamParameters(
eq(testIfName), eq(ipv4Addr), eq(null), mStringArrayCaptor.capture()); eq(testIfName), eq(ipv4Addr), eq(null), eq(null));
assertTrue(mStringArrayCaptor.getValue().isEmpty());
inOrder.verifyNoMoreInteractions(); inOrder.verifyNoMoreInteractions();
final String ipv4Gateway = "192.0.2.1"; final String ipv4Gateway = "192.0.2.1";
lp.addRoute(new RouteInfo(InetAddress.getByName(ipv4Gateway))); lp.addRoute(new RouteInfo(InetAddress.getByName(ipv4Gateway)));
offload.setUpstreamLinkProperties(lp); offload.setUpstreamLinkProperties(lp);
inOrder.verify(mHardware, times(1)).setUpstreamParameters( inOrder.verify(mHardware, times(1)).setUpstreamParameters(
eq(testIfName), eq(ipv4Addr), eq(ipv4Gateway), mStringArrayCaptor.capture()); eq(testIfName), eq(ipv4Addr), eq(ipv4Gateway), eq(null));
assertTrue(mStringArrayCaptor.getValue().isEmpty());
inOrder.verifyNoMoreInteractions(); inOrder.verifyNoMoreInteractions();
final String ipv6Gw1 = "fe80::cafe"; final String ipv6Gw1 = "fe80::cafe";