use of com.android.settings.wifi.slice.WifiSliceItem in project android_packages_apps_Settings by omnirom.
the class ProviderModelSliceHelperTest method getConnectedWifiItem_inputNull_verifyReturnItem.
@Test
public void getConnectedWifiItem_inputNull_verifyReturnItem() {
List<WifiSliceItem> wifiList = null;
WifiSliceItem testItem = mProviderModelSliceHelper.getConnectedWifiItem(wifiList);
assertThat(testItem).isNull();
}
use of com.android.settings.wifi.slice.WifiSliceItem in project android_packages_apps_Settings by omnirom.
the class ProviderModelSlice method getSlice.
@Override
public Slice getSlice() {
// The provider model slice step:
// First section: Add the Ethernet item.
// Second section: Add the carrier item.
// Third section: Add the Wi-Fi toggle item.
// Fourth section: Add the connected Wi-Fi item.
// Fifth section: Add the Wi-Fi items which are not connected.
// Sixth section: Add the See All item.
final ListBuilder listBuilder = mHelper.createListBuilder(getUri());
int maxListSize = 0;
final NetworkProviderWorker worker = getWorker();
if (worker != null) {
maxListSize = worker.getApRowCount();
} else {
log("network provider worker is null.");
}
// First section: Add the Ethernet item.
if (getInternetType() == InternetUpdater.INTERNET_ETHERNET) {
log("get Ethernet item which is connected");
listBuilder.addRow(createEthernetRow());
maxListSize--;
}
// Second section: Add the carrier item.
if (!mHelper.isAirplaneModeEnabled()) {
final boolean hasCarrier = mHelper.hasCarrier();
log("hasCarrier: " + hasCarrier);
if (hasCarrier) {
mHelper.updateTelephony();
listBuilder.addRow(mHelper.createCarrierRow(worker != null ? worker.getNetworkTypeDescription() : ""));
maxListSize--;
}
}
// Third section: Add the Wi-Fi toggle item.
final boolean isWifiEnabled = mWifiManager.isWifiEnabled();
listBuilder.addRow(createWifiToggleRow(mContext, isWifiEnabled));
maxListSize--;
if (!isWifiEnabled) {
log("Wi-Fi is disabled");
return listBuilder.build();
}
List<WifiSliceItem> wifiList = (worker != null) ? worker.getResults() : null;
if (wifiList == null || wifiList.size() <= 0) {
log("Wi-Fi list is empty");
return listBuilder.build();
}
// Fourth section: Add the connected Wi-Fi item.
final WifiSliceItem connectedWifiItem = mHelper.getConnectedWifiItem(wifiList);
if (connectedWifiItem != null) {
log("get Wi-Fi item which is connected");
listBuilder.addRow(getWifiSliceItemRow(connectedWifiItem));
maxListSize--;
}
// Fifth section: Add the Wi-Fi items which are not connected.
log("get Wi-Fi items which are not connected. Wi-Fi items : " + wifiList.size());
final List<WifiSliceItem> disconnectedWifiList = wifiList.stream().filter(item -> item.getConnectedState() != WifiEntry.CONNECTED_STATE_CONNECTED).limit(maxListSize - 1).collect(Collectors.toList());
for (WifiSliceItem item : disconnectedWifiList) {
listBuilder.addRow(getWifiSliceItemRow(item));
}
// Sixth section: Add the See All item.
log("add See-All");
listBuilder.addRow(getSeeAllRow());
return listBuilder.build();
}
use of com.android.settings.wifi.slice.WifiSliceItem in project android_packages_apps_Settings by omnirom.
the class ProviderModelSliceHelperTest method getConnectedWifiItem_inputListInvolveNoConnectedWifiItem_verifyReturnItem.
@Test
public void getConnectedWifiItem_inputListInvolveNoConnectedWifiItem_verifyReturnItem() {
when(mWifiSliceItem1.getConnectedState()).thenReturn(WifiEntry.CONNECTED_STATE_DISCONNECTED);
when(mWifiSliceItem2.getConnectedState()).thenReturn(WifiEntry.CONNECTED_STATE_DISCONNECTED);
List<WifiSliceItem> wifiList = new ArrayList<>();
wifiList.add(mWifiSliceItem1);
wifiList.add(mWifiSliceItem2);
WifiSliceItem testItem = mProviderModelSliceHelper.getConnectedWifiItem(wifiList);
assertThat(testItem).isNull();
}
use of com.android.settings.wifi.slice.WifiSliceItem in project android_packages_apps_Settings by omnirom.
the class ProviderModelSliceHelperTest method getConnectedWifiItem_inputListInvolveOneConnectedWifiItem_verifyReturnItem.
@Test
public void getConnectedWifiItem_inputListInvolveOneConnectedWifiItem_verifyReturnItem() {
when(mWifiSliceItem1.getConnectedState()).thenReturn(WifiEntry.CONNECTED_STATE_CONNECTED);
when(mWifiSliceItem2.getConnectedState()).thenReturn(WifiEntry.CONNECTED_STATE_DISCONNECTED);
List<WifiSliceItem> wifiList = new ArrayList<>();
wifiList.add(mWifiSliceItem1);
wifiList.add(mWifiSliceItem2);
WifiSliceItem testItem = mProviderModelSliceHelper.getConnectedWifiItem(wifiList);
assertThat(testItem).isNotNull();
assertEquals(mWifiSliceItem1, testItem);
}
Aggregations