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

Commit 8cdbeab5 authored by Weng Su's avatar Weng Su Committed by Android (Google) Code Review
Browse files

Merge "Show Instant Tether network icon" into udc-qpr-dev

parents 82c36c5c c32f5cf3
Loading
Loading
Loading
Loading
+29 −15
Original line number Diff line number Diff line
@@ -15,6 +15,8 @@
 */
package com.android.settings.wifi;

import static com.android.settingslib.wifi.WifiUtils.getHotspotIconResource;

import android.annotation.Nullable;
import android.content.Context;
import android.content.res.Resources;
@@ -37,6 +39,7 @@ import com.android.settingslib.RestrictedPreference;
import com.android.settingslib.Utils;
import com.android.settingslib.wifi.WifiUtils;
import com.android.wifitrackerlib.BaseWifiTracker;
import com.android.wifitrackerlib.HotspotNetworkEntry;
import com.android.wifitrackerlib.WifiEntry;

/**
@@ -145,13 +148,17 @@ public class WifiEntryPreference extends RestrictedPreference implements
     */
    public void refresh() {
        setTitle(mWifiEntry.getTitle());
        final int level = mWifiEntry.getLevel();
        final boolean showX = mWifiEntry.shouldShowXLevelIcon();
        if (mWifiEntry instanceof HotspotNetworkEntry) {
            updateHotspotIcon(((HotspotNetworkEntry) mWifiEntry).getDeviceType());
        } else {
            int level = mWifiEntry.getLevel();
            boolean showX = mWifiEntry.shouldShowXLevelIcon();

            if (level != mLevel || showX != mShowX) {
                mLevel = level;
                mShowX = showX;
                updateIcon(mShowX, mLevel);
            notifyChanged();
            }
        }

        setSummary(mWifiEntry.getSummary(false /* concise */));
@@ -201,14 +208,7 @@ public class WifiEntryPreference extends RestrictedPreference implements
        return accent ? android.R.attr.colorAccent : android.R.attr.colorControlNormal;
    }

    @VisibleForTesting
    void updateIcon(boolean showX, int level) {
        if (level == -1) {
            setIcon(null);
            return;
        }

        final Drawable drawable = mIconInjector.getIcon(showX, level);
    private void setIconWithTint(Drawable drawable) {
        if (drawable != null) {
            // Must use Drawable#setTintList() instead of Drawable#setTint() to show the grey
            // icon when the preference is disabled.
@@ -219,6 +219,20 @@ public class WifiEntryPreference extends RestrictedPreference implements
        }
    }

    @VisibleForTesting
    void updateIcon(boolean showX, int level) {
        if (level == -1) {
            setIcon(null);
            return;
        }
        setIconWithTint(mIconInjector.getIcon(showX, level));
    }

    @VisibleForTesting
    void updateHotspotIcon(int deviceType) {
        setIconWithTint(getContext().getDrawable(getHotspotIconResource(deviceType)));
    }

    @Nullable
    private StateListDrawable getFrictionStateListDrawable() {
        TypedArray frictionSld;
+29 −0
Original line number Diff line number Diff line
@@ -18,11 +18,15 @@ package com.android.settings.wifi;
import static com.google.common.truth.Truth.assertThat;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.net.wifi.sharedconnectivity.app.NetworkProviderInfo;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
@@ -31,6 +35,7 @@ import androidx.preference.PreferenceViewHolder;

import com.android.settingslib.R;
import com.android.settingslib.wifi.WifiUtils;
import com.android.wifitrackerlib.HotspotNetworkEntry;
import com.android.wifitrackerlib.WifiEntry;

import org.junit.Before;
@@ -52,6 +57,8 @@ public class WifiEntryPreferenceTest {
    @Mock
    private WifiEntry mMockWifiEntry;
    @Mock
    private HotspotNetworkEntry mHotspotNetworkEntry;
    @Mock
    private WifiUtils.InternetIconInjector mMockIconInjector;

    @Mock
@@ -256,4 +263,26 @@ public class WifiEntryPreferenceTest {
    public void getSecondTargetResId_shouldNotReturnZero() {
        assertThat(mPref.getSecondTargetResId()).isNotEqualTo(0);
    }

    @Test
    public void refresh_itsHotspotNetworkEntry_shouldUpdateHotspotIcon() {
        int deviceType = NetworkProviderInfo.DEVICE_TYPE_PHONE;
        when(mHotspotNetworkEntry.getDeviceType()).thenReturn(deviceType);
        WifiEntryPreference pref = spy(
                new WifiEntryPreference(mContext, mHotspotNetworkEntry, mMockIconInjector));

        pref.refresh();

        verify(pref).updateHotspotIcon(deviceType);
    }

    @Test
    public void refresh_notHotspotNetworkEntry_shouldNotUpdateHotspotIcon() {
        WifiEntryPreference pref = spy(
                new WifiEntryPreference(mContext, mMockWifiEntry, mMockIconInjector));

        pref.refresh();

        verify(pref, never()).updateHotspotIcon(anyInt());
    }
}