Merge "[Tether06] Migrate tether offload controller into module"
This commit is contained in:
@@ -27,6 +27,7 @@ java_defaults {
|
|||||||
"androidx.annotation_annotation",
|
"androidx.annotation_annotation",
|
||||||
"netd_aidl_interface-java",
|
"netd_aidl_interface-java",
|
||||||
"networkstack-aidl-interfaces-java",
|
"networkstack-aidl-interfaces-java",
|
||||||
|
"android.hardware.tetheroffload.control-V1.0-java",
|
||||||
"tethering-client",
|
"tethering-client",
|
||||||
],
|
],
|
||||||
manifest: "AndroidManifestBase.xml",
|
manifest: "AndroidManifestBase.xml",
|
||||||
@@ -38,11 +39,39 @@ android_library {
|
|||||||
defaults: ["TetheringAndroidLibraryDefaults"],
|
defaults: ["TetheringAndroidLibraryDefaults"],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cc_library_shared {
|
||||||
|
name: "libtetheroffloadjni",
|
||||||
|
srcs: [
|
||||||
|
"jni/com_android_server_connectivity_tethering_OffloadHardwareInterface.cpp",
|
||||||
|
],
|
||||||
|
shared_libs: [
|
||||||
|
"libnativehelper",
|
||||||
|
"libcutils",
|
||||||
|
"android.hardware.tetheroffload.config@1.0",
|
||||||
|
],
|
||||||
|
static_libs: [
|
||||||
|
"liblog",
|
||||||
|
"libbase",
|
||||||
|
"libhidlbase",
|
||||||
|
"libutils",
|
||||||
|
],
|
||||||
|
|
||||||
|
cflags: [
|
||||||
|
"-Wall",
|
||||||
|
"-Werror",
|
||||||
|
"-Wno-unused-parameter",
|
||||||
|
"-Wthread-safety",
|
||||||
|
],
|
||||||
|
}
|
||||||
|
|
||||||
// Common defaults for compiling the actual APK.
|
// Common defaults for compiling the actual APK.
|
||||||
java_defaults {
|
java_defaults {
|
||||||
name: "TetheringAppDefaults",
|
name: "TetheringAppDefaults",
|
||||||
platform_apis: true,
|
platform_apis: true,
|
||||||
privileged: true,
|
privileged: true,
|
||||||
|
jni_libs: [
|
||||||
|
"libtetheroffloadjni",
|
||||||
|
],
|
||||||
resource_dirs: [
|
resource_dirs: [
|
||||||
"res",
|
"res",
|
||||||
],
|
],
|
||||||
@@ -71,6 +100,8 @@ filegroup {
|
|||||||
name: "tethering-servicescore-srcs",
|
name: "tethering-servicescore-srcs",
|
||||||
srcs: [
|
srcs: [
|
||||||
"src/com/android/server/connectivity/tethering/EntitlementManager.java",
|
"src/com/android/server/connectivity/tethering/EntitlementManager.java",
|
||||||
|
"src/com/android/server/connectivity/tethering/OffloadController.java",
|
||||||
|
"src/com/android/server/connectivity/tethering/OffloadHardwareInterface.java",
|
||||||
"src/com/android/server/connectivity/tethering/TetheringConfiguration.java",
|
"src/com/android/server/connectivity/tethering/TetheringConfiguration.java",
|
||||||
"src/com/android/server/connectivity/tethering/UpstreamNetworkMonitor.java",
|
"src/com/android/server/connectivity/tethering/UpstreamNetworkMonitor.java",
|
||||||
],
|
],
|
||||||
@@ -88,3 +119,11 @@ filegroup {
|
|||||||
"src/android/net/util/PrefixUtils.java",
|
"src/android/net/util/PrefixUtils.java",
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This group would be removed when tethering migration is done.
|
||||||
|
filegroup {
|
||||||
|
name: "tethering-jni-srcs",
|
||||||
|
srcs: [
|
||||||
|
"jni/com_android_server_connectivity_tethering_OffloadHardwareInterface.cpp",
|
||||||
|
],
|
||||||
|
}
|
||||||
|
|||||||
@@ -36,8 +36,8 @@ import android.net.netlink.NetlinkSocket;
|
|||||||
import android.net.util.IpUtils;
|
import android.net.util.IpUtils;
|
||||||
import android.net.util.SharedLog;
|
import android.net.util.SharedLog;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Looper;
|
|
||||||
import android.os.INetworkManagementService;
|
import android.os.INetworkManagementService;
|
||||||
|
import android.os.Looper;
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
import android.os.SystemClock;
|
import android.os.SystemClock;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
@@ -60,7 +60,6 @@ import java.util.Map;
|
|||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A class to encapsulate the business logic of programming the tethering
|
* A class to encapsulate the business logic of programming the tethering
|
||||||
@@ -74,7 +73,7 @@ public class OffloadController {
|
|||||||
private static final String ANYIP = "0.0.0.0";
|
private static final String ANYIP = "0.0.0.0";
|
||||||
private static final ForwardedStats EMPTY_STATS = new ForwardedStats();
|
private static final ForwardedStats EMPTY_STATS = new ForwardedStats();
|
||||||
|
|
||||||
private static enum UpdateType { IF_NEEDED, FORCE };
|
private enum UpdateType { IF_NEEDED, FORCE };
|
||||||
|
|
||||||
private final Handler mHandler;
|
private final Handler mHandler;
|
||||||
private final OffloadHardwareInterface mHwInterface;
|
private final OffloadHardwareInterface mHwInterface;
|
||||||
@@ -128,6 +127,7 @@ public class OffloadController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Start hardware offload. */
|
||||||
public boolean start() {
|
public boolean start() {
|
||||||
if (started()) return true;
|
if (started()) return true;
|
||||||
|
|
||||||
@@ -235,6 +235,7 @@ public class OffloadController {
|
|||||||
return isStarted;
|
return isStarted;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Stop hardware offload. */
|
||||||
public void stop() {
|
public void stop() {
|
||||||
// Completely stops tethering offload. After this method is called, it is no longer safe to
|
// Completely stops tethering offload. After this method is called, it is no longer safe to
|
||||||
// call any HAL method, no callbacks from the hardware will be delivered, and any in-flight
|
// call any HAL method, no callbacks from the hardware will be delivered, and any in-flight
|
||||||
@@ -258,7 +259,9 @@ public class OffloadController {
|
|||||||
// getTetherStats() is the only function in OffloadController that can be called from
|
// getTetherStats() is the only function in OffloadController that can be called from
|
||||||
// a different thread. Do not attempt to update stats by querying the offload HAL
|
// a different thread. Do not attempt to update stats by querying the offload HAL
|
||||||
// synchronously from a different thread than our Handler thread. http://b/64771555.
|
// synchronously from a different thread than our Handler thread. http://b/64771555.
|
||||||
Runnable updateStats = () -> { updateStatsForCurrentUpstream(); };
|
Runnable updateStats = () -> {
|
||||||
|
updateStatsForCurrentUpstream();
|
||||||
|
};
|
||||||
if (Looper.myLooper() == mHandler.getLooper()) {
|
if (Looper.myLooper() == mHandler.getLooper()) {
|
||||||
updateStats.run();
|
updateStats.run();
|
||||||
} else {
|
} else {
|
||||||
@@ -358,6 +361,7 @@ public class OffloadController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Set current tethering upstream LinkProperties. */
|
||||||
public void setUpstreamLinkProperties(LinkProperties lp) {
|
public void setUpstreamLinkProperties(LinkProperties lp) {
|
||||||
if (!started() || Objects.equals(mUpstreamLinkProperties, lp)) return;
|
if (!started() || Objects.equals(mUpstreamLinkProperties, lp)) return;
|
||||||
|
|
||||||
@@ -376,6 +380,7 @@ public class OffloadController {
|
|||||||
pushUpstreamParameters(prevUpstream);
|
pushUpstreamParameters(prevUpstream);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Set local prefixes. */
|
||||||
public void setLocalPrefixes(Set<IpPrefix> localPrefixes) {
|
public void setLocalPrefixes(Set<IpPrefix> localPrefixes) {
|
||||||
mExemptPrefixes = localPrefixes;
|
mExemptPrefixes = localPrefixes;
|
||||||
|
|
||||||
@@ -383,6 +388,7 @@ public class OffloadController {
|
|||||||
computeAndPushLocalPrefixes(UpdateType.IF_NEEDED);
|
computeAndPushLocalPrefixes(UpdateType.IF_NEEDED);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Update current downstream LinkProperties. */
|
||||||
public void notifyDownstreamLinkProperties(LinkProperties lp) {
|
public void notifyDownstreamLinkProperties(LinkProperties lp) {
|
||||||
final String ifname = lp.getInterfaceName();
|
final String ifname = lp.getInterfaceName();
|
||||||
final LinkProperties oldLp = mDownstreams.put(ifname, new LinkProperties(lp));
|
final LinkProperties oldLp = mDownstreams.put(ifname, new LinkProperties(lp));
|
||||||
@@ -421,6 +427,7 @@ public class OffloadController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Remove downstream interface from offload hardware. */
|
||||||
public void removeDownstreamInterface(String ifname) {
|
public void removeDownstreamInterface(String ifname) {
|
||||||
final LinkProperties lp = mDownstreams.remove(ifname);
|
final LinkProperties lp = mDownstreams.remove(ifname);
|
||||||
if (lp == null) return;
|
if (lp == null) return;
|
||||||
@@ -481,7 +488,7 @@ public class OffloadController {
|
|||||||
iface, v4addr, v4gateway, (v6gateways.isEmpty() ? null : v6gateways));
|
iface, v4addr, v4gateway, (v6gateways.isEmpty() ? null : v6gateways));
|
||||||
|
|
||||||
if (!success) {
|
if (!success) {
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update stats after we've told the hardware to change routing so we don't miss packets.
|
// Update stats after we've told the hardware to change routing so we don't miss packets.
|
||||||
@@ -545,6 +552,7 @@ public class OffloadController {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Dump information. */
|
||||||
public void dump(IndentingPrintWriter pw) {
|
public void dump(IndentingPrintWriter pw) {
|
||||||
if (isOffloadDisabled()) {
|
if (isOffloadDisabled()) {
|
||||||
pw.println("Offload disabled");
|
pw.println("Offload disabled");
|
||||||
@@ -630,7 +638,7 @@ public class OffloadController {
|
|||||||
if (ip instanceof Inet4Address) {
|
if (ip instanceof Inet4Address) {
|
||||||
return (Inet4Address) ip;
|
return (Inet4Address) ip;
|
||||||
}
|
}
|
||||||
} catch (IllegalArgumentException iae) {}
|
} catch (IllegalArgumentException iae) { }
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -23,9 +23,9 @@ import android.hardware.tetheroffload.control.V1_0.ITetheringOffloadCallback;
|
|||||||
import android.hardware.tetheroffload.control.V1_0.NatTimeoutUpdate;
|
import android.hardware.tetheroffload.control.V1_0.NatTimeoutUpdate;
|
||||||
import android.hardware.tetheroffload.control.V1_0.NetworkProtocol;
|
import android.hardware.tetheroffload.control.V1_0.NetworkProtocol;
|
||||||
import android.hardware.tetheroffload.control.V1_0.OffloadCallbackEvent;
|
import android.hardware.tetheroffload.control.V1_0.OffloadCallbackEvent;
|
||||||
|
import android.net.util.SharedLog;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
import android.net.util.SharedLog;
|
|
||||||
import android.system.OsConstants;
|
import android.system.OsConstants;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -55,18 +55,34 @@ public class OffloadHardwareInterface {
|
|||||||
private TetheringOffloadCallback mTetheringOffloadCallback;
|
private TetheringOffloadCallback mTetheringOffloadCallback;
|
||||||
private ControlCallback mControlCallback;
|
private ControlCallback mControlCallback;
|
||||||
|
|
||||||
|
/** The callback to notify status of offload management process. */
|
||||||
public static class ControlCallback {
|
public static class ControlCallback {
|
||||||
|
/** Offload started. */
|
||||||
public void onStarted() {}
|
public void onStarted() {}
|
||||||
|
/**
|
||||||
|
* Offload stopped because an error has occurred in lower layer.
|
||||||
|
*/
|
||||||
public void onStoppedError() {}
|
public void onStoppedError() {}
|
||||||
|
/**
|
||||||
|
* Offload stopped because the device has moved to a bearer on which hardware offload is
|
||||||
|
* not supported. Subsequent calls to setUpstreamParameters and add/removeDownstream will
|
||||||
|
* likely fail and cannot be presumed to be saved inside of the hardware management process.
|
||||||
|
* Upon receiving #onSupportAvailable(), the caller should reprogram the hardware to begin
|
||||||
|
* offload again.
|
||||||
|
*/
|
||||||
public void onStoppedUnsupported() {}
|
public void onStoppedUnsupported() {}
|
||||||
|
/** Indicate that offload is able to proivde support for this time. */
|
||||||
public void onSupportAvailable() {}
|
public void onSupportAvailable() {}
|
||||||
|
/** Offload stopped because of usage limit reached. */
|
||||||
public void onStoppedLimitReached() {}
|
public void onStoppedLimitReached() {}
|
||||||
|
|
||||||
|
/** Indicate to update NAT timeout. */
|
||||||
public void onNatTimeoutUpdate(int proto,
|
public void onNatTimeoutUpdate(int proto,
|
||||||
String srcAddr, int srcPort,
|
String srcAddr, int srcPort,
|
||||||
String dstAddr, int dstPort) {}
|
String dstAddr, int dstPort) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** The object which records Tx/Rx forwarded bytes. */
|
||||||
public static class ForwardedStats {
|
public static class ForwardedStats {
|
||||||
public long rxBytes;
|
public long rxBytes;
|
||||||
public long txBytes;
|
public long txBytes;
|
||||||
@@ -76,11 +92,13 @@ public class OffloadHardwareInterface {
|
|||||||
txBytes = 0;
|
txBytes = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Add Tx/Rx bytes. */
|
||||||
public void add(ForwardedStats other) {
|
public void add(ForwardedStats other) {
|
||||||
rxBytes += other.rxBytes;
|
rxBytes += other.rxBytes;
|
||||||
txBytes += other.txBytes;
|
txBytes += other.txBytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Returns the string representation of this object. */
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return String.format("rx:%s tx:%s", rxBytes, txBytes);
|
return String.format("rx:%s tx:%s", rxBytes, txBytes);
|
||||||
}
|
}
|
||||||
@@ -91,14 +109,17 @@ public class OffloadHardwareInterface {
|
|||||||
mLog = log.forSubComponent(TAG);
|
mLog = log.forSubComponent(TAG);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Get default value indicating whether offload is supported. */
|
||||||
public int getDefaultTetherOffloadDisabled() {
|
public int getDefaultTetherOffloadDisabled() {
|
||||||
return DEFAULT_TETHER_OFFLOAD_DISABLED;
|
return DEFAULT_TETHER_OFFLOAD_DISABLED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Configure offload management process. */
|
||||||
public boolean initOffloadConfig() {
|
public boolean initOffloadConfig() {
|
||||||
return configOffload();
|
return configOffload();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Initialize the tethering offload HAL. */
|
||||||
public boolean initOffloadControl(ControlCallback controlCb) {
|
public boolean initOffloadControl(ControlCallback controlCb) {
|
||||||
mControlCallback = controlCb;
|
mControlCallback = controlCb;
|
||||||
|
|
||||||
@@ -125,8 +146,8 @@ public class OffloadHardwareInterface {
|
|||||||
mOffloadControl.initOffload(
|
mOffloadControl.initOffload(
|
||||||
mTetheringOffloadCallback,
|
mTetheringOffloadCallback,
|
||||||
(boolean success, String errMsg) -> {
|
(boolean success, String errMsg) -> {
|
||||||
results.success = success;
|
results.mSuccess = success;
|
||||||
results.errMsg = errMsg;
|
results.mErrMsg = errMsg;
|
||||||
});
|
});
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
record(logmsg, e);
|
record(logmsg, e);
|
||||||
@@ -134,9 +155,10 @@ public class OffloadHardwareInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
record(logmsg, results);
|
record(logmsg, results);
|
||||||
return results.success;
|
return results.mSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Stop IOffloadControl. */
|
||||||
public void stopOffloadControl() {
|
public void stopOffloadControl() {
|
||||||
if (mOffloadControl != null) {
|
if (mOffloadControl != null) {
|
||||||
try {
|
try {
|
||||||
@@ -154,6 +176,7 @@ public class OffloadHardwareInterface {
|
|||||||
mLog.log("stopOffloadControl()");
|
mLog.log("stopOffloadControl()");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Get Tx/Rx usage from last query. */
|
||||||
public ForwardedStats getForwardedStats(String upstream) {
|
public ForwardedStats getForwardedStats(String upstream) {
|
||||||
final String logmsg = String.format("getForwardedStats(%s)", upstream);
|
final String logmsg = String.format("getForwardedStats(%s)", upstream);
|
||||||
|
|
||||||
@@ -174,6 +197,7 @@ public class OffloadHardwareInterface {
|
|||||||
return stats;
|
return stats;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Set local prefixes to offload management process. */
|
||||||
public boolean setLocalPrefixes(ArrayList<String> localPrefixes) {
|
public boolean setLocalPrefixes(ArrayList<String> localPrefixes) {
|
||||||
final String logmsg = String.format("setLocalPrefixes([%s])",
|
final String logmsg = String.format("setLocalPrefixes([%s])",
|
||||||
String.join(",", localPrefixes));
|
String.join(",", localPrefixes));
|
||||||
@@ -182,8 +206,8 @@ public class OffloadHardwareInterface {
|
|||||||
try {
|
try {
|
||||||
mOffloadControl.setLocalPrefixes(localPrefixes,
|
mOffloadControl.setLocalPrefixes(localPrefixes,
|
||||||
(boolean success, String errMsg) -> {
|
(boolean success, String errMsg) -> {
|
||||||
results.success = success;
|
results.mSuccess = success;
|
||||||
results.errMsg = errMsg;
|
results.mErrMsg = errMsg;
|
||||||
});
|
});
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
record(logmsg, e);
|
record(logmsg, e);
|
||||||
@@ -191,9 +215,10 @@ public class OffloadHardwareInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
record(logmsg, results);
|
record(logmsg, results);
|
||||||
return results.success;
|
return results.mSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Set data limit value to offload management process. */
|
||||||
public boolean setDataLimit(String iface, long limit) {
|
public boolean setDataLimit(String iface, long limit) {
|
||||||
|
|
||||||
final String logmsg = String.format("setDataLimit(%s, %d)", iface, limit);
|
final String logmsg = String.format("setDataLimit(%s, %d)", iface, limit);
|
||||||
@@ -203,8 +228,8 @@ public class OffloadHardwareInterface {
|
|||||||
mOffloadControl.setDataLimit(
|
mOffloadControl.setDataLimit(
|
||||||
iface, limit,
|
iface, limit,
|
||||||
(boolean success, String errMsg) -> {
|
(boolean success, String errMsg) -> {
|
||||||
results.success = success;
|
results.mSuccess = success;
|
||||||
results.errMsg = errMsg;
|
results.mErrMsg = errMsg;
|
||||||
});
|
});
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
record(logmsg, e);
|
record(logmsg, e);
|
||||||
@@ -212,9 +237,10 @@ public class OffloadHardwareInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
record(logmsg, results);
|
record(logmsg, results);
|
||||||
return results.success;
|
return results.mSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Set upstream parameters to offload management process. */
|
||||||
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;
|
iface = (iface != null) ? iface : NO_INTERFACE_NAME;
|
||||||
@@ -230,8 +256,8 @@ public class OffloadHardwareInterface {
|
|||||||
mOffloadControl.setUpstreamParameters(
|
mOffloadControl.setUpstreamParameters(
|
||||||
iface, v4addr, v4gateway, v6gws,
|
iface, v4addr, v4gateway, v6gws,
|
||||||
(boolean success, String errMsg) -> {
|
(boolean success, String errMsg) -> {
|
||||||
results.success = success;
|
results.mSuccess = success;
|
||||||
results.errMsg = errMsg;
|
results.mErrMsg = errMsg;
|
||||||
});
|
});
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
record(logmsg, e);
|
record(logmsg, e);
|
||||||
@@ -239,9 +265,10 @@ public class OffloadHardwareInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
record(logmsg, results);
|
record(logmsg, results);
|
||||||
return results.success;
|
return results.mSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Add downstream prefix to offload management process. */
|
||||||
public boolean addDownstreamPrefix(String ifname, String prefix) {
|
public boolean addDownstreamPrefix(String ifname, String prefix) {
|
||||||
final String logmsg = String.format("addDownstreamPrefix(%s, %s)", ifname, prefix);
|
final String logmsg = String.format("addDownstreamPrefix(%s, %s)", ifname, prefix);
|
||||||
|
|
||||||
@@ -249,8 +276,8 @@ public class OffloadHardwareInterface {
|
|||||||
try {
|
try {
|
||||||
mOffloadControl.addDownstream(ifname, prefix,
|
mOffloadControl.addDownstream(ifname, prefix,
|
||||||
(boolean success, String errMsg) -> {
|
(boolean success, String errMsg) -> {
|
||||||
results.success = success;
|
results.mSuccess = success;
|
||||||
results.errMsg = errMsg;
|
results.mErrMsg = errMsg;
|
||||||
});
|
});
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
record(logmsg, e);
|
record(logmsg, e);
|
||||||
@@ -258,9 +285,10 @@ public class OffloadHardwareInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
record(logmsg, results);
|
record(logmsg, results);
|
||||||
return results.success;
|
return results.mSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Remove downstream prefix from offload management process. */
|
||||||
public boolean removeDownstreamPrefix(String ifname, String prefix) {
|
public boolean removeDownstreamPrefix(String ifname, String prefix) {
|
||||||
final String logmsg = String.format("removeDownstreamPrefix(%s, %s)", ifname, prefix);
|
final String logmsg = String.format("removeDownstreamPrefix(%s, %s)", ifname, prefix);
|
||||||
|
|
||||||
@@ -268,8 +296,8 @@ public class OffloadHardwareInterface {
|
|||||||
try {
|
try {
|
||||||
mOffloadControl.removeDownstream(ifname, prefix,
|
mOffloadControl.removeDownstream(ifname, prefix,
|
||||||
(boolean success, String errMsg) -> {
|
(boolean success, String errMsg) -> {
|
||||||
results.success = success;
|
results.mSuccess = success;
|
||||||
results.errMsg = errMsg;
|
results.mErrMsg = errMsg;
|
||||||
});
|
});
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
record(logmsg, e);
|
record(logmsg, e);
|
||||||
@@ -277,7 +305,7 @@ public class OffloadHardwareInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
record(logmsg, results);
|
record(logmsg, results);
|
||||||
return results.success;
|
return results.mSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void record(String msg, Throwable t) {
|
private void record(String msg, Throwable t) {
|
||||||
@@ -286,7 +314,7 @@ public class OffloadHardwareInterface {
|
|||||||
|
|
||||||
private void record(String msg, CbResults results) {
|
private void record(String msg, CbResults results) {
|
||||||
final String logmsg = msg + YIELDS + results;
|
final String logmsg = msg + YIELDS + results;
|
||||||
if (!results.success) {
|
if (!results.mSuccess) {
|
||||||
mLog.e(logmsg);
|
mLog.e(logmsg);
|
||||||
} else {
|
} else {
|
||||||
mLog.log(logmsg);
|
mLog.log(logmsg);
|
||||||
@@ -298,7 +326,7 @@ public class OffloadHardwareInterface {
|
|||||||
public final ControlCallback controlCb;
|
public final ControlCallback controlCb;
|
||||||
public final SharedLog log;
|
public final SharedLog log;
|
||||||
|
|
||||||
public TetheringOffloadCallback(Handler h, ControlCallback cb, SharedLog sharedLog) {
|
TetheringOffloadCallback(Handler h, ControlCallback cb, SharedLog sharedLog) {
|
||||||
handler = h;
|
handler = h;
|
||||||
controlCb = cb;
|
controlCb = cb;
|
||||||
log = sharedLog;
|
log = sharedLog;
|
||||||
@@ -332,7 +360,7 @@ public class OffloadHardwareInterface {
|
|||||||
@Override
|
@Override
|
||||||
public void updateTimeout(NatTimeoutUpdate params) {
|
public void updateTimeout(NatTimeoutUpdate params) {
|
||||||
handler.post(() -> {
|
handler.post(() -> {
|
||||||
controlCb.onNatTimeoutUpdate(
|
controlCb.onNatTimeoutUpdate(
|
||||||
networkProtocolToOsConstant(params.proto),
|
networkProtocolToOsConstant(params.proto),
|
||||||
params.src.addr, uint16(params.src.port),
|
params.src.addr, uint16(params.src.port),
|
||||||
params.dst.addr, uint16(params.dst.port));
|
params.dst.addr, uint16(params.dst.port));
|
||||||
@@ -352,15 +380,15 @@ public class OffloadHardwareInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static class CbResults {
|
private static class CbResults {
|
||||||
boolean success;
|
boolean mSuccess;
|
||||||
String errMsg;
|
String mErrMsg;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
if (success) {
|
if (mSuccess) {
|
||||||
return "ok";
|
return "ok";
|
||||||
} else {
|
} else {
|
||||||
return "fail: " + errMsg;
|
return "fail: " + mErrMsg;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -25,6 +25,7 @@ android_test {
|
|||||||
static_libs: [
|
static_libs: [
|
||||||
"androidx.test.rules",
|
"androidx.test.rules",
|
||||||
"frameworks-base-testutils",
|
"frameworks-base-testutils",
|
||||||
|
"net-tests-utils",
|
||||||
"mockito-target-extended-minus-junit4",
|
"mockito-target-extended-minus-junit4",
|
||||||
"TetheringApiCurrentLib",
|
"TetheringApiCurrentLib",
|
||||||
"testables",
|
"testables",
|
||||||
@@ -46,6 +47,7 @@ filegroup {
|
|||||||
name: "tethering-tests-src",
|
name: "tethering-tests-src",
|
||||||
srcs: [
|
srcs: [
|
||||||
"src/com/android/server/connectivity/tethering/EntitlementManagerTest.java",
|
"src/com/android/server/connectivity/tethering/EntitlementManagerTest.java",
|
||||||
|
"src/com/android/server/connectivity/tethering/OffloadControllerTest.java",
|
||||||
"src/com/android/server/connectivity/tethering/TetheringConfigurationTest.java",
|
"src/com/android/server/connectivity/tethering/TetheringConfigurationTest.java",
|
||||||
"src/com/android/server/connectivity/tethering/UpstreamNetworkMonitorTest.java",
|
"src/com/android/server/connectivity/tethering/UpstreamNetworkMonitorTest.java",
|
||||||
"src/android/net/dhcp/DhcpServingParamsParcelExtTest.java",
|
"src/android/net/dhcp/DhcpServingParamsParcelExtTest.java",
|
||||||
|
|||||||
@@ -26,10 +26,10 @@ import static android.provider.Settings.Global.TETHER_OFFLOAD_DISABLED;
|
|||||||
|
|
||||||
import static com.android.server.connectivity.tethering.OffloadHardwareInterface.ForwardedStats;
|
import static com.android.server.connectivity.tethering.OffloadHardwareInterface.ForwardedStats;
|
||||||
import static com.android.testutils.MiscAssertsKt.assertContainsAll;
|
import static com.android.testutils.MiscAssertsKt.assertContainsAll;
|
||||||
|
import static com.android.testutils.MiscAssertsKt.assertThrows;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.junit.Assert.fail;
|
|
||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.Matchers.any;
|
||||||
import static org.mockito.Matchers.anyLong;
|
import static org.mockito.Matchers.anyLong;
|
||||||
import static org.mockito.Matchers.anyObject;
|
import static org.mockito.Matchers.anyObject;
|
||||||
@@ -148,10 +148,8 @@ public class OffloadControllerTest {
|
|||||||
public void testNoSettingsValueDefaultDisabledDoesNotStart() throws Exception {
|
public void testNoSettingsValueDefaultDisabledDoesNotStart() throws Exception {
|
||||||
setupFunctioningHardwareInterface();
|
setupFunctioningHardwareInterface();
|
||||||
when(mHardware.getDefaultTetherOffloadDisabled()).thenReturn(1);
|
when(mHardware.getDefaultTetherOffloadDisabled()).thenReturn(1);
|
||||||
try {
|
assertThrows(SettingNotFoundException.class, () ->
|
||||||
Settings.Global.getInt(mContentResolver, TETHER_OFFLOAD_DISABLED);
|
Settings.Global.getInt(mContentResolver, TETHER_OFFLOAD_DISABLED));
|
||||||
fail();
|
|
||||||
} catch (SettingNotFoundException expected) {}
|
|
||||||
|
|
||||||
final OffloadController offload = makeOffloadController();
|
final OffloadController offload = makeOffloadController();
|
||||||
offload.start();
|
offload.start();
|
||||||
@@ -168,10 +166,8 @@ public class OffloadControllerTest {
|
|||||||
public void testNoSettingsValueDefaultEnabledDoesStart() throws Exception {
|
public void testNoSettingsValueDefaultEnabledDoesStart() throws Exception {
|
||||||
setupFunctioningHardwareInterface();
|
setupFunctioningHardwareInterface();
|
||||||
when(mHardware.getDefaultTetherOffloadDisabled()).thenReturn(0);
|
when(mHardware.getDefaultTetherOffloadDisabled()).thenReturn(0);
|
||||||
try {
|
assertThrows(SettingNotFoundException.class, () ->
|
||||||
Settings.Global.getInt(mContentResolver, TETHER_OFFLOAD_DISABLED);
|
Settings.Global.getInt(mContentResolver, TETHER_OFFLOAD_DISABLED));
|
||||||
fail();
|
|
||||||
} catch (SettingNotFoundException expected) {}
|
|
||||||
|
|
||||||
final OffloadController offload = makeOffloadController();
|
final OffloadController offload = makeOffloadController();
|
||||||
offload.start();
|
offload.start();
|
||||||
@@ -23,7 +23,6 @@ cc_library_static {
|
|||||||
"com_android_server_AlarmManagerService.cpp",
|
"com_android_server_AlarmManagerService.cpp",
|
||||||
"com_android_server_am_BatteryStatsService.cpp",
|
"com_android_server_am_BatteryStatsService.cpp",
|
||||||
"com_android_server_connectivity_Vpn.cpp",
|
"com_android_server_connectivity_Vpn.cpp",
|
||||||
"com_android_server_connectivity_tethering_OffloadHardwareInterface.cpp",
|
|
||||||
"com_android_server_ConsumerIrService.cpp",
|
"com_android_server_ConsumerIrService.cpp",
|
||||||
"com_android_server_devicepolicy_CryptoTestHelper.cpp",
|
"com_android_server_devicepolicy_CryptoTestHelper.cpp",
|
||||||
"com_android_server_HardwarePropertiesManagerService.cpp",
|
"com_android_server_HardwarePropertiesManagerService.cpp",
|
||||||
@@ -54,6 +53,7 @@ cc_library_static {
|
|||||||
"com_android_server_am_LowMemDetector.cpp",
|
"com_android_server_am_LowMemDetector.cpp",
|
||||||
"onload.cpp",
|
"onload.cpp",
|
||||||
":lib_networkStatsFactory_native",
|
":lib_networkStatsFactory_native",
|
||||||
|
":tethering-jni-srcs",
|
||||||
],
|
],
|
||||||
|
|
||||||
include_dirs: [
|
include_dirs: [
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ filegroup {
|
|||||||
"java/android/net/ConnectivityModuleConnector.java",
|
"java/android/net/ConnectivityModuleConnector.java",
|
||||||
"java/android/net/NetworkStackClient.java",
|
"java/android/net/NetworkStackClient.java",
|
||||||
"java/android/net/ip/InterfaceController.java",
|
"java/android/net/ip/InterfaceController.java",
|
||||||
|
"java/android/net/netlink/*.java",
|
||||||
"java/android/net/util/InterfaceParams.java",
|
"java/android/net/util/InterfaceParams.java",
|
||||||
"java/android/net/util/NetdService.java",
|
"java/android/net/util/NetdService.java",
|
||||||
"java/android/net/util/NetworkConstants.java",
|
"java/android/net/util/NetworkConstants.java",
|
||||||
|
|||||||
Reference in New Issue
Block a user