Search in sources :

Example 1 with NetworkProviderWorker

use of com.android.settings.network.telephony.NetworkProviderWorker 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)

Aggregations

ListBuilder (androidx.slice.builders.ListBuilder)1 NetworkProviderWorker (com.android.settings.network.telephony.NetworkProviderWorker)1 WifiSliceItem (com.android.settings.wifi.slice.WifiSliceItem)1