Fix some fields in WifiInfo are not written into Parcel
Some fields in WifiInfo are not written into Parcel so these fields will not be carried over process boundaries. cherry-picked from: ag/4820524 Bug: 79889311 Test: compile & verified fields are filled from app Test: Unit tests Change-Id: I0d8f453c49212fc6d12d28537454c9a9657c1ef7
This commit is contained in:
parent
c5a00e0957
commit
f53446deca
@ -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;
|
||||
|
60
wifi/tests/src/android/net/wifi/WifiInfoTest.java
Normal file
60
wifi/tests/src/android/net/wifi/WifiInfoTest.java
Normal file
@ -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);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user