Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit cc88c2fe authored by Fan Zhang's avatar Fan Zhang
Browse files

Add place holder rows to wifi slice.

When loading wifi slice, the wifitracker is super slow to scan and
return APs. So we will show up to 3 rows of placeholder in the slice UI.

- When building slice, if there are at least 3 APs, show first 3.
- When there aren't enough APs, show them all and fill the rest of
  placeholder rows.

Bug: 118224581
Test: robotests
Change-Id: Id332f64bfa335543ea406f73b249f93504d63d4f
parent db556612
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -154,6 +154,7 @@ public class CardContentLoader extends AsyncLoaderCompat<List<ContextualCard>> {

        final Slice slice = Slice.bindSlice(mContext, uri, SUPPORTED_SPECS);
        if (slice == null || slice.hasHint(HINT_ERROR)) {
            Log.w(TAG, "Failed to bind slice, not eligible for display " + uri);
            return false;
        }

+31 −9
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ import android.os.Looper;
import android.provider.SettingsSlicesContract;
import android.text.TextUtils;

import androidx.annotation.VisibleForTesting;
import androidx.core.graphics.drawable.IconCompat;
import androidx.slice.Slice;
import androidx.slice.builders.ListBuilder;
@@ -61,6 +62,7 @@ import java.util.List;
 */
public class WifiSlice implements CustomSliceable {


    /**
     * Backing Uri for the Wifi Slice.
     */
@@ -71,6 +73,9 @@ public class WifiSlice implements CustomSliceable {
            .appendPath(KEY_WIFI)
            .build();

    @VisibleForTesting
    static final int DEFAULT_EXPANDED_ROW_COUNT = 3;

    private final Context mContext;

    public WifiSlice(Context context) {
@@ -115,26 +120,43 @@ public class WifiSlice implements CustomSliceable {
                        .addEndItem(toggleSliceAction)
                        .setPrimaryAction(primarySliceAction));

        if (isWifiEnabled) {
            final List<AccessPoint> result = getBackgroundWorker().getResults();
            if (result != null && !result.isEmpty()) {
                for (AccessPoint ap : result) {
                    listBuilder.addRow(getAccessPointRow(ap));
        if (!isWifiEnabled) {
            return listBuilder.build();
        }

        List<AccessPoint> result = getBackgroundWorker().getResults();
        if (result == null) {
            result = new ArrayList<>();
        }
                listBuilder.setSeeMoreAction(primaryAction);
        final int apCount = result.size();
        // Add AP rows
        final CharSequence placeholder = mContext.getText(R.string.summary_placeholder);
        for (int i = 0; i < DEFAULT_EXPANDED_ROW_COUNT; i++) {
            if (i < apCount) {
                listBuilder.addRow(getAccessPointRow(result.get(i)));
            } else {
                listBuilder.addRow(new RowBuilder()
                        .setTitle(placeholder)
                        .setSubtitle(placeholder));
            }
        }
        return listBuilder.build();
        // Add more button
        return listBuilder
                .setSeeMoreAction(primaryAction)
                .build();
    }

    private RowBuilder getAccessPointRow(AccessPoint accessPoint) {
        final String title = accessPoint.getConfigName();
        final IconCompat levelIcon = IconCompat.createWithResource(mContext,
                com.android.settingslib.Utils.getWifiIconResource(accessPoint.getLevel()));
        final CharSequence apSummary = accessPoint.getSettingsSummary();
        final RowBuilder rowBuilder = new RowBuilder()
                .setTitleItem(levelIcon, ListBuilder.ICON_IMAGE)
                .setTitle(title)
                .setSubtitle(accessPoint.getSettingsSummary())
                .setSubtitle(!TextUtils.isEmpty(apSummary)
                        ? apSummary
                        : mContext.getText(R.string.summary_placeholder))
                .setPrimaryAction(new SliceAction(
                        getAccessPointAction(accessPoint), levelIcon, title));

+1 −1
Original line number Diff line number Diff line
@@ -213,7 +213,7 @@ public class SliceTester {
            for (SliceItem subTitleItem : titleItems) {
                if (TextUtils.equals(subTitleItem.getText(), title)) {
                    hasTitle = true;
                    assertThat(subTitleItem.getText()).isEqualTo(title);
                    break;
                }
            }
        }
+18 −1
Original line number Diff line number Diff line
@@ -17,6 +17,11 @@

package com.android.settings.wifi;

import static android.app.slice.Slice.HINT_LIST_ITEM;
import static android.app.slice.SliceItem.FORMAT_SLICE;

import static com.android.settings.wifi.WifiSlice.DEFAULT_EXPANDED_ROW_COUNT;

import static com.google.common.truth.Truth.assertThat;

import android.content.Context;
@@ -29,6 +34,7 @@ import androidx.slice.SliceItem;
import androidx.slice.SliceMetadata;
import androidx.slice.SliceProvider;
import androidx.slice.core.SliceAction;
import androidx.slice.core.SliceQuery;
import androidx.slice.widget.SliceLiveData;

import com.android.settings.R;
@@ -60,7 +66,7 @@ public class WifiSliceTest {
    }

    @Test
    public void getWifiSlice_correctSliceContent() {
    public void getWifiSlice_shouldHaveTitleAndToggle() {
        final Slice wifiSlice = mWifiSlice.getSlice();
        final SliceMetadata metadata = SliceMetadata.from(mContext, wifiSlice);

@@ -76,6 +82,17 @@ public class WifiSliceTest {
        SliceTester.assertTitle(sliceItems, mContext.getString(R.string.wifi_settings));
    }

    @Test
    public void getWifiSlice_noAp_shouldReturnPlaceholder() {
        final Slice wifiSlice = mWifiSlice.getSlice();

        int rows = SliceQuery.findAll(wifiSlice, FORMAT_SLICE, HINT_LIST_ITEM,
                null /* nonHints */).size();
        // All AP rows + title row + see more row
        // (see more row will drop the last AP row, thus -1)
        assertThat(rows).isEqualTo(DEFAULT_EXPANDED_ROW_COUNT - 1 + 2);
    }

    @Test
    public void handleUriChange_updatesWifi() {
        final Intent intent = mWifiSlice.getIntent();