Loading src/com/android/settings/wifi/p2p/WifiP2pSettings.java +29 −29 Original line number Diff line number Diff line Loading @@ -76,7 +76,7 @@ public class WifiP2pSettings extends DashboardFragment private final IntentFilter mIntentFilter = new IntentFilter(); @VisibleForTesting WifiP2pManager mWifiP2pManager; @VisibleForTesting WifiP2pManager.Channel mChannel; @VisibleForTesting static WifiP2pManager.Channel sChannel; @VisibleForTesting OnClickListener mRenameListener; @VisibleForTesting OnClickListener mDisconnectListener; @VisibleForTesting OnClickListener mCancelConnectListener; Loading Loading @@ -150,8 +150,8 @@ public class WifiP2pSettings extends DashboardFragment // Requesting our own device info as an app holding the NETWORK_SETTINGS permission // ensures that the MAC address will be available in the result. if (DBG) Log.d(TAG, "This device changed. Requesting device info."); if (mWifiP2pManager != null && mChannel != null) { mWifiP2pManager.requestDeviceInfo(mChannel, WifiP2pSettings.this); if (mWifiP2pManager != null && sChannel != null) { mWifiP2pManager.requestDeviceInfo(sChannel, WifiP2pSettings.this); } } else if (WifiP2pManager.WIFI_P2P_DISCOVERY_CHANGED_ACTION.equals(action)) { int discoveryState = intent.getIntExtra(WifiP2pManager.EXTRA_DISCOVERY_STATE, Loading @@ -163,8 +163,8 @@ public class WifiP2pSettings extends DashboardFragment updateSearchMenu(false); } } else if (WifiP2pManager.ACTION_WIFI_P2P_PERSISTENT_GROUPS_CHANGED.equals(action)) { if (mWifiP2pManager != null && mChannel != null) { mWifiP2pManager.requestPersistentGroupInfo(mChannel, WifiP2pSettings.this); if (mWifiP2pManager != null && sChannel != null) { mWifiP2pManager.requestPersistentGroupInfo(sChannel, WifiP2pSettings.this); } } } Loading Loading @@ -239,7 +239,7 @@ public class WifiP2pSettings extends DashboardFragment @Override public void onClick(DialogInterface dialog, int which) { if (which == DialogInterface.BUTTON_POSITIVE) { if (mWifiP2pManager != null && mChannel != null) { if (mWifiP2pManager != null && sChannel != null) { String name = mDeviceNameText.getText().toString(); if (name != null) { for (int i = 0; i < name.length(); i++) { Loading @@ -253,7 +253,7 @@ public class WifiP2pSettings extends DashboardFragment } } } mWifiP2pManager.setDeviceName(mChannel, mWifiP2pManager.setDeviceName(sChannel, mDeviceNameText.getText().toString(), new WifiP2pManager.ActionListener() { public void onSuccess() { Loading @@ -275,8 +275,8 @@ public class WifiP2pSettings extends DashboardFragment @Override public void onClick(DialogInterface dialog, int which) { if (which == DialogInterface.BUTTON_POSITIVE) { if (mWifiP2pManager != null && mChannel != null) { mWifiP2pManager.removeGroup(mChannel, new WifiP2pManager.ActionListener() { if (mWifiP2pManager != null && sChannel != null) { mWifiP2pManager.removeGroup(sChannel, new WifiP2pManager.ActionListener() { public void onSuccess() { if (DBG) Log.d(TAG, " remove group success"); } Loading @@ -294,8 +294,8 @@ public class WifiP2pSettings extends DashboardFragment @Override public void onClick(DialogInterface dialog, int which) { if (which == DialogInterface.BUTTON_POSITIVE) { if (mWifiP2pManager != null && mChannel != null) { mWifiP2pManager.cancelConnect(mChannel, if (mWifiP2pManager != null && sChannel != null) { mWifiP2pManager.cancelConnect(sChannel, new WifiP2pManager.ActionListener() { public void onSuccess() { if (DBG) Log.d(TAG, " cancel connect success"); Loading @@ -314,10 +314,10 @@ public class WifiP2pSettings extends DashboardFragment @Override public void onClick(DialogInterface dialog, int which) { if (which == DialogInterface.BUTTON_POSITIVE) { if (mWifiP2pManager != null && mChannel != null) { if (mWifiP2pManager != null && sChannel != null) { if (mSelectedGroup != null) { if (DBG) Log.d(TAG, " deleting group " + mSelectedGroup.getGroupName()); mWifiP2pManager.deletePersistentGroup(mChannel, mWifiP2pManager.deletePersistentGroup(sChannel, mSelectedGroup.getNetworkId(), new WifiP2pManager.ActionListener() { public void onSuccess() { Loading Loading @@ -357,8 +357,8 @@ public class WifiP2pSettings extends DashboardFragment if (mWifiP2pManager != null && initChannel()) { // Register receiver after make sure channel exist getActivity().registerReceiver(mReceiver, mIntentFilter); mWifiP2pManager.requestPeers(mChannel, WifiP2pSettings.this); mWifiP2pManager.requestDeviceInfo(mChannel, WifiP2pSettings.this); mWifiP2pManager.requestPeers(sChannel, WifiP2pSettings.this); mWifiP2pManager.requestDeviceInfo(sChannel, WifiP2pSettings.this); mIsIgnoreInitConnectionInfoCallback = false; } } Loading @@ -366,12 +366,12 @@ public class WifiP2pSettings extends DashboardFragment @Override public void onStop() { super.onStop(); if (mWifiP2pManager != null && mChannel != null) { mWifiP2pManager.stopPeerDiscovery(mChannel, null); if (mWifiP2pManager != null && sChannel != null) { mWifiP2pManager.stopPeerDiscovery(sChannel, null); if (!mLastGroupFormed) { // Close the channel when p2p doesn't connected. mChannel.close(); mChannel = null; sChannel.close(); sChannel = null; } } getActivity().unregisterReceiver(mReceiver); Loading Loading @@ -445,8 +445,8 @@ public class WifiP2pSettings extends DashboardFragment config.wps.setup = WpsInfo.DISPLAY; } } if (mWifiP2pManager != null && mChannel != null) { mWifiP2pManager.connect(mChannel, config, if (mWifiP2pManager != null && sChannel != null) { mWifiP2pManager.connect(sChannel, config, new WifiP2pManager.ActionListener() { public void onSuccess() { if (DBG) Log.d(TAG, " connect success"); Loading Loading @@ -617,9 +617,9 @@ public class WifiP2pSettings extends DashboardFragment } private void onDeviceAvailable() { mWifiP2pManager.requestNetworkInfo(mChannel, networkInfo -> { if (mChannel == null) return; mWifiP2pManager.requestConnectionInfo(mChannel, wifip2pinfo -> { mWifiP2pManager.requestNetworkInfo(sChannel, networkInfo -> { if (sChannel == null) return; mWifiP2pManager.requestConnectionInfo(sChannel, wifip2pinfo -> { if (!mIsIgnoreInitConnectionInfoCallback) { if (networkInfo.isConnected()) { if (DBG) { Loading Loading @@ -652,8 +652,8 @@ public class WifiP2pSettings extends DashboardFragment } private void startSearch() { if (mWifiP2pManager != null && mChannel != null && !mWifiP2pSearching) { mWifiP2pManager.discoverPeers(mChannel, new WifiP2pManager.ActionListener() { if (mWifiP2pManager != null && sChannel != null && !mWifiP2pSearching) { mWifiP2pManager.discoverPeers(sChannel, new WifiP2pManager.ActionListener() { public void onSuccess() { } public void onFailure(int reason) { Loading @@ -664,14 +664,14 @@ public class WifiP2pSettings extends DashboardFragment } private boolean initChannel() { if (mChannel != null) { if (sChannel != null) { return true; } if (mWifiP2pManager != null) { mChannel = mWifiP2pManager.initialize(getActivity().getApplicationContext(), sChannel = mWifiP2pManager.initialize(getActivity().getApplicationContext(), getActivity().getMainLooper(), null); } if (mChannel == null) { if (sChannel == null) { Log.e(TAG, "Failed to set up connection with wifi p2p service"); return false; } Loading tests/robotests/src/com/android/settings/wifi/p2p/WifiP2pSettingsTest.java +4 −4 Original line number Diff line number Diff line Loading @@ -338,7 +338,7 @@ public class WifiP2pSettingsTest { public void onStop_notLastGroupFormed_shouldCloseChannel() { mFragment.onStop(); assertThat(mFragment.mChannel).isNull(); assertThat(mFragment.sChannel).isNull(); } @Test Loading @@ -355,7 +355,7 @@ public class WifiP2pSettingsTest { verify(mWifiP2pManager, times(1)).stopPeerDiscovery(any(), any()); mFragment.onStart(); assertThat(mFragment.mChannel).isNotNull(); assertThat(mFragment.sChannel).isNotNull(); } @Test Loading Loading @@ -526,7 +526,7 @@ public class WifiP2pSettingsTest { @Test public void onCreateView_withNullP2pManager_shouldGetP2pManagerAgain() { mFragment.mChannel = null; // Reset channel to re-test onCreateView flow mFragment.sChannel = null; // Reset channel to re-test onCreateView flow mFragment.mWifiP2pManager = null; mFragment.onCreateView(LayoutInflater.from(mContext), null, new Bundle()); Loading @@ -537,7 +537,7 @@ public class WifiP2pSettingsTest { @Test public void onCreateView_withNullChannel_shouldSetP2pManagerNull() { doReturn(null).when(mWifiP2pManager).initialize(any(), any(), any()); mFragment.mChannel = null; // Reset channel to re-test onCreateView flow mFragment.sChannel = null; // Reset channel to re-test onCreateView flow mFragment.onCreateView(LayoutInflater.from(mContext), null, new Bundle()); assertThat(mFragment.mWifiP2pManager).isNull(); Loading Loading
src/com/android/settings/wifi/p2p/WifiP2pSettings.java +29 −29 Original line number Diff line number Diff line Loading @@ -76,7 +76,7 @@ public class WifiP2pSettings extends DashboardFragment private final IntentFilter mIntentFilter = new IntentFilter(); @VisibleForTesting WifiP2pManager mWifiP2pManager; @VisibleForTesting WifiP2pManager.Channel mChannel; @VisibleForTesting static WifiP2pManager.Channel sChannel; @VisibleForTesting OnClickListener mRenameListener; @VisibleForTesting OnClickListener mDisconnectListener; @VisibleForTesting OnClickListener mCancelConnectListener; Loading Loading @@ -150,8 +150,8 @@ public class WifiP2pSettings extends DashboardFragment // Requesting our own device info as an app holding the NETWORK_SETTINGS permission // ensures that the MAC address will be available in the result. if (DBG) Log.d(TAG, "This device changed. Requesting device info."); if (mWifiP2pManager != null && mChannel != null) { mWifiP2pManager.requestDeviceInfo(mChannel, WifiP2pSettings.this); if (mWifiP2pManager != null && sChannel != null) { mWifiP2pManager.requestDeviceInfo(sChannel, WifiP2pSettings.this); } } else if (WifiP2pManager.WIFI_P2P_DISCOVERY_CHANGED_ACTION.equals(action)) { int discoveryState = intent.getIntExtra(WifiP2pManager.EXTRA_DISCOVERY_STATE, Loading @@ -163,8 +163,8 @@ public class WifiP2pSettings extends DashboardFragment updateSearchMenu(false); } } else if (WifiP2pManager.ACTION_WIFI_P2P_PERSISTENT_GROUPS_CHANGED.equals(action)) { if (mWifiP2pManager != null && mChannel != null) { mWifiP2pManager.requestPersistentGroupInfo(mChannel, WifiP2pSettings.this); if (mWifiP2pManager != null && sChannel != null) { mWifiP2pManager.requestPersistentGroupInfo(sChannel, WifiP2pSettings.this); } } } Loading Loading @@ -239,7 +239,7 @@ public class WifiP2pSettings extends DashboardFragment @Override public void onClick(DialogInterface dialog, int which) { if (which == DialogInterface.BUTTON_POSITIVE) { if (mWifiP2pManager != null && mChannel != null) { if (mWifiP2pManager != null && sChannel != null) { String name = mDeviceNameText.getText().toString(); if (name != null) { for (int i = 0; i < name.length(); i++) { Loading @@ -253,7 +253,7 @@ public class WifiP2pSettings extends DashboardFragment } } } mWifiP2pManager.setDeviceName(mChannel, mWifiP2pManager.setDeviceName(sChannel, mDeviceNameText.getText().toString(), new WifiP2pManager.ActionListener() { public void onSuccess() { Loading @@ -275,8 +275,8 @@ public class WifiP2pSettings extends DashboardFragment @Override public void onClick(DialogInterface dialog, int which) { if (which == DialogInterface.BUTTON_POSITIVE) { if (mWifiP2pManager != null && mChannel != null) { mWifiP2pManager.removeGroup(mChannel, new WifiP2pManager.ActionListener() { if (mWifiP2pManager != null && sChannel != null) { mWifiP2pManager.removeGroup(sChannel, new WifiP2pManager.ActionListener() { public void onSuccess() { if (DBG) Log.d(TAG, " remove group success"); } Loading @@ -294,8 +294,8 @@ public class WifiP2pSettings extends DashboardFragment @Override public void onClick(DialogInterface dialog, int which) { if (which == DialogInterface.BUTTON_POSITIVE) { if (mWifiP2pManager != null && mChannel != null) { mWifiP2pManager.cancelConnect(mChannel, if (mWifiP2pManager != null && sChannel != null) { mWifiP2pManager.cancelConnect(sChannel, new WifiP2pManager.ActionListener() { public void onSuccess() { if (DBG) Log.d(TAG, " cancel connect success"); Loading @@ -314,10 +314,10 @@ public class WifiP2pSettings extends DashboardFragment @Override public void onClick(DialogInterface dialog, int which) { if (which == DialogInterface.BUTTON_POSITIVE) { if (mWifiP2pManager != null && mChannel != null) { if (mWifiP2pManager != null && sChannel != null) { if (mSelectedGroup != null) { if (DBG) Log.d(TAG, " deleting group " + mSelectedGroup.getGroupName()); mWifiP2pManager.deletePersistentGroup(mChannel, mWifiP2pManager.deletePersistentGroup(sChannel, mSelectedGroup.getNetworkId(), new WifiP2pManager.ActionListener() { public void onSuccess() { Loading Loading @@ -357,8 +357,8 @@ public class WifiP2pSettings extends DashboardFragment if (mWifiP2pManager != null && initChannel()) { // Register receiver after make sure channel exist getActivity().registerReceiver(mReceiver, mIntentFilter); mWifiP2pManager.requestPeers(mChannel, WifiP2pSettings.this); mWifiP2pManager.requestDeviceInfo(mChannel, WifiP2pSettings.this); mWifiP2pManager.requestPeers(sChannel, WifiP2pSettings.this); mWifiP2pManager.requestDeviceInfo(sChannel, WifiP2pSettings.this); mIsIgnoreInitConnectionInfoCallback = false; } } Loading @@ -366,12 +366,12 @@ public class WifiP2pSettings extends DashboardFragment @Override public void onStop() { super.onStop(); if (mWifiP2pManager != null && mChannel != null) { mWifiP2pManager.stopPeerDiscovery(mChannel, null); if (mWifiP2pManager != null && sChannel != null) { mWifiP2pManager.stopPeerDiscovery(sChannel, null); if (!mLastGroupFormed) { // Close the channel when p2p doesn't connected. mChannel.close(); mChannel = null; sChannel.close(); sChannel = null; } } getActivity().unregisterReceiver(mReceiver); Loading Loading @@ -445,8 +445,8 @@ public class WifiP2pSettings extends DashboardFragment config.wps.setup = WpsInfo.DISPLAY; } } if (mWifiP2pManager != null && mChannel != null) { mWifiP2pManager.connect(mChannel, config, if (mWifiP2pManager != null && sChannel != null) { mWifiP2pManager.connect(sChannel, config, new WifiP2pManager.ActionListener() { public void onSuccess() { if (DBG) Log.d(TAG, " connect success"); Loading Loading @@ -617,9 +617,9 @@ public class WifiP2pSettings extends DashboardFragment } private void onDeviceAvailable() { mWifiP2pManager.requestNetworkInfo(mChannel, networkInfo -> { if (mChannel == null) return; mWifiP2pManager.requestConnectionInfo(mChannel, wifip2pinfo -> { mWifiP2pManager.requestNetworkInfo(sChannel, networkInfo -> { if (sChannel == null) return; mWifiP2pManager.requestConnectionInfo(sChannel, wifip2pinfo -> { if (!mIsIgnoreInitConnectionInfoCallback) { if (networkInfo.isConnected()) { if (DBG) { Loading Loading @@ -652,8 +652,8 @@ public class WifiP2pSettings extends DashboardFragment } private void startSearch() { if (mWifiP2pManager != null && mChannel != null && !mWifiP2pSearching) { mWifiP2pManager.discoverPeers(mChannel, new WifiP2pManager.ActionListener() { if (mWifiP2pManager != null && sChannel != null && !mWifiP2pSearching) { mWifiP2pManager.discoverPeers(sChannel, new WifiP2pManager.ActionListener() { public void onSuccess() { } public void onFailure(int reason) { Loading @@ -664,14 +664,14 @@ public class WifiP2pSettings extends DashboardFragment } private boolean initChannel() { if (mChannel != null) { if (sChannel != null) { return true; } if (mWifiP2pManager != null) { mChannel = mWifiP2pManager.initialize(getActivity().getApplicationContext(), sChannel = mWifiP2pManager.initialize(getActivity().getApplicationContext(), getActivity().getMainLooper(), null); } if (mChannel == null) { if (sChannel == null) { Log.e(TAG, "Failed to set up connection with wifi p2p service"); return false; } Loading
tests/robotests/src/com/android/settings/wifi/p2p/WifiP2pSettingsTest.java +4 −4 Original line number Diff line number Diff line Loading @@ -338,7 +338,7 @@ public class WifiP2pSettingsTest { public void onStop_notLastGroupFormed_shouldCloseChannel() { mFragment.onStop(); assertThat(mFragment.mChannel).isNull(); assertThat(mFragment.sChannel).isNull(); } @Test Loading @@ -355,7 +355,7 @@ public class WifiP2pSettingsTest { verify(mWifiP2pManager, times(1)).stopPeerDiscovery(any(), any()); mFragment.onStart(); assertThat(mFragment.mChannel).isNotNull(); assertThat(mFragment.sChannel).isNotNull(); } @Test Loading Loading @@ -526,7 +526,7 @@ public class WifiP2pSettingsTest { @Test public void onCreateView_withNullP2pManager_shouldGetP2pManagerAgain() { mFragment.mChannel = null; // Reset channel to re-test onCreateView flow mFragment.sChannel = null; // Reset channel to re-test onCreateView flow mFragment.mWifiP2pManager = null; mFragment.onCreateView(LayoutInflater.from(mContext), null, new Bundle()); Loading @@ -537,7 +537,7 @@ public class WifiP2pSettingsTest { @Test public void onCreateView_withNullChannel_shouldSetP2pManagerNull() { doReturn(null).when(mWifiP2pManager).initialize(any(), any(), any()); mFragment.mChannel = null; // Reset channel to re-test onCreateView flow mFragment.sChannel = null; // Reset channel to re-test onCreateView flow mFragment.onCreateView(LayoutInflater.from(mContext), null, new Bundle()); assertThat(mFragment.mWifiP2pManager).isNull(); Loading