diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 09ee4243287..2bb81a1384f 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -268,7 +268,7 @@ diff --git a/res/values/strings.xml b/res/values/strings.xml index cf869565c2a..e33aac74cc3 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -1878,8 +1878,6 @@ Advanced Wi\u2011Fi - - Configure Wi\u2011Fi MAC address diff --git a/res/xml/wifi_configure_settings.xml b/res/xml/wifi_configure_settings.xml index 14990a5b1c9..ccf7f1dd0b8 100644 --- a/res/xml/wifi_configure_settings.xml +++ b/res/xml/wifi_configure_settings.xml @@ -17,7 +17,7 @@ + android:title="@string/wifi_configure_settings_preference_title"> - - + android:title="@string/wifi_menu_p2p" + android:fragment="com.android.settings.wifi.p2p.WifiP2pSettings"/> - + + + diff --git a/src/com/android/settings/wifi/p2p/P2pCategoryPreferenceController.java b/src/com/android/settings/wifi/p2p/P2pCategoryPreferenceController.java new file mode 100644 index 00000000000..3df1978d51d --- /dev/null +++ b/src/com/android/settings/wifi/p2p/P2pCategoryPreferenceController.java @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2017 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 com.android.settings.wifi.p2p; + +import android.content.Context; +import android.support.v7.preference.Preference; +import android.support.v7.preference.PreferenceGroup; +import android.support.v7.preference.PreferenceScreen; + +import com.android.settings.core.PreferenceController; + +public abstract class P2pCategoryPreferenceController extends PreferenceController { + + protected PreferenceGroup mCategory; + + public P2pCategoryPreferenceController(Context context) { + super(context); + } + + @Override + public boolean isAvailable() { + return true; + } + + @Override + public void displayPreference(PreferenceScreen screen) { + super.displayPreference(screen); + mCategory = (PreferenceGroup) screen.findPreference(getPreferenceKey()); + } + + public void removeAllChildren() { + if (mCategory != null) { + mCategory.removeAll(); + mCategory.setVisible(false); + } + } + + public void addChild(Preference child) { + if (mCategory != null) { + mCategory.addPreference(child); + mCategory.setVisible(true); + } + } + + public void setEnabled(boolean enabled) { + if (mCategory != null) { + mCategory.setEnabled(enabled); + } + } +} diff --git a/src/com/android/settings/wifi/p2p/P2pPeerCategoryPreferenceController.java b/src/com/android/settings/wifi/p2p/P2pPeerCategoryPreferenceController.java new file mode 100644 index 00000000000..5baa403abe5 --- /dev/null +++ b/src/com/android/settings/wifi/p2p/P2pPeerCategoryPreferenceController.java @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2017 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 com.android.settings.wifi.p2p; + +import android.content.Context; + +public class P2pPeerCategoryPreferenceController extends P2pCategoryPreferenceController { + + public P2pPeerCategoryPreferenceController(Context context) { + super(context); + } + + @Override + public String getPreferenceKey() { + return "p2p_peer_devices"; + } +} diff --git a/src/com/android/settings/wifi/p2p/P2pPersistentCategoryPreferenceController.java b/src/com/android/settings/wifi/p2p/P2pPersistentCategoryPreferenceController.java new file mode 100644 index 00000000000..139f69830a7 --- /dev/null +++ b/src/com/android/settings/wifi/p2p/P2pPersistentCategoryPreferenceController.java @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2017 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 com.android.settings.wifi.p2p; + +import android.content.Context; + +public class P2pPersistentCategoryPreferenceController extends P2pCategoryPreferenceController { + + public P2pPersistentCategoryPreferenceController(Context context) { + super(context); + } + + @Override + public String getPreferenceKey() { + return "p2p_persistent_group"; + } +} diff --git a/src/com/android/settings/wifi/p2p/P2pThisDevicePreferenceController.java b/src/com/android/settings/wifi/p2p/P2pThisDevicePreferenceController.java new file mode 100644 index 00000000000..ca992a984eb --- /dev/null +++ b/src/com/android/settings/wifi/p2p/P2pThisDevicePreferenceController.java @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2017 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 com.android.settings.wifi.p2p; + +import android.content.Context; +import android.net.wifi.p2p.WifiP2pDevice; +import android.support.v7.preference.Preference; +import android.support.v7.preference.PreferenceScreen; +import android.text.TextUtils; + +import com.android.settings.core.PreferenceController; + +public class P2pThisDevicePreferenceController extends PreferenceController { + + private Preference mPreference; + + public P2pThisDevicePreferenceController(Context context) { + super(context); + } + + @Override + public boolean isAvailable() { + return true; + } + + @Override + public String getPreferenceKey() { + return "p2p_this_device"; + } + + @Override + public void displayPreference(PreferenceScreen screen) { + super.displayPreference(screen); + mPreference = screen.findPreference(getPreferenceKey()); + } + + public void setEnabled(boolean enabled) { + if (mPreference != null) { + mPreference.setEnabled(enabled); + } + } + + public void updateDeviceName(WifiP2pDevice thisDevice) { + if (mPreference != null && thisDevice != null) { + if (TextUtils.isEmpty(thisDevice.deviceName)) { + mPreference.setTitle(thisDevice.deviceAddress); + } else { + mPreference.setTitle(thisDevice.deviceName); + } + } + } +} diff --git a/src/com/android/settings/wifi/p2p/WifiP2pSettings.java b/src/com/android/settings/wifi/p2p/WifiP2pSettings.java index 977be7ea723..232666a636e 100644 --- a/src/com/android/settings/wifi/p2p/WifiP2pSettings.java +++ b/src/com/android/settings/wifi/p2p/WifiP2pSettings.java @@ -39,8 +39,6 @@ import android.net.wifi.p2p.WifiP2pManager.PersistentGroupInfoListener; import android.os.Bundle; import android.os.SystemProperties; import android.support.v7.preference.Preference; -import android.support.v7.preference.PreferenceCategory; -import android.support.v7.preference.PreferenceGroup; import android.support.v7.preference.PreferenceScreen; import android.text.InputFilter; import android.text.TextUtils; @@ -53,12 +51,16 @@ import android.widget.Toast; import com.android.internal.logging.nano.MetricsProto.MetricsEvent; import com.android.settings.R; -import com.android.settings.SettingsPreferenceFragment; +import com.android.settings.core.PreferenceController; +import com.android.settings.dashboard.DashboardFragment; + +import java.util.ArrayList; +import java.util.List; /* * Displays Wi-fi p2p settings UI */ -public class WifiP2pSettings extends SettingsPreferenceFragment +public class WifiP2pSettings extends DashboardFragment implements PersistentGroupInfoListener, PeerListListener { private static final String TAG = "WifiP2pSettings"; @@ -83,9 +85,9 @@ public class WifiP2pSettings extends SettingsPreferenceFragment private int mConnectedDevices; private boolean mLastGroupFormed = false; - private PreferenceGroup mPeersGroup; - private PreferenceGroup mPersistentGroup; - private Preference mThisDevicePref; + private P2pPeerCategoryPreferenceController mPeerCategoryController; + private P2pPersistentCategoryPreferenceController mPersistentCategoryController; + private P2pThisDevicePreferenceController mThisDevicePreferenceController; private static final int DIALOG_DISCONNECT = 1; private static final int DIALOG_CANCEL_CONNECT = 2; @@ -132,7 +134,7 @@ public class WifiP2pSettings extends SettingsPreferenceFragment mThisDevice = (WifiP2pDevice) intent.getParcelableExtra( WifiP2pManager.EXTRA_WIFI_P2P_DEVICE); if (DBG) Log.d(TAG, "Update device info: " + mThisDevice); - updateDevicePref(); + mThisDevicePreferenceController.updateDeviceName(mThisDevice); } else if (WifiP2pManager.WIFI_P2P_DISCOVERY_CHANGED_ACTION.equals(action)) { int discoveryState = intent.getIntExtra(WifiP2pManager.EXTRA_DISCOVERY_STATE, WifiP2pManager.WIFI_P2P_DISCOVERY_STOPPED); @@ -150,21 +152,37 @@ public class WifiP2pSettings extends SettingsPreferenceFragment } }; - public WifiP2pSettings() { - if (DBG) Log.d(TAG, "Creating WifiP2pSettings ..."); + @Override + protected String getLogTag() { + return TAG; + } + + @Override + protected int getPreferenceScreenResId() { + return R.xml.wifi_p2p_settings; + } + + @Override + public int getMetricsCategory() { + return MetricsEvent.WIFI_P2P; + } + + @Override + protected List getPreferenceControllers(Context context) { + final List controllers = new ArrayList<>(); + mPersistentCategoryController = + new P2pPersistentCategoryPreferenceController(context); + mPeerCategoryController = + new P2pPeerCategoryPreferenceController(context); + mThisDevicePreferenceController = new P2pThisDevicePreferenceController(context); + controllers.add(mPersistentCategoryController); + controllers.add(mPeerCategoryController); + controllers.add(mThisDevicePreferenceController); + return controllers; } @Override public void onActivityCreated(Bundle savedInstanceState) { - addPreferencesFromResource(R.xml.wifi_p2p_settings); - - mIntentFilter.addAction(WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION); - mIntentFilter.addAction(WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION); - mIntentFilter.addAction(WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION); - mIntentFilter.addAction(WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION); - mIntentFilter.addAction(WifiP2pManager.WIFI_P2P_DISCOVERY_CHANGED_ACTION); - mIntentFilter.addAction(WifiP2pManager.WIFI_P2P_PERSISTENT_GROUPS_CHANGED_ACTION); - final Activity activity = getActivity(); mWifiP2pManager = (WifiP2pManager) getSystemService(Context.WIFI_P2P_SERVICE); if (mWifiP2pManager != null) { @@ -274,16 +292,17 @@ public class WifiP2pSettings extends SettingsPreferenceFragment mWifiP2pManager.deletePersistentGroup(mChannel, mSelectedGroup.getNetworkId(), new WifiP2pManager.ActionListener() { - public void onSuccess() { - if (DBG) Log.d(TAG, " delete group success"); - } - public void onFailure(int reason) { - if (DBG) Log.d(TAG, " delete group fail " + reason); - } - }); + public void onSuccess() { + if (DBG) Log.d(TAG, " delete group success"); + } + + public void onFailure(int reason) { + if (DBG) Log.d(TAG, " delete group fail " + reason); + } + }); mSelectedGroup = null; } else { - if (DBG) Log.w(TAG, " No selected group to delete!" ); + if (DBG) Log.w(TAG, " No selected group to delete!"); } } } else if (which == DialogInterface.BUTTON_NEGATIVE) { @@ -295,31 +314,20 @@ public class WifiP2pSettings extends SettingsPreferenceFragment } }; - setHasOptionsMenu(true); - - final PreferenceScreen preferenceScreen = getPreferenceScreen(); - preferenceScreen.removeAll(); - preferenceScreen.setOrderingAsAdded(true); - - mThisDevicePref = new Preference(getPrefContext()); - mThisDevicePref.setPersistent(false); - mThisDevicePref.setSelectable(false); - preferenceScreen.addPreference(mThisDevicePref); - - mPeersGroup = new PreferenceCategory(getPrefContext()); - mPeersGroup.setTitle(R.string.wifi_p2p_peer_devices); - preferenceScreen.addPreference(mPeersGroup); - - mPersistentGroup = new PreferenceCategory(getPrefContext()); - mPersistentGroup.setTitle(R.string.wifi_p2p_remembered_groups); - preferenceScreen.addPreference(mPersistentGroup); - super.onActivityCreated(savedInstanceState); } @Override public void onResume() { super.onResume(); + mIntentFilter.addAction(WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION); + mIntentFilter.addAction(WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION); + mIntentFilter.addAction(WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION); + mIntentFilter.addAction(WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION); + mIntentFilter.addAction(WifiP2pManager.WIFI_P2P_DISCOVERY_CHANGED_ACTION); + mIntentFilter.addAction(WifiP2pManager.WIFI_P2P_PERSISTENT_GROUPS_CHANGED_ACTION); + final PreferenceScreen preferenceScreen = getPreferenceScreen(); + getActivity().registerReceiver(mReceiver, mIntentFilter); if (mWifiP2pManager != null) { mWifiP2pManager.requestPeers(mChannel, WifiP2pSettings.this); @@ -490,11 +498,6 @@ public class WifiP2pSettings extends SettingsPreferenceFragment return null; } - @Override - public int getMetricsCategory() { - return MetricsEvent.WIFI_P2P; - } - @Override public int getDialogMetricsCategory(int dialogId) { switch (dialogId) { @@ -524,13 +527,13 @@ public class WifiP2pSettings extends SettingsPreferenceFragment } private void handlePeersChanged() { - mPeersGroup.removeAll(); + mPeerCategoryController.removeAllChildren(); mConnectedDevices = 0; if (DBG) Log.d(TAG, "List of available peers"); for (WifiP2pDevice peer: mPeers.getDeviceList()) { if (DBG) Log.d(TAG, "-> " + peer); - mPeersGroup.addPreference(new WifiP2pPeer(getActivity(), peer)); + mPeerCategoryController.addChild(new WifiP2pPeer(getActivity(), peer)); if (peer.status == WifiP2pDevice.CONNECTED) mConnectedDevices++; } if (DBG) Log.d(TAG, " mConnectedDevices " + mConnectedDevices); @@ -538,12 +541,12 @@ public class WifiP2pSettings extends SettingsPreferenceFragment @Override public void onPersistentGroupInfoAvailable(WifiP2pGroupList groups) { - mPersistentGroup.removeAll(); + mPersistentCategoryController.removeAllChildren(); for (WifiP2pGroup group: groups.getGroupList()) { if (DBG) Log.d(TAG, " group " + group); - WifiP2pPersistentGroup wppg = new WifiP2pPersistentGroup(getActivity(), group); - mPersistentGroup.addPreference(wppg); + WifiP2pPersistentGroup wppg = new WifiP2pPersistentGroup(getPrefContext(), group); + mPersistentCategoryController.addChild(wppg); if (wppg.getGroupName().equals(mSelectedGroupName)) { if (DBG) Log.d(TAG, "Selecting group " + wppg.getGroupName()); mSelectedGroup = wppg; @@ -568,9 +571,9 @@ public class WifiP2pSettings extends SettingsPreferenceFragment private void handleP2pStateChanged() { updateSearchMenu(false); - mThisDevicePref.setEnabled(mWifiP2pEnabled); - mPeersGroup.setEnabled(mWifiP2pEnabled); - mPersistentGroup.setEnabled(mWifiP2pEnabled); + mThisDevicePreferenceController.setEnabled(mWifiP2pEnabled); + mPersistentCategoryController.setEnabled(mWifiP2pEnabled); + mPeerCategoryController.setEnabled(mWifiP2pEnabled); } private void updateSearchMenu(boolean searching) { @@ -590,14 +593,4 @@ public class WifiP2pSettings extends SettingsPreferenceFragment }); } } - - private void updateDevicePref() { - if (mThisDevice != null) { - if (TextUtils.isEmpty(mThisDevice.deviceName)) { - mThisDevicePref.setTitle(mThisDevice.deviceAddress); - } else { - mThisDevicePref.setTitle(mThisDevice.deviceName); - } - } - } } diff --git a/tests/robotests/assets/grandfather_not_implementing_index_provider b/tests/robotests/assets/grandfather_not_implementing_index_provider index 8613dd1bac9..2e30bc9803d 100644 --- a/tests/robotests/assets/grandfather_not_implementing_index_provider +++ b/tests/robotests/assets/grandfather_not_implementing_index_provider @@ -7,8 +7,9 @@ com.android.settings.fuelgauge.PowerUsageDetail com.android.settings.fuelgauge.AdvancedPowerUsageDetail com.android.settings.deviceinfo.StorageProfileFragment com.android.settings.wifi.details.WifiNetworkDetailsFragment +com.android.settings.wifi.p2p.WifiP2pSettings com.android.settings.enterprise.ApplicationListFragment$AdminGrantedPermissionCamera com.android.settings.enterprise.ApplicationListFragment$AdminGrantedPermissionLocation com.android.settings.enterprise.ApplicationListFragment$AdminGrantedPermissionMicrophone com.android.settings.enterprise.ApplicationListFragment$EnterpriseInstalledPackages -com.android.settings.enterprise.EnterpriseSetDefaultAppsListFragment \ No newline at end of file +com.android.settings.enterprise.EnterpriseSetDefaultAppsListFragment diff --git a/tests/robotests/src/com/android/settings/wifi/p2p/P2pCategoryPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/wifi/p2p/P2pCategoryPreferenceControllerTest.java new file mode 100644 index 00000000000..9dbd406ed88 --- /dev/null +++ b/tests/robotests/src/com/android/settings/wifi/p2p/P2pCategoryPreferenceControllerTest.java @@ -0,0 +1,97 @@ +/* + * Copyright (C) 2017 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 com.android.settings.wifi.p2p; + +import android.support.v7.preference.Preference; +import android.support.v7.preference.PreferenceCategory; +import android.support.v7.preference.PreferenceScreen; + +import com.android.settings.SettingsRobolectricTestRunner; +import com.android.settings.TestConfig; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.robolectric.RuntimeEnvironment; +import org.robolectric.annotation.Config; + +import static com.google.common.truth.Truth.assertThat; +import static org.mockito.Matchers.anyString; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +@RunWith(SettingsRobolectricTestRunner.class) +@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION) +public class P2pCategoryPreferenceControllerTest { + + @Mock + private PreferenceScreen mPreferenceScreen; + @Mock + private PreferenceCategory mCategory; + private P2pCategoryPreferenceController mController; + + @Before + public void setUp() { + MockitoAnnotations.initMocks(this); + when(mPreferenceScreen.findPreference(anyString())).thenReturn(mCategory); + + mController = new P2pCategoryPreferenceController(RuntimeEnvironment.application) { + + @Override + public String getPreferenceKey() { + return "test_key"; + } + }; + mController.displayPreference(mPreferenceScreen); + } + + @Test + public void isAlwaysAvailable() { + assertThat(mController.isAvailable()).isTrue(); + } + + + @Test + public void removeAllChildren_shouldRemove() { + mController.removeAllChildren(); + + verify(mCategory).removeAll(); + verify(mCategory).setVisible(false); + } + + @Test + public void addChild_shouldAdd() { + final Preference pref = new Preference(RuntimeEnvironment.application); + mController.addChild(pref); + + verify(mCategory).addPreference(pref); + verify(mCategory).setVisible(true); + } + + @Test + public void shouldToggleEnable() { + mController.setEnabled(false); + + verify(mCategory).setEnabled(false); + + mController.setEnabled(true); + + verify(mCategory).setEnabled(true); + } +} diff --git a/tests/robotests/src/com/android/settings/wifi/p2p/P2pThisDevicePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/wifi/p2p/P2pThisDevicePreferenceControllerTest.java new file mode 100644 index 00000000000..07aa7227a28 --- /dev/null +++ b/tests/robotests/src/com/android/settings/wifi/p2p/P2pThisDevicePreferenceControllerTest.java @@ -0,0 +1,82 @@ +/* + * Copyright (C) 2017 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 com.android.settings.wifi.p2p; + + +import android.net.wifi.p2p.WifiP2pDevice; +import android.support.v7.preference.Preference; +import android.support.v7.preference.PreferenceScreen; + +import com.android.settings.SettingsRobolectricTestRunner; +import com.android.settings.TestConfig; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.robolectric.RuntimeEnvironment; +import org.robolectric.annotation.Config; + +import static com.google.common.truth.Truth.assertThat; +import static org.mockito.Matchers.anyString; +import static org.mockito.Mockito.when; + +@RunWith(SettingsRobolectricTestRunner.class) +@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION) +public class P2pThisDevicePreferenceControllerTest { + + @Mock + private PreferenceScreen mPreferenceScreen; + private Preference mPreference; + private P2pThisDevicePreferenceController mController; + + @Before + public void setUp() { + MockitoAnnotations.initMocks(this); + mPreference = new Preference(RuntimeEnvironment.application); + when(mPreferenceScreen.findPreference(anyString())).thenReturn(mPreference); + + mController = new P2pThisDevicePreferenceController(RuntimeEnvironment.application); + } + + @Test + public void isAlwaysAvailable() { + assertThat(mController.isAvailable()).isTrue(); + } + + @Test + public void updateDeviceName_emptyName_shouldUseIpAddress() { + WifiP2pDevice device = new WifiP2pDevice(); + device.deviceAddress = "address"; + mController.displayPreference(mPreferenceScreen); + mController.updateDeviceName(device); + + assertThat(mPreference.getTitle()).isEqualTo(device.deviceAddress); + } + + @Test + public void updateDeviceName_hasName_shouldUseName() { + WifiP2pDevice device = new WifiP2pDevice(); + device.deviceAddress = "address"; + device.deviceName = "name"; + mController.displayPreference(mPreferenceScreen); + mController.updateDeviceName(device); + + assertThat(mPreference.getTitle()).isEqualTo(device.deviceName); + } +}