diff options
author | Ningyuan Wang <nywang@google.com> | 2017-02-10 17:55:02 -0800 |
---|---|---|
committer | Ningyuan Wang <nywang@google.com> | 2017-02-13 15:29:48 -0800 |
commit | 11d07764318e2491003346ce88047862fea45b4f (patch) | |
tree | 5def8181d56ccf06305fc7b6f0490461b8848c2f /service | |
parent | 65ca369420a66fbb44610a37e93cc1a519ac2a1c (diff) |
Use NativeUtil methods for WifiStateMachine
Bug: 35154749
Test: compile, unit tests
Change-Id: I0e8839059017c873ae64a0b84ddf42ce83c93a87
Diffstat (limited to 'service')
-rw-r--r-- | service/java/com/android/server/wifi/WifiStateMachine.java | 50 |
1 files changed, 19 insertions, 31 deletions
diff --git a/service/java/com/android/server/wifi/WifiStateMachine.java b/service/java/com/android/server/wifi/WifiStateMachine.java index 644ea22f0..5d6f201e4 100644 --- a/service/java/com/android/server/wifi/WifiStateMachine.java +++ b/service/java/com/android/server/wifi/WifiStateMachine.java @@ -112,6 +112,7 @@ import com.android.server.wifi.hotspot2.PasspointManager; import com.android.server.wifi.hotspot2.Utils; import com.android.server.wifi.hotspot2.WnmData; import com.android.server.wifi.p2p.WifiP2pServiceImpl; +import com.android.server.wifi.util.NativeUtil; import com.android.server.wifi.util.TelephonyUtil; import com.android.server.wifi.util.TelephonyUtil.SimAuthRequestData; import com.android.server.wifi.util.TelephonyUtil.SimAuthResponseData; @@ -3447,19 +3448,6 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiRss mWifiNative.disconnect(); } - private byte[] macAddressFromString(String macString) { - String[] macBytes = macString.split(":"); - if (macBytes.length != 6) { - throw new IllegalArgumentException("MAC address should be 6 bytes long!"); - } - byte[] mac = new byte[6]; - for (int i = 0; i < macBytes.length; i++) { - Integer hexVal = Integer.parseInt(macBytes[i], 16); - mac[i] = hexVal.byteValue(); - } - return mac; - } - /* * Read a MAC address in /proc/arp/table, used by WifistateMachine * so as to record MAC address of default gateway. @@ -6210,26 +6198,26 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiRss } break; case CMD_START_IP_PACKET_OFFLOAD: { - int slot = message.arg1; - int intervalSeconds = message.arg2; - KeepalivePacketData pkt = (KeepalivePacketData) message.obj; - byte[] dstMac; - try { - InetAddress gateway = RouteInfo.selectBestRoute( - mLinkProperties.getRoutes(), pkt.dstAddress).getGateway(); - String dstMacStr = macAddressFromRoute(gateway.getHostAddress()); - dstMac = macAddressFromString(dstMacStr); - } catch (NullPointerException|IllegalArgumentException e) { - loge("Can't find MAC address for next hop to " + pkt.dstAddress); - mNetworkAgent.onPacketKeepaliveEvent(slot, - ConnectivityManager.PacketKeepalive.ERROR_INVALID_IP_ADDRESS); - break; - } - pkt.dstMac = dstMac; - int result = startWifiIPPacketOffload(slot, pkt, intervalSeconds); - mNetworkAgent.onPacketKeepaliveEvent(slot, result); + int slot = message.arg1; + int intervalSeconds = message.arg2; + KeepalivePacketData pkt = (KeepalivePacketData) message.obj; + byte[] dstMac; + try { + InetAddress gateway = RouteInfo.selectBestRoute( + mLinkProperties.getRoutes(), pkt.dstAddress).getGateway(); + String dstMacStr = macAddressFromRoute(gateway.getHostAddress()); + dstMac = NativeUtil.macAddressToByteArray(dstMacStr); + } catch (NullPointerException | IllegalArgumentException e) { + loge("Can't find MAC address for next hop to " + pkt.dstAddress); + mNetworkAgent.onPacketKeepaliveEvent(slot, + ConnectivityManager.PacketKeepalive.ERROR_INVALID_IP_ADDRESS); break; } + pkt.dstMac = dstMac; + int result = startWifiIPPacketOffload(slot, pkt, intervalSeconds); + mNetworkAgent.onPacketKeepaliveEvent(slot, result); + break; + } default: return NOT_HANDLED; } |