Check P2P channel before requesting network info

WifiP2pSettings requests network info from WifiP2pManager whenever it
gets onDeviceInfoAvailable, but sChannel may be null causing an
IllegalArgumentException. Check that sChannel is not null before
requesting network info.

Bug: 289004627
Test: atest WifiP2pSettingsTest
Change-Id: Ied8c3f8a894683d7b8e368e5c52343adb7d05e4b
This commit is contained in:
Quang Anh Luong
2023-06-30 12:21:30 +09:00
parent c97fe1a27f
commit 36d71f8785
2 changed files with 11 additions and 0 deletions

View File

@@ -617,6 +617,9 @@ public class WifiP2pSettings extends DashboardFragment
}
private void onDeviceAvailable() {
if (mWifiP2pManager == null || sChannel == null) {
return;
}
mWifiP2pManager.requestNetworkInfo(sChannel, networkInfo -> {
if (sChannel == null) return;
mWifiP2pManager.requestConnectionInfo(sChannel, wifip2pinfo -> {

View File

@@ -21,6 +21,7 @@ import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
@@ -150,6 +151,13 @@ public class WifiP2pSettingsTest {
verify(mWifiP2pManager, times(1)).requestNetworkInfo(any(), any());
}
@Test
public void onDeviceInfoAvailable_nullChannel_shouldBeIgnored() {
mFragment.sChannel = null;
mFragment.onDeviceInfoAvailable(mock(WifiP2pDevice.class));
verify(mWifiP2pManager, never()).requestNetworkInfo(any(), any());
}
@Test
public void beSearching_getP2pStateDisabledIntent_shouldBeFalse() {
final Bundle bundle = new Bundle();