Merge "p2p: Close the channel when onStop is called." into tm-dev

This commit is contained in:
TreeHugger Robot
2022-03-07 06:40:05 +00:00
committed by Android (Google) Code Review
2 changed files with 15 additions and 3 deletions

View File

@@ -375,13 +375,20 @@ public class WifiP2pSettings extends DashboardFragment
super.onPause();
if (mWifiP2pManager != null && mChannel != null) {
mWifiP2pManager.stopPeerDiscovery(mChannel, null);
}
getActivity().unregisterReceiver(mReceiver);
}
@Override
public void onStop() {
super.onStop();
if (mWifiP2pManager != null && mChannel != null) {
if (!mLastGroupFormed) {
// Close the channel when p2p doesn't connected.
mChannel.close();
mChannel = null;
}
}
getActivity().unregisterReceiver(mReceiver);
}
@Override

View File

@@ -319,12 +319,18 @@ public class WifiP2pSettingsTest {
assertThat(mFragment.onCreateDialog(-1 /* id */)).isNull();
}
@Test
public void onStop_notLastGroupFormed_shouldCloseChannel() {
mFragment.onStop();
assertThat(mFragment.mChannel).isNull();
}
@Test
public void peerDiscovery_whenOnPause_shouldStop() {
mFragment.onPause();
verify(mWifiP2pManager, times(1)).stopPeerDiscovery(any(), any());
assertThat(mFragment.mChannel).isNull();
}
@Test
@@ -332,7 +338,6 @@ public class WifiP2pSettingsTest {
mFragment.onPause();
verify(mWifiP2pManager, times(1)).stopPeerDiscovery(any(), any());
assertThat(mFragment.mChannel).isNull();
mFragment.onResume();
assertThat(mFragment.mChannel).isNotNull();