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

Commit 60b850de authored by Fan Zhang's avatar Fan Zhang
Browse files

Add Wifi's security type to contentDescription

Change-Id: I0c1945fd8776814ddf0097c0c1f27ed4dd1c73b2
Fix: 63805288
Test: robotests
parent 78575081
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -237,6 +237,12 @@
    <!-- Content description of the WIFI signal when it is full for accessibility (not shown on the screen). [CHAR LIMIT=NONE] -->
    <string name="accessibility_wifi_signal_full">Wifi signal full.</string>

    <!-- Content description of the Wi-Fi security type. This message indicates this is an open Wi-Fi (no password needed) [CHAR LIMIT=NONE] -->
    <string name="accessibility_wifi_security_type_none">Open network</string>

    <!-- Content description of the Wi-Fi security type. This message indicates this is a secured Wi-Fi (password needed) [CHAR LIMIT=NONE] -->
    <string name="accessibility_wifi_security_type_secured">Secure network</string>

    <!-- Label for kernel threads in battery usage -->
    <string name="process_kernel_label">Android OS</string>
    <!-- Title of data usage item that represents all uninstalled applications. [CHAR LIMIT=48] -->
+36 −19
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import android.net.NetworkBadging;
import android.net.wifi.WifiConfiguration;
import android.os.Looper;
import android.os.UserHandle;
import android.support.annotation.VisibleForTesting;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceViewHolder;
import android.text.TextUtils;
@@ -47,7 +48,17 @@ public class AccessPointPreference extends Preference {
            R.attr.state_metered
    };

    private static final int[] wifi_friction_attributes = { R.attr.wifi_friction };
    private static final int[] FRICTION_ATTRS = {
            R.attr.wifi_friction
    };

    private static final int[] WIFI_CONNECTION_STRENGTH = {
            R.string.accessibility_no_wifi,
            R.string.accessibility_wifi_one_bar,
            R.string.accessibility_wifi_two_bars,
            R.string.accessibility_wifi_three_bars,
            R.string.accessibility_wifi_signal_full
    };

    private final StateListDrawable mFrictionSld;
    private final int mBadgePadding;
