Merge "Wakeup packet mark/mask configuration option" into oc-dr1-dev

This commit is contained in:
Lorenzo Colitti
2017-07-06 15:19:15 +00:00
committed by Android (Google) Code Review
3 changed files with 36 additions and 17 deletions

View File

@@ -284,6 +284,13 @@
Settings.Global.NETWORK_AVOID_BAD_WIFI. This is the default value of that setting. --> Settings.Global.NETWORK_AVOID_BAD_WIFI. This is the default value of that setting. -->
<integer translatable="false" name="config_networkAvoidBadWifi">1</integer> <integer translatable="false" name="config_networkAvoidBadWifi">1</integer>
<!-- If the hardware supports specially marking packets that caused a wakeup of the
main CPU, set this value to the mark used. -->
<integer name="config_networkWakeupPacketMark">0</integer>
<!-- Mask to use when checking skb mark defined in config_networkWakeupPacketMark above. -->
<integer name="config_networkWakeupPacketMask">0</integer>
<!-- Default value for ConnectivityManager.getMultipathPreference() on metered networks. Actual <!-- Default value for ConnectivityManager.getMultipathPreference() on metered networks. Actual
device behaviour is controlled by Settings.Global.NETWORK_METERED_MULTIPATH_PREFERENCE. device behaviour is controlled by Settings.Global.NETWORK_METERED_MULTIPATH_PREFERENCE.
This is the default value of that setting. --> This is the default value of that setting. -->

View File

@@ -1838,6 +1838,8 @@
<java-symbol type="integer" name="config_networkNotifySwitchType" /> <java-symbol type="integer" name="config_networkNotifySwitchType" />
<java-symbol type="array" name="config_networkNotifySwitches" /> <java-symbol type="array" name="config_networkNotifySwitches" />
<java-symbol type="integer" name="config_networkAvoidBadWifi" /> <java-symbol type="integer" name="config_networkAvoidBadWifi" />
<java-symbol type="integer" name="config_networkWakeupPacketMark" />
<java-symbol type="integer" name="config_networkWakeupPacketMask" />
<java-symbol type="integer" name="config_networkMeteredMultipathPreference" /> <java-symbol type="integer" name="config_networkMeteredMultipathPreference" />
<java-symbol type="integer" name="config_notificationsBatteryFullARGB" /> <java-symbol type="integer" name="config_notificationsBatteryFullARGB" />
<java-symbol type="integer" name="config_notificationsBatteryLedOff" /> <java-symbol type="integer" name="config_notificationsBatteryLedOff" />

View File

