diff --git a/wifi/java/android/net/wifi/WifiInfo.java b/wifi/java/android/net/wifi/WifiInfo.java index 1e03891019f6..e37a85670972 100644 --- a/wifi/java/android/net/wifi/WifiInfo.java +++ b/wifi/java/android/net/wifi/WifiInfo.java @@ -17,14 +17,14 @@ package android.net.wifi; import android.annotation.UnsupportedAppUsage; -import android.os.Parcelable; -import android.os.Parcel; import android.net.NetworkInfo.DetailedState; import android.net.NetworkUtils; +import android.os.Parcel; +import android.os.Parcelable; import android.text.TextUtils; -import java.net.InetAddress; import java.net.Inet4Address; +import java.net.InetAddress; import java.net.UnknownHostException; import java.util.EnumMap; import java.util.Locale; @@ -540,9 +540,13 @@ public class WifiInfo implements Parcelable { dest.writeInt(mMeteredHint ? 1 : 0); dest.writeInt(mEphemeral ? 1 : 0); dest.writeInt(score); + dest.writeLong(txSuccess); dest.writeDouble(txSuccessRate); + dest.writeLong(txRetries); dest.writeDouble(txRetriesRate); + dest.writeLong(txBad); dest.writeDouble(txBadRate); + dest.writeLong(rxSuccess); dest.writeDouble(rxSuccessRate); mSupplicantState.writeToParcel(dest, flags); } @@ -570,9 +574,13 @@ public class WifiInfo implements Parcelable { info.mMeteredHint = in.readInt() != 0; info.mEphemeral = in.readInt() != 0; info.score = in.readInt(); + info.txSuccess = in.readLong(); info.txSuccessRate = in.readDouble(); + info.txRetries = in.readLong(); info.txRetriesRate = in.readDouble(); + info.txBad = in.readLong(); info.txBadRate = in.readDouble(); + info.rxSuccess = in.readLong(); info.rxSuccessRate = in.readDouble(); info.mSupplicantState = SupplicantState.CREATOR.createFromParcel(in); return info; diff --git a/wifi/tests/src/android/net/wifi/WifiInfoTest.java b/wifi/tests/src/android/net/wifi/WifiInfoTest.java new file mode 100644 index 000000000000..f5a8b29167bf --- /dev/null +++ b/wifi/tests/src/android/net/wifi/WifiInfoTest.java @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2018 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.wifi; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import android.os.Parcel; +import android.support.test.filters.SmallTest; + +import org.junit.Test; + +/** + * Unit tests for {@link android.net.wifi.WifiInfo}. + */ +@SmallTest +public class WifiInfoTest { + private static final long TEST_TX_SUCCESS = 1; + private static final long TEST_TX_RETRIES = 2; + private static final long TEST_TX_BAD = 3; + private static final long TEST_RX_SUCCESS = 4; + + /** + * Verify parcel write/read with WifiInfo. + */ + @Test + public void testWifiInfoParcelWriteRead() throws Exception { + WifiInfo writeWifiInfo = new WifiInfo(); + writeWifiInfo.txSuccess = TEST_TX_SUCCESS; + writeWifiInfo.txRetries = TEST_TX_RETRIES; + writeWifiInfo.txBad = TEST_TX_BAD; + writeWifiInfo.rxSuccess = TEST_RX_SUCCESS; + + Parcel parcel = Parcel.obtain(); + writeWifiInfo.writeToParcel(parcel, 0); + // Rewind the pointer to the head of the parcel. + parcel.setDataPosition(0); + WifiInfo readWifiInfo = WifiInfo.CREATOR.createFromParcel(parcel); + + assertNotNull(readWifiInfo); + assertEquals(TEST_TX_SUCCESS, readWifiInfo.txSuccess); + assertEquals(TEST_TX_RETRIES, readWifiInfo.txRetries); + assertEquals(TEST_TX_BAD, readWifiInfo.txBad); + assertEquals(TEST_RX_SUCCESS, readWifiInfo.rxSuccess); + } +}