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

Commit fb77e90d authored by Fabián Kozynski's avatar Fabián Kozynski
Browse files

Fix state description of CastTile

The cast tile was concatenating empty string (with commas) for its state
description, leading to bad state description.

Instead, make sure to only add non empty strings and then concatenate
what we actually have.

Test: manual, talkback
Test: atest CastTile
Flag: EXEMPT bugfix
Fixes: 412321774
Change-Id: I26fbdab916e2e05fdbc76d49affff3978b2d2231
parent 71572aa7
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@ package com.android.systemui.qs.tiles;

import static com.android.systemui.flags.Flags.SIGNAL_CALLBACK_DEPRECATION;

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

import static junit.framework.Assert.assertTrue;
import static junit.framework.TestCase.assertEquals;

@@ -544,6 +546,13 @@ public class CastTileTest extends SysuiTestCase {
        mCastTile.getDetailsViewModel(Assert::assertNotNull);
    }

    @Test
    public void testStateInactive_emptyStateDescription() {
        createAndStartTileOldImpl();
        enableWifiAndProcessMessages();
        assertThat(mCastTile.getState().stateDescription.isEmpty()).isTrue();
    }

    /**
     * For simplicity, let this method still set the field even though that's kind of gross
     */
+8 −5
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import android.os.Handler;
import android.os.Looper;
import android.provider.Settings;
import android.service.quicksettings.Tile;
import android.text.TextUtils;
import android.util.Log;
import android.widget.Button;

@@ -301,7 +302,7 @@ public class CastTile extends QSTileImpl<BooleanState> {
    protected void handleUpdateState(BooleanState state, Object arg) {
        state.label = mContext.getString(R.string.quick_settings_cast_title);
        state.contentDescription = state.label;
        state.stateDescription = "";
        ArrayList<CharSequence> stateDescriptionParts = new ArrayList<>();
        state.value = false;
        final List<CastDevice> devices = mController.getCastDevices();
        boolean connecting = false;
@@ -311,9 +312,8 @@ public class CastTile extends QSTileImpl<BooleanState> {
            if (device.getState() == CastDevice.CastState.Connected) {
                state.value = true;
                state.secondaryLabel = getDeviceName(device);
                state.stateDescription = state.stateDescription + ","
                        + mContext.getString(
                        R.string.accessibility_cast_name, state.label);
                stateDescriptionParts
                        .add(mContext.getString(R.string.accessibility_cast_name, state.label));
                connecting = false;
                break;
            } else if (device.getState() == CastDevice.CastState.Connecting) {
@@ -338,7 +338,10 @@ public class CastTile extends QSTileImpl<BooleanState> {
            state.secondaryLabel = noWifi;
            state.forceExpandIcon = false;
        }
        state.stateDescription = state.stateDescription + ", " + state.secondaryLabel;
        if (!TextUtils.isEmpty(state.secondaryLabel)) {
            stateDescriptionParts.add(state.secondaryLabel);
        }
        state.stateDescription = String.join(", ", stateDescriptionParts);
    }

    @Override