@@ -210,13 +210,6 @@ public class ConnectivityService extends IConnectivityManager.Stub
// See Settings.Secure.CONNECTIVITY_RELEASE_PENDING_INTENT_DELAY_MS // See Settings.Secure.CONNECTIVITY_RELEASE_PENDING_INTENT_DELAY_MS
private final int mReleasePendingIntentDelayMs; private final int mReleasePendingIntentDelayMs;
// Driver specific constants used to select packets received via
// WiFi that caused the phone to exit sleep state. Currently there
// is only one kernel implementation so we can get away with
// constants.
private static final int mWakeupPacketMark = 0x80000000;
private static final int mWakeupPacketMask = 0x80000000;
private MockableSystemProperties mSystemProperties; private MockableSystemProperties mSystemProperties;
private Tethering mTethering; private Tethering mTethering;
@@ -2282,6 +2275,10 @@ public class ConnectivityService extends IConnectivityManager.Stub
notifyNetworkCallbacks(nai, ConnectivityManager.CALLBACK_LOST); notifyNetworkCallbacks(nai, ConnectivityManager.CALLBACK_LOST);
mKeepaliveTracker.handleStopAllKeepalives(nai, mKeepaliveTracker.handleStopAllKeepalives(nai,
ConnectivityManager.PacketKeepalive.ERROR_INVALID_NETWORK); ConnectivityManager.PacketKeepalive.ERROR_INVALID_NETWORK);
for (String iface : nai.linkProperties.getAllInterfaceNames()) {
// Disable wakeup packet monitoring for each interface.
wakeupModifyInterface(iface, nai.networkCapabilities, false);
}
nai.networkMonitor.sendMessage(NetworkMonitor.CMD_NETWORK_DISCONNECTED); nai.networkMonitor.sendMessage(NetworkMonitor.CMD_NETWORK_DISCONNECTED);
mNetworkAgentInfos.remove(msg.replyTo); mNetworkAgentInfos.remove(msg.replyTo);
updateClat(null, nai.linkProperties, nai); updateClat(null, nai.linkProperties, nai);
@@ -4401,22 +4398,35 @@ public class ConnectivityService extends IConnectivityManager.Stub
} }
} }
private void wakeupAddInterface(String iface, NetworkCapabilities caps) throws RemoteException { private void wakeupModifyInterface(String iface, NetworkCapabilities caps, boolean add) {
// Marks are only available on WiFi interaces. Checking for // Marks are only available on WiFi interaces. Checking for
// marks on unsupported interfaces is harmless. // marks on unsupported interfaces is harmless.
if (!caps.hasTransport(NetworkCapabilities.TRANSPORT_WIFI)) { if (!caps.hasTransport(NetworkCapabilities.TRANSPORT_WIFI)) {
return; return;
} }
mNetd.getNetdService().wakeupAddInterface(
iface, "iface:" + iface, mWakeupPacketMark, mWakeupPacketMask);
}
private void wakeupDelInterface(String iface, NetworkCapabilities caps) throws RemoteException { int mark = mContext.getResources().getInteger(
if (!caps.hasTransport(NetworkCapabilities.TRANSPORT_WIFI)) { com.android.internal.R.integer.config_networkWakeupPacketMark);
int mask = mContext.getResources().getInteger(
com.android.internal.R.integer.config_networkWakeupPacketMask);
// Mask/mark of zero will not detect anything interesting.
// Don't install rules unless both values are nonzero.
if (mark == 0 || mask == 0) {
return; return;
} }
mNetd.getNetdService().wakeupDelInterface(
iface, "iface:" + iface, mWakeupPacketMark, mWakeupPacketMask); final String prefix = "iface:" + iface;
try {
if (add) {
mNetd.getNetdService().wakeupAddInterface(iface, prefix, mark, mask);
} else {
mNetd.getNetdService().wakeupDelInterface(iface, prefix, mark, mask);
}
} catch (Exception e) {
loge("Exception modifying wakeup packet monitoring: " + e);
}
} }
private void updateInterfaces(LinkProperties newLp, LinkProperties oldLp, int netId, private void updateInterfaces(LinkProperties newLp, LinkProperties oldLp, int netId,
@@ -4431,7 +4441,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
try { try {
if (DBG) log("Adding iface " + iface + " to network " + netId); if (DBG) log("Adding iface " + iface + " to network " + netId);
mNetd.addInterfaceToNetwork(iface, netId); mNetd.addInterfaceToNetwork(iface, netId);
wakeupAddInterface(iface, caps); wakeupModifyInterface(iface, caps, true);
} catch (Exception e) { } catch (Exception e) {
loge("Exception adding interface: " + e); loge("Exception adding interface: " + e);
} }
@@ -4439,8 +4449,8 @@ public class ConnectivityService extends IConnectivityManager.Stub
for (String iface : interfaceDiff.removed) { for (String iface : interfaceDiff.removed) {
try { try {
if (DBG) log("Removing iface " + iface + " from network " + netId); if (DBG) log("Removing iface " + iface + " from network " + netId);
wakeupModifyInterface(iface, caps, false);
mNetd.removeInterfaceFromNetwork(iface, netId); mNetd.removeInterfaceFromNetwork(iface, netId);
wakeupDelInterface(iface, caps);
} catch (Exception e) { } catch (Exception e) {
loge("Exception removing interface: " + e); loge("Exception removing interface: " + e);
} }