Search in sources :

Example 1 with WifiSliceItem

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();
}
Also used : WifiSliceItem(com.android.settings.wifi.slice.WifiSliceItem) Test(org.junit.Test)

Example 2 with WifiSliceItem

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();
}
Also used : WifiSliceItem(com.android.settings.wifi.slice.WifiSliceItem) ListBuilder(androidx.slice.builders.ListBuilder) NetworkProviderWorker(com.android.settings.network.telephony.NetworkProviderWorker)

Example 3 with WifiSliceItem

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();
}
Also used : WifiSliceItem(com.android.settings.wifi.slice.WifiSliceItem) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 4 with WifiSliceItem

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);
}
Also used : WifiSliceItem(com.android.settings.wifi.slice.WifiSliceItem) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

WifiSliceItem (com.android.settings.wifi.slice.WifiSliceItem)4 Test (org.junit.Test)3 ArrayList (java.util.ArrayList)2 ListBuilder (androidx.slice.builders.ListBuilder)1 NetworkProviderWorker (com.android.settings.network.telephony.NetworkProviderWorker)1