@@ -62,14 +73,6 @@ public class AccessPointPreference extends Preference {
    private int mDefaultIconResId;
    private int mWifiSpeed = NetworkBadging.BADGING_NONE;

    static final int[] WIFI_CONNECTION_STRENGTH = {
            R.string.accessibility_no_wifi,
            R.string.accessibility_wifi_one_bar,
            R.string.accessibility_wifi_two_bars,
            R.string.accessibility_wifi_three_bars,
            R.string.accessibility_wifi_signal_full
    };

    public static String generatePreferenceKey(AccessPoint accessPoint) {
        StringBuilder builder = new StringBuilder();

@@ -103,7 +106,7 @@ public class AccessPointPreference extends Preference {

        TypedArray frictionSld;
        try {
            frictionSld = context.getTheme().obtainStyledAttributes(wifi_friction_attributes);
            frictionSld = context.getTheme().obtainStyledAttributes(FRICTION_ATTRS);
        } catch (Resources.NotFoundException e) {
            // Fallback for platforms that do not need friction icon resources.
            frictionSld = null;
@@ -129,7 +132,7 @@ public class AccessPointPreference extends Preference {

        TypedArray frictionSld;
        try {
            frictionSld = context.getTheme().obtainStyledAttributes(wifi_friction_attributes);
            frictionSld = context.getTheme().obtainStyledAttributes(FRICTION_ATTRS);
        } catch (Resources.NotFoundException e) {
            // Fallback for platforms that do not need friction icon resources.
            frictionSld = null;
@@ -249,14 +252,7 @@ public class AccessPointPreference extends Preference {
        setSummary(mForSavedNetworks ? mAccessPoint.getSavedNetworkSummary()
                : mAccessPoint.getSettingsSummary());

        mContentDescription = getTitle();
        if (getSummary() != null) {
            mContentDescription = TextUtils.concat(mContentDescription, ",", getSummary());
        }
        if (level >= 0 && level < WIFI_CONNECTION_STRENGTH.length) {
            mContentDescription = TextUtils.concat(mContentDescription, ",",
                    getContext().getString(WIFI_CONNECTION_STRENGTH[level]));
        }
        mContentDescription = buildContentDescription(getContext(), this /* pref */, mAccessPoint);
    }

    @Override
@@ -269,6 +265,27 @@ public class AccessPointPreference extends Preference {
        }
    }

    /**
     * Helper method to generate content description string.
     */
    @VisibleForTesting
    static CharSequence buildContentDescription(Context context, Preference pref, AccessPoint ap) {
        CharSequence contentDescription = pref.getTitle();
        final CharSequence summary = pref.getSummary();
        if (!TextUtils.isEmpty(summary)) {
            contentDescription = TextUtils.concat(contentDescription, ",", summary);
        }
        int level = ap.getLevel();
        if (level >= 0 && level < WIFI_CONNECTION_STRENGTH.length) {
            contentDescription = TextUtils.concat(contentDescription, ",",
                    context.getString(WIFI_CONNECTION_STRENGTH[level]));
        }
        return TextUtils.concat(contentDescription, ",",
                ap.getSecurity() == AccessPoint.SECURITY_NONE
                        ? context.getString(R.string.accessibility_wifi_security_type_none)
                        : context.getString(R.string.accessibility_wifi_security_type_secured));
    }

    public void onLevelChanged() {
        postNotifyChanged();
    }
+26 −2
Original line number Diff line number Diff line
@@ -20,6 +20,9 @@ import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;
import org.robolectric.manifest.AndroidManifest;
import org.robolectric.res.Fs;
import org.robolectric.res.ResourcePath;

import java.util.List;

public class SettingLibRobolectricTestRunner extends RobolectricTestRunner {

@@ -36,10 +39,31 @@ public class SettingLibRobolectricTestRunner extends RobolectricTestRunner {
        final String assetsDir = appRoot + config.assetDir();

        final AndroidManifest manifest = new AndroidManifest(Fs.fileFromPath(manifestPath),
                Fs.fileFromPath(resDir), Fs.fileFromPath(assetsDir));

                Fs.fileFromPath(resDir), Fs.fileFromPath(assetsDir)) {
            @Override
            public List<ResourcePath> getIncludedResourcePaths() {
                List<ResourcePath> paths = super.getIncludedResourcePaths();
                SettingLibRobolectricTestRunner.getIncludedResourcePaths(getPackageName(), paths);
                return paths;
            }
        };
        manifest.setPackageName("com.android.settingslib");
        return manifest;
    }

    static void getIncludedResourcePaths(String packageName, List<ResourcePath> paths) {
        paths.add(new ResourcePath(
                packageName,
                Fs.fileFromPath("./frameworks/base/packages/SettingsLib/res"),
                null));
        paths.add(new ResourcePath(
                packageName,
                Fs.fileFromPath("./frameworks/base/core/res/res"),
                null));
        paths.add(new ResourcePath(
                packageName,
                Fs.fileFromPath("./frameworks/support/v7/appcompat/res"),
                null));
    }

}
+20 −0
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@
package com.android.settingslib.wifi;

import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import android.content.Context;

@@ -58,4 +60,22 @@ public class AccessPointPreferenceTest {
        assertThat(AccessPointPreference.generatePreferenceKey(builder.build()))
                .isEqualTo(expectedKey);
    }

    @Test
    public void refresh_openNetwork_updateContentDescription() {
        final String ssid = "ssid";
        final String summary = "connected";
        final int security = AccessPoint.SECURITY_WEP;
        final AccessPoint ap = new TestAccessPointBuilder(mContext)
                .setSsid(ssid)
                .setSecurity(security)
                .build();
        final AccessPointPreference pref = mock(AccessPointPreference.class);
        when(pref.getTitle()).thenReturn(ssid);
        when(pref.getSummary()).thenReturn(summary);

        assertThat(AccessPointPreference.buildContentDescription(
                RuntimeEnvironment.application, pref, ap))
                .isEqualTo("ssid,connected,Wifi signal full.,Secure network");
    }
}