Loading packages/SystemUI/src/com/android/systemui/qs/tiles/dialog/InternetAdapter.java +23 −24 Original line number Diff line number Diff line Loading @@ -19,7 +19,6 @@ package com.android.systemui.qs.tiles.dialog; import static com.android.wifitrackerlib.WifiEntry.SECURITY_NONE; import static com.android.wifitrackerlib.WifiEntry.SECURITY_OWE; import android.annotation.ColorInt; import android.content.Context; import android.content.Intent; import android.graphics.drawable.Drawable; Loading @@ -35,10 +34,10 @@ import android.widget.LinearLayout; import android.widget.TextView; import androidx.annotation.NonNull; import androidx.annotation.VisibleForTesting; import androidx.recyclerview.widget.RecyclerView; import com.android.settingslib.Utils; import com.android.settingslib.wifi.WifiUtils; import com.android.systemui.R; import com.android.wifitrackerlib.WifiEntry; Loading Loading @@ -98,8 +97,7 @@ public class InternetAdapter extends RecyclerView.Adapter<InternetAdapter.Intern } return mInternetDialogController.getWifiEntryList().stream() .filter(wifiAp -> wifiAp.getConnectedState() != WifiEntry.CONNECTED_STATE_CONNECTED) .filter(wifiEntry -> !wifiEntry.isDefaultNetwork()) .limit(getItemCount()) .collect(Collectors.toList()); } Loading @@ -109,21 +107,21 @@ public class InternetAdapter extends RecyclerView.Adapter<InternetAdapter.Intern * {@link InternetDialog}. * * Airplane mode is ON (mobile network is gone): * Return four Wi-Fi's entries if no connected Wi-Fi. * Return three Wi-Fi's entries if one connected Wi-Fi. * Return four Wi-Fi's entries if no default Wi-Fi. * Return three Wi-Fi's entries if one default Wi-Fi. * Airplane mode is OFF (mobile network is visible): * Return three Wi-Fi's entries if no connected Wi-Fi. * Return two Wi-Fi's entries if one connected Wi-Fi. * Return three Wi-Fi's entries if no default Wi-Fi. * Return two Wi-Fi's entries if one default Wi-Fi. * * @return The total number of networks. */ @Override public int getItemCount() { boolean hasConnectedWifi = mInternetDialogController.getConnectedWifiEntry() != null; final boolean hasDefaultWifi = mInternetDialogController.getDefaultWifiEntry() != null; if (mInternetDialogController.isAirplaneModeEnabled()) { return hasConnectedWifi ? 3 : 4; return hasDefaultWifi ? 3 : 4; } else { return hasConnectedWifi ? 2 : 3; return hasDefaultWifi ? 2 : 3; } } Loading @@ -142,6 +140,8 @@ public class InternetAdapter extends RecyclerView.Adapter<InternetAdapter.Intern final Context mContext; final InternetDialogController mInternetDialogController; protected WifiUtils.InternetIconInjector mWifiIconInjector; InternetViewHolder(View view, InternetDialogController internetDialogController) { super(view); mContext = view.getContext(); Loading @@ -153,6 +153,7 @@ public class InternetAdapter extends RecyclerView.Adapter<InternetAdapter.Intern mWifiTitleText = view.requireViewById(R.id.wifi_title); mWifiSummaryText = view.requireViewById(R.id.wifi_summary); mWifiLockedIcon = view.requireViewById(R.id.wifi_locked_icon); mWifiIconInjector = mInternetDialogController.getWifiIconInjector(); } void onBind(WifiEntry wifiEntry) { Loading Loading @@ -207,19 +208,17 @@ public class InternetAdapter extends RecyclerView.Adapter<InternetAdapter.Intern mWifiSummaryText.setText(summary); } Drawable getWifiDrawable(WifiEntry wifiEntry) throws Throwable { Drawable drawable = mContext.getDrawable( com.android.internal.R.drawable.ic_wifi_signal_0); AtomicReference<Drawable> shared = new AtomicReference<>(); final @ColorInt int tint = Utils.getColorAttrDefaultColor(mContext, android.R.attr.colorControlNormal); Drawable signalDrawable = mContext.getDrawable( Utils.getWifiIconResource(wifiEntry.getLevel())); signalDrawable.setTint(tint); shared.set(signalDrawable); drawable = shared.get(); return drawable; Drawable getWifiDrawable(@NonNull WifiEntry wifiEntry) throws Throwable { final Drawable drawable = mWifiIconInjector.getIcon(wifiEntry.shouldShowXLevelIcon(), wifiEntry.getLevel()); if (drawable == null) { return null; } drawable.setTint( Utils.getColorAttrDefaultColor(mContext, android.R.attr.colorControlNormal)); final AtomicReference<Drawable> shared = new AtomicReference<>(); shared.set(drawable); return shared.get(); } } } packages/SystemUI/src/com/android/systemui/qs/tiles/dialog/InternetDialog.java +7 −15 Original line number Diff line number Diff line Loading @@ -91,6 +91,8 @@ public class InternetDialog extends SystemUIDialog implements protected WifiManager mWifiManager; @VisibleForTesting protected View mDialogView; @VisibleForTesting protected WifiEntry mConnectedWifiEntry; private InternetDialogFactory mInternetDialogFactory; private SubscriptionManager mSubscriptionManager; Loading Loading @@ -123,7 +125,6 @@ public class InternetDialog extends SystemUIDialog implements private Switch mWiFiToggle; private Button mDoneButton; private Drawable mBackgroundOn; private WifiEntry mConnectedWifiEntry; private int mListMaxHeight; private int mDefaultDataSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; private boolean mCanConfigMobileData; Loading Loading @@ -355,8 +356,7 @@ public class InternetDialog extends SystemUIDialog implements } private void setConnectedWifiLayout() { if (!mWifiManager.isWifiEnabled() || mInternetDialogController.getConnectedWifiEntry() == null) { if (!mWifiManager.isWifiEnabled() || mConnectedWifiEntry == null) { mConnectedWifListLayout.setBackground(null); mConnectedWifListLayout.setVisibility(View.GONE); return; Loading @@ -364,7 +364,8 @@ public class InternetDialog extends SystemUIDialog implements mConnectedWifListLayout.setVisibility(View.VISIBLE); mConnectedWifiTitleText.setText(getConnectedWifiTitle()); mConnectedWifiSummaryText.setText(getConnectedWifiSummary()); mConnectedWifiIcon.setImageDrawable(getConnectedWifiDrawable()); mConnectedWifiIcon.setImageDrawable( mInternetDialogController.getConnectedWifiDrawable(mConnectedWifiEntry)); mConnectedWifiTitleText.setTextColor( mContext.getColor(R.color.connected_network_primary_color)); mConnectedWifiSummaryText.setTextColor( Loading @@ -391,15 +392,6 @@ public class InternetDialog extends SystemUIDialog implements mIsProgressBarVisible && !mIsSearchingHidden); } private Drawable getConnectedWifiDrawable() { try { return mInternetDialogController.getWifiConnectedDrawable(mConnectedWifiEntry); } catch (Throwable e) { e.printStackTrace(); } return null; } private Drawable getSignalStrengthDrawable() { return mInternetDialogController.getSignalStrengthDrawable(); } Loading @@ -413,11 +405,11 @@ public class InternetDialog extends SystemUIDialog implements } String getConnectedWifiTitle() { return mInternetDialogController.getConnectedWifiTitle(); return mInternetDialogController.getDefaultWifiTitle(); } String getConnectedWifiSummary() { return mInternetDialogController.getConnectedWifiSummary(); return mInternetDialogController.getDefaultWifiSummary(); } protected void showProgressBar() { Loading packages/SystemUI/src/com/android/systemui/qs/tiles/dialog/InternetDialogController.java +27 −18 Original line number Diff line number Diff line Loading @@ -19,7 +19,6 @@ package com.android.systemui.qs.tiles.dialog; import static com.android.settingslib.mobile.MobileMappings.getIconKey; import static com.android.settingslib.mobile.MobileMappings.mapIconSets; import android.annotation.ColorInt; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; Loading Loading @@ -134,6 +133,8 @@ public class InternetDialogController implements WifiEntry.DisconnectCallback, protected SubscriptionManager.OnSubscriptionsChangedListener mOnSubscriptionsChangedListener; @VisibleForTesting protected InternetTelephonyCallback mInternetTelephonyCallback; @VisibleForTesting protected WifiUtils.InternetIconInjector mWifiIconInjector; private final KeyguardUpdateMonitorCallback mKeyguardUpdateCallback = new KeyguardUpdateMonitorCallback() { Loading Loading @@ -181,6 +182,7 @@ public class InternetDialogController implements WifiEntry.DisconnectCallback, mActivityStarter = starter; mAccessPointController = accessPointController; mConfig = MobileMappings.Config.readConfig(mContext); mWifiIconInjector = new WifiUtils.InternetIconInjector(mContext); } void onStart(@NonNull InternetDialogCallback callback) { Loading Loading @@ -315,14 +317,14 @@ public class InternetDialogController implements WifiEntry.DisconnectCallback, return mContext.getText(SUBTITLE_TEXT_NON_CARRIER_NETWORK_UNAVAILABLE); } Drawable getWifiConnectedDrawable(WifiEntry wifiEntry) throws Throwable { final @ColorInt int tint; tint = Utils.getColorAttrDefaultColor(mContext, com.android.internal.R.attr.colorControlNormal); final Drawable drawable = mContext.getDrawable( com.android.settingslib.Utils.getWifiIconResource(wifiEntry.getLevel())); drawable.setTint(tint); Drawable getConnectedWifiDrawable(@NonNull WifiEntry wifiEntry) { final Drawable drawable = mWifiIconInjector.getIcon(false /* noInternet*/, wifiEntry.getLevel()); if (drawable == null) { return null; } drawable.setTint(Utils.getColorAttrDefaultColor(mContext, com.android.internal.R.attr.colorControlNormal)); return drawable; } Loading Loading @@ -525,24 +527,24 @@ public class InternetDialogController implements WifiEntry.DisconnectCallback, return summary; } String getConnectedWifiTitle() { if (getConnectedWifiEntry() == null) { String getDefaultWifiTitle() { if (getDefaultWifiEntry() == null) { if (DEBUG) { Log.d(TAG, "connected entry is null"); } return ""; } return getConnectedWifiEntry().getTitle(); return getDefaultWifiEntry().getTitle(); } String getConnectedWifiSummary() { if (getConnectedWifiEntry() == null) { String getDefaultWifiSummary() { if (getDefaultWifiEntry() == null) { if (DEBUG) { Log.d(TAG, "connected entry is null"); } return ""; } return getConnectedWifiEntry().getSummary(false); return getDefaultWifiEntry().getSummary(false); } void launchNetworkSetting() { Loading Loading @@ -570,9 +572,12 @@ public class InternetDialogController implements WifiEntry.DisconnectCallback, return mWifiEntry; } WifiEntry getConnectedWifiEntry() { WifiEntry getDefaultWifiEntry() { if (mConnectedEntry != null && mConnectedEntry.isDefaultNetwork()) { return mConnectedEntry; } return null; } WifiManager getWifiManager() { return mWifiManager; Loading Loading @@ -770,7 +775,7 @@ public class InternetDialogController implements WifiEntry.DisconnectCallback, mConnectedEntry = null; } mCallback.onAccessPointsChanged(mWifiEntry, mConnectedEntry); mCallback.onAccessPointsChanged(mWifiEntry, getDefaultWifiEntry()); } @Override Loading Loading @@ -873,6 +878,10 @@ public class InternetDialogController implements WifiEntry.DisconnectCallback, } } public WifiUtils.InternetIconInjector getWifiIconInjector() { return mWifiIconInjector; } interface InternetDialogCallback { void onRefreshCarrierInfo(); Loading packages/SystemUI/tests/src/com/android/systemui/qs/tiles/dialog/InternetAdapterTest.java +40 −15 Original line number Diff line number Diff line Loading @@ -2,7 +2,9 @@ package com.android.systemui.qs.tiles.dialog; import static com.google.common.truth.Truth.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import android.testing.AndroidTestingRunner; Loading @@ -11,6 +13,7 @@ import android.widget.LinearLayout; import androidx.test.filters.SmallTest; import com.android.settingslib.wifi.WifiUtils; import com.android.systemui.SysuiTestCase; import com.android.wifitrackerlib.WifiEntry; Loading @@ -28,51 +31,55 @@ public class InternetAdapterTest extends SysuiTestCase { private static final String WIFI_TITLE = "Wi-Fi Title"; private static final String WIFI_SUMMARY = "Wi-Fi Summary"; private InternetDialogController mInternetDialogController = mock( InternetDialogController.class); @Mock private WifiEntry mWifiEntry; @Mock private InternetDialogController mInternetDialogController; @Mock private WifiUtils.InternetIconInjector mWifiIconInjector; private InternetAdapter mInternetAdapter; private InternetAdapter.InternetViewHolder mViewHolder; @Mock private WifiEntry mWifiEntry = mock(WifiEntry.class); @Before public void setUp() { MockitoAnnotations.initMocks(this); mInternetAdapter = new InternetAdapter(mInternetDialogController); mViewHolder = (InternetAdapter.InternetViewHolder) mInternetAdapter .onCreateViewHolder(new LinearLayout(mContext), 0); mViewHolder = mInternetAdapter.onCreateViewHolder(new LinearLayout(mContext), 0); when(mWifiEntry.getTitle()).thenReturn(WIFI_TITLE); when(mWifiEntry.getSummary(false)).thenReturn(WIFI_SUMMARY); when(mInternetDialogController.getWifiEntryList()).thenReturn(Arrays.asList(mWifiEntry)); mViewHolder.mWifiIconInjector = mWifiIconInjector; } @Test public void getItemCount_withApmOnWifiOnNoConnectedWifi_returnFour() { public void getItemCount_withApmOnWifiOnNoDefaultWifi_returnFour() { when(mInternetDialogController.isAirplaneModeEnabled()).thenReturn(true); assertThat(mInternetAdapter.getItemCount()).isEqualTo(4); } @Test public void getItemCount_withApmOnWifiOnHasConnectedWifi_returnThree() { when(mWifiEntry.getConnectedState()).thenReturn(WifiEntry.CONNECTED_STATE_CONNECTED); when(mInternetDialogController.getConnectedWifiEntry()).thenReturn(mWifiEntry); public void getItemCount_withApmOnWifiOnHasDefaultWifi_returnThree() { when(mWifiEntry.isDefaultNetwork()).thenReturn(true); when(mInternetDialogController.getDefaultWifiEntry()).thenReturn(mWifiEntry); when(mInternetDialogController.isAirplaneModeEnabled()).thenReturn(true); assertThat(mInternetAdapter.getItemCount()).isEqualTo(3); } @Test public void getItemCount_withApmOffWifiOnNoConnectedWifi_returnThree() { public void getItemCount_withApmOffWifiOnNoDefaultWifi_returnThree() { when(mInternetDialogController.isAirplaneModeEnabled()).thenReturn(false); assertThat(mInternetAdapter.getItemCount()).isEqualTo(3); } @Test public void getItemCount_withApmOffWifiOnHasConnectedWifi_returnTwo() { when(mWifiEntry.getConnectedState()).thenReturn(WifiEntry.CONNECTED_STATE_CONNECTED); when(mInternetDialogController.getConnectedWifiEntry()).thenReturn(mWifiEntry); public void getItemCount_withApmOffWifiOnHasDefaultWifi_returnTwo() { when(mWifiEntry.isDefaultNetwork()).thenReturn(true); when(mInternetDialogController.getDefaultWifiEntry()).thenReturn(mWifiEntry); when(mInternetDialogController.isAirplaneModeEnabled()).thenReturn(false); assertThat(mInternetAdapter.getItemCount()).isEqualTo(2); Loading @@ -99,4 +106,22 @@ public class InternetAdapterTest extends SysuiTestCase { assertThat(mViewHolder.mWifiIcon.getVisibility()).isEqualTo(View.VISIBLE); assertThat(mViewHolder.mWifiLockedIcon.getVisibility()).isEqualTo(View.VISIBLE); } @Test public void onBindViewHolder_bindDefaultWifiNetwork_getIconWithInternet() { when(mWifiEntry.shouldShowXLevelIcon()).thenReturn(false); mInternetAdapter.onBindViewHolder(mViewHolder, 0); verify(mWifiIconInjector).getIcon(eq(false) /* noInternet */, anyInt()); } @Test public void onBindViewHolder_bindNoDefaultWifiNetwork_getIconWithNoInternet() { when(mWifiEntry.shouldShowXLevelIcon()).thenReturn(true); mInternetAdapter.onBindViewHolder(mViewHolder, 0); verify(mWifiIconInjector).getIcon(eq(true) /* noInternet */, anyInt()); } } packages/SystemUI/tests/src/com/android/systemui/qs/tiles/dialog/InternetDialogControllerTest.java +67 −26 Original line number Diff line number Diff line Loading @@ -4,7 +4,9 @@ import static com.google.common.truth.Truth.assertThat; import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; Loading @@ -13,6 +15,7 @@ import static org.mockito.Mockito.when; import android.content.Context; import android.content.Intent; import android.graphics.drawable.Drawable; import android.net.ConnectivityManager; import android.net.wifi.ScanResult; import android.net.wifi.WifiInfo; Loading @@ -30,6 +33,8 @@ import androidx.test.filters.SmallTest; import com.android.internal.logging.UiEventLogger; import com.android.keyguard.KeyguardUpdateMonitor; import com.android.settingslib.Utils; import com.android.settingslib.wifi.WifiUtils; import com.android.systemui.SysuiTestCase; import com.android.systemui.broadcast.BroadcastDispatcher; import com.android.systemui.dagger.qualifiers.Main; Loading Loading @@ -60,16 +65,12 @@ public class InternetDialogControllerTest extends SysuiTestCase { private static final String CONNECTED_TITLE = "Connected Wi-Fi Title"; private static final String CONNECTED_SUMMARY = "Connected Wi-Fi Summary"; private final UiEventLogger mUiEventLogger = mock(UiEventLogger.class); private MockInternetDialogController mInternetDialogController; private InternetDialogController.InternetDialogCallback mCallback = mock(InternetDialogController.InternetDialogCallback.class); private ActivityStarter mStarter = mock(ActivityStarter.class); private WifiManager mWifiManager = mock(WifiManager.class); private ConnectivityManager mConnectivityManager = mock(ConnectivityManager.class); private TelephonyManager mTelephonyManager = mock(TelephonyManager.class); private SubscriptionManager mSubscriptionManager = mock(SubscriptionManager.class); private FakeExecutor mExecutor = new FakeExecutor(new FakeSystemClock()); @Mock private WifiManager mWifiManager; @Mock private TelephonyManager mTelephonyManager; @Mock private SubscriptionManager mSubscriptionManager; @Mock private Handler mHandler; @Mock Loading @@ -88,21 +89,31 @@ public class InternetDialogControllerTest extends SysuiTestCase { private ServiceState mServiceState; @Mock private BroadcastDispatcher mBroadcastDispatcher; @Mock private WifiUtils.InternetIconInjector mWifiIconInjector; private MockInternetDialogController mInternetDialogController; private FakeExecutor mExecutor = new FakeExecutor(new FakeSystemClock()); @Before public void setUp() { MockitoAnnotations.initMocks(this); doReturn(mTelephonyManager).when(mTelephonyManager).createForSubscriptionId(SUB_ID); when(mWifiManager.getConnectionInfo()).thenReturn(mWifiInfo); mInternetDialogController = new MockInternetDialogController(mContext, mUiEventLogger, mStarter, mAccessPointController, mSubscriptionManager, mTelephonyManager, mWifiManager, mConnectivityManager, mHandler, mExecutor, mBroadcastDispatcher, when(mConnectedEntry.isDefaultNetwork()).thenReturn(true); mInternetDialogController = new MockInternetDialogController(mContext, mock(UiEventLogger.class), mock(ActivityStarter.class), mAccessPointController, mSubscriptionManager, mTelephonyManager, mWifiManager, mock(ConnectivityManager.class), mHandler, mExecutor, mBroadcastDispatcher, mKeyguardUpdateMonitor, mGlobalSettings); mSubscriptionManager.addOnSubscriptionsChangedListener(mExecutor, mInternetDialogController.mOnSubscriptionsChangedListener); mInternetDialogController.onStart(mCallback); mInternetDialogController.onStart( mock(InternetDialogController.InternetDialogCallback.class)); mInternetDialogController.mActivityStarter = mActivityStarter; mInternetDialogController.mConnectedEntry = mConnectedEntry; mInternetDialogController.mWifiIconInjector = mWifiIconInjector; } @Test Loading Loading @@ -199,35 +210,53 @@ public class InternetDialogControllerTest extends SysuiTestCase { } @Test public void getConnectedWifiTitle_withNoConnectedEntry_returnNull() { public void getDefaultWifiEntry_connectedEntryIsNull_returnNull() { mInternetDialogController.mConnectedEntry = null; assertThat(mInternetDialogController.getDefaultWifiEntry()).isNull(); } @Test public void getDefaultWifiEntry_connectedEntryIsNotDefault_returnNull() { when(mConnectedEntry.isDefaultNetwork()).thenReturn(false); assertThat(mInternetDialogController.getDefaultWifiEntry()).isNull(); } @Test public void getDefaultWifiEntry_connectedEntryIsDefault_returnConnectedEntry() { // The default conditions have been set in setUp(). // - The connected Wi-Fi entry with the default network condition. assertThat(mInternetDialogController.getDefaultWifiEntry()).isEqualTo(mConnectedEntry); } @Test public void getDefaultWifiTitle_withNoDefaultEntry_returnEmpty() { mInternetDialogController.mConnectedEntry = null; assertTrue(TextUtils.equals(mInternetDialogController.getConnectedWifiTitle(), "")); assertThat(mInternetDialogController.getDefaultWifiTitle()).isEmpty(); } @Test public void getConnectedWifiTitle_withConnectedEntry_returnTitle() { public void getDefaultWifiTitle_withDefaultEntry_returnTitle() { when(mConnectedEntry.getTitle()).thenReturn(CONNECTED_TITLE); assertTrue(TextUtils.equals(mInternetDialogController.getConnectedWifiTitle(), CONNECTED_TITLE)); assertThat(mInternetDialogController.getDefaultWifiTitle()).isEqualTo(CONNECTED_TITLE); } @Test public void getConnectedWifiSummary_withNoConnectedEntry_returnNull() { public void getDefaultWifiSummary_withNoDefaultEntry_returnEmpty() { mInternetDialogController.mConnectedEntry = null; assertTrue(TextUtils.equals(mInternetDialogController.getConnectedWifiSummary(), "")); assertThat(mInternetDialogController.getDefaultWifiSummary()).isEmpty(); } @Test public void getConnectedWifiSummary_withConnectedEntry_returnSummary() { public void getDefaultWifiSummary_withDefaultEntry_returnSummary() { when(mConnectedEntry.getSummary(false)).thenReturn(CONNECTED_SUMMARY); assertTrue(TextUtils.equals(mInternetDialogController.getConnectedWifiSummary(), CONNECTED_SUMMARY)); assertThat(mInternetDialogController.getDefaultWifiSummary()).isEqualTo(CONNECTED_SUMMARY); } @Test Loading @@ -251,6 +280,18 @@ public class InternetDialogControllerTest extends SysuiTestCase { assertThat(mInternetDialogController.getWifiDetailsSettingsIntent()).isNotNull(); } @Test public void getWifiConnectedDrawable_withConnectedEntry_returnIntentIconWithColorAccent() { final Drawable drawable = mock(Drawable.class); when(mWifiIconInjector.getIcon(anyBoolean(), anyInt())).thenReturn(drawable); mInternetDialogController.getConnectedWifiDrawable(mConnectedEntry); verify(mWifiIconInjector).getIcon(eq(false), anyInt()); verify(drawable).setTint(Utils.getColorAttrDefaultColor(mContext, com.android.internal.R.attr.colorControlNormal)); } @Test public void launchWifiNetworkDetailsSetting_withNoConnectedEntry_doNothing() { mInternetDialogController.mConnectedEntry = null; Loading Loading
packages/SystemUI/src/com/android/systemui/qs/tiles/dialog/InternetAdapter.java +23 −24 Original line number Diff line number Diff line Loading @@ -19,7 +19,6 @@ package com.android.systemui.qs.tiles.dialog; import static com.android.wifitrackerlib.WifiEntry.SECURITY_NONE; import static com.android.wifitrackerlib.WifiEntry.SECURITY_OWE; import android.annotation.ColorInt; import android.content.Context; import android.content.Intent; import android.graphics.drawable.Drawable; Loading @@ -35,10 +34,10 @@ import android.widget.LinearLayout; import android.widget.TextView; import androidx.annotation.NonNull; import androidx.annotation.VisibleForTesting; import androidx.recyclerview.widget.RecyclerView; import com.android.settingslib.Utils; import com.android.settingslib.wifi.WifiUtils; import com.android.systemui.R; import com.android.wifitrackerlib.WifiEntry; Loading Loading @@ -98,8 +97,7 @@ public class InternetAdapter extends RecyclerView.Adapter<InternetAdapter.Intern } return mInternetDialogController.getWifiEntryList().stream() .filter(wifiAp -> wifiAp.getConnectedState() != WifiEntry.CONNECTED_STATE_CONNECTED) .filter(wifiEntry -> !wifiEntry.isDefaultNetwork()) .limit(getItemCount()) .collect(Collectors.toList()); } Loading @@ -109,21 +107,21 @@ public class InternetAdapter extends RecyclerView.Adapter<InternetAdapter.Intern * {@link InternetDialog}. * * Airplane mode is ON (mobile network is gone): * Return four Wi-Fi's entries if no connected Wi-Fi. * Return three Wi-Fi's entries if one connected Wi-Fi. * Return four Wi-Fi's entries if no default Wi-Fi. * Return three Wi-Fi's entries if one default Wi-Fi. * Airplane mode is OFF (mobile network is visible): * Return three Wi-Fi's entries if no connected Wi-Fi. * Return two Wi-Fi's entries if one connected Wi-Fi. * Return three Wi-Fi's entries if no default Wi-Fi. * Return two Wi-Fi's entries if one default Wi-Fi. * * @return The total number of networks. */ @Override public int getItemCount() { boolean hasConnectedWifi = mInternetDialogController.getConnectedWifiEntry() != null; final boolean hasDefaultWifi = mInternetDialogController.getDefaultWifiEntry() != null; if (mInternetDialogController.isAirplaneModeEnabled()) { return hasConnectedWifi ? 3 : 4; return hasDefaultWifi ? 3 : 4; } else { return hasConnectedWifi ? 2 : 3; return hasDefaultWifi ? 2 : 3; } } Loading @@ -142,6 +140,8 @@ public class InternetAdapter extends RecyclerView.Adapter<InternetAdapter.Intern final Context mContext; final InternetDialogController mInternetDialogController; protected WifiUtils.InternetIconInjector mWifiIconInjector; InternetViewHolder(View view, InternetDialogController internetDialogController) { super(view); mContext = view.getContext(); Loading @@ -153,6 +153,7 @@ public class InternetAdapter extends RecyclerView.Adapter<InternetAdapter.Intern mWifiTitleText = view.requireViewById(R.id.wifi_title); mWifiSummaryText = view.requireViewById(R.id.wifi_summary); mWifiLockedIcon = view.requireViewById(R.id.wifi_locked_icon); mWifiIconInjector = mInternetDialogController.getWifiIconInjector(); } void onBind(WifiEntry wifiEntry) { Loading Loading @@ -207,19 +208,17 @@ public class InternetAdapter extends RecyclerView.Adapter<InternetAdapter.Intern mWifiSummaryText.setText(summary); } Drawable getWifiDrawable(WifiEntry wifiEntry) throws Throwable { Drawable drawable = mContext.getDrawable( com.android.internal.R.drawable.ic_wifi_signal_0); AtomicReference<Drawable> shared = new AtomicReference<>(); final @ColorInt int tint = Utils.getColorAttrDefaultColor(mContext, android.R.attr.colorControlNormal); Drawable signalDrawable = mContext.getDrawable( Utils.getWifiIconResource(wifiEntry.getLevel())); signalDrawable.setTint(tint); shared.set(signalDrawable); drawable = shared.get(); return drawable; Drawable getWifiDrawable(@NonNull WifiEntry wifiEntry) throws Throwable { final Drawable drawable = mWifiIconInjector.getIcon(wifiEntry.shouldShowXLevelIcon(), wifiEntry.getLevel()); if (drawable == null) { return null; } drawable.setTint( Utils.getColorAttrDefaultColor(mContext, android.R.attr.colorControlNormal)); final AtomicReference<Drawable> shared = new AtomicReference<>(); shared.set(drawable); return shared.get(); } } }
packages/SystemUI/src/com/android/systemui/qs/tiles/dialog/InternetDialog.java +7 −15 Original line number Diff line number Diff line Loading @@ -91,6 +91,8 @@ public class InternetDialog extends SystemUIDialog implements protected WifiManager mWifiManager; @VisibleForTesting protected View mDialogView; @VisibleForTesting protected WifiEntry mConnectedWifiEntry; private InternetDialogFactory mInternetDialogFactory; private SubscriptionManager mSubscriptionManager; Loading Loading @@ -123,7 +125,6 @@ public class InternetDialog extends SystemUIDialog implements private Switch mWiFiToggle; private Button mDoneButton; private Drawable mBackgroundOn; private WifiEntry mConnectedWifiEntry; private int mListMaxHeight; private int mDefaultDataSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; private boolean mCanConfigMobileData; Loading Loading @@ -355,8 +356,7 @@ public class InternetDialog extends SystemUIDialog implements } private void setConnectedWifiLayout() { if (!mWifiManager.isWifiEnabled() || mInternetDialogController.getConnectedWifiEntry() == null) { if (!mWifiManager.isWifiEnabled() || mConnectedWifiEntry == null) { mConnectedWifListLayout.setBackground(null); mConnectedWifListLayout.setVisibility(View.GONE); return; Loading @@ -364,7 +364,8 @@ public class InternetDialog extends SystemUIDialog implements mConnectedWifListLayout.setVisibility(View.VISIBLE); mConnectedWifiTitleText.setText(getConnectedWifiTitle()); mConnectedWifiSummaryText.setText(getConnectedWifiSummary()); mConnectedWifiIcon.setImageDrawable(getConnectedWifiDrawable()); mConnectedWifiIcon.setImageDrawable( mInternetDialogController.getConnectedWifiDrawable(mConnectedWifiEntry)); mConnectedWifiTitleText.setTextColor( mContext.getColor(R.color.connected_network_primary_color)); mConnectedWifiSummaryText.setTextColor( Loading @@ -391,15 +392,6 @@ public class InternetDialog extends SystemUIDialog implements mIsProgressBarVisible && !mIsSearchingHidden); } private Drawable getConnectedWifiDrawable() { try { return mInternetDialogController.getWifiConnectedDrawable(mConnectedWifiEntry); } catch (Throwable e) { e.printStackTrace(); } return null; } private Drawable getSignalStrengthDrawable() { return mInternetDialogController.getSignalStrengthDrawable(); } Loading @@ -413,11 +405,11 @@ public class InternetDialog extends SystemUIDialog implements } String getConnectedWifiTitle() { return mInternetDialogController.getConnectedWifiTitle(); return mInternetDialogController.getDefaultWifiTitle(); } String getConnectedWifiSummary() { return mInternetDialogController.getConnectedWifiSummary(); return mInternetDialogController.getDefaultWifiSummary(); } protected void showProgressBar() { Loading
packages/SystemUI/src/com/android/systemui/qs/tiles/dialog/InternetDialogController.java +27 −18 Original line number Diff line number Diff line Loading @@ -19,7 +19,6 @@ package com.android.systemui.qs.tiles.dialog; import static com.android.settingslib.mobile.MobileMappings.getIconKey; import static com.android.settingslib.mobile.MobileMappings.mapIconSets; import android.annotation.ColorInt; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; Loading Loading @@ -134,6 +133,8 @@ public class InternetDialogController implements WifiEntry.DisconnectCallback, protected SubscriptionManager.OnSubscriptionsChangedListener mOnSubscriptionsChangedListener; @VisibleForTesting protected InternetTelephonyCallback mInternetTelephonyCallback; @VisibleForTesting protected WifiUtils.InternetIconInjector mWifiIconInjector; private final KeyguardUpdateMonitorCallback mKeyguardUpdateCallback = new KeyguardUpdateMonitorCallback() { Loading Loading @@ -181,6 +182,7 @@ public class InternetDialogController implements WifiEntry.DisconnectCallback, mActivityStarter = starter; mAccessPointController = accessPointController; mConfig = MobileMappings.Config.readConfig(mContext); mWifiIconInjector = new WifiUtils.InternetIconInjector(mContext); } void onStart(@NonNull InternetDialogCallback callback) { Loading Loading @@ -315,14 +317,14 @@ public class InternetDialogController implements WifiEntry.DisconnectCallback, return mContext.getText(SUBTITLE_TEXT_NON_CARRIER_NETWORK_UNAVAILABLE); } Drawable getWifiConnectedDrawable(WifiEntry wifiEntry) throws Throwable { final @ColorInt int tint; tint = Utils.getColorAttrDefaultColor(mContext, com.android.internal.R.attr.colorControlNormal); final Drawable drawable = mContext.getDrawable( com.android.settingslib.Utils.getWifiIconResource(wifiEntry.getLevel())); drawable.setTint(tint); Drawable getConnectedWifiDrawable(@NonNull WifiEntry wifiEntry) { final Drawable drawable = mWifiIconInjector.getIcon(false /* noInternet*/, wifiEntry.getLevel()); if (drawable == null) { return null; } drawable.setTint(Utils.getColorAttrDefaultColor(mContext, com.android.internal.R.attr.colorControlNormal)); return drawable; } Loading Loading @@ -525,24 +527,24 @@ public class InternetDialogController implements WifiEntry.DisconnectCallback, return summary; } String getConnectedWifiTitle() { if (getConnectedWifiEntry() == null) { String getDefaultWifiTitle() { if (getDefaultWifiEntry() == null) { if (DEBUG) { Log.d(TAG, "connected entry is null"); } return ""; } return getConnectedWifiEntry().getTitle(); return getDefaultWifiEntry().getTitle(); } String getConnectedWifiSummary() { if (getConnectedWifiEntry() == null) { String getDefaultWifiSummary() { if (getDefaultWifiEntry() == null) { if (DEBUG) { Log.d(TAG, "connected entry is null"); } return ""; } return getConnectedWifiEntry().getSummary(false); return getDefaultWifiEntry().getSummary(false); } void launchNetworkSetting() { Loading Loading @@ -570,9 +572,12 @@ public class InternetDialogController implements WifiEntry.DisconnectCallback, return mWifiEntry; } WifiEntry getConnectedWifiEntry() { WifiEntry getDefaultWifiEntry() { if (mConnectedEntry != null && mConnectedEntry.isDefaultNetwork()) { return mConnectedEntry; } return null; } WifiManager getWifiManager() { return mWifiManager; Loading Loading @@ -770,7 +775,7 @@ public class InternetDialogController implements WifiEntry.DisconnectCallback, mConnectedEntry = null; } mCallback.onAccessPointsChanged(mWifiEntry, mConnectedEntry); mCallback.onAccessPointsChanged(mWifiEntry, getDefaultWifiEntry()); } @Override Loading Loading @@ -873,6 +878,10 @@ public class InternetDialogController implements WifiEntry.DisconnectCallback, } } public WifiUtils.InternetIconInjector getWifiIconInjector() { return mWifiIconInjector; } interface InternetDialogCallback { void onRefreshCarrierInfo(); Loading
packages/SystemUI/tests/src/com/android/systemui/qs/tiles/dialog/InternetAdapterTest.java +40 −15 Original line number Diff line number Diff line Loading @@ -2,7 +2,9 @@ package com.android.systemui.qs.tiles.dialog; import static com.google.common.truth.Truth.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import android.testing.AndroidTestingRunner; Loading @@ -11,6 +13,7 @@ import android.widget.LinearLayout; import androidx.test.filters.SmallTest; import com.android.settingslib.wifi.WifiUtils; import com.android.systemui.SysuiTestCase; import com.android.wifitrackerlib.WifiEntry; Loading @@ -28,51 +31,55 @@ public class InternetAdapterTest extends SysuiTestCase { private static final String WIFI_TITLE = "Wi-Fi Title"; private static final String WIFI_SUMMARY = "Wi-Fi Summary"; private InternetDialogController mInternetDialogController = mock( InternetDialogController.class); @Mock private WifiEntry mWifiEntry; @Mock private InternetDialogController mInternetDialogController; @Mock private WifiUtils.InternetIconInjector mWifiIconInjector; private InternetAdapter mInternetAdapter; private InternetAdapter.InternetViewHolder mViewHolder; @Mock private WifiEntry mWifiEntry = mock(WifiEntry.class); @Before public void setUp() { MockitoAnnotations.initMocks(this); mInternetAdapter = new InternetAdapter(mInternetDialogController); mViewHolder = (InternetAdapter.InternetViewHolder) mInternetAdapter .onCreateViewHolder(new LinearLayout(mContext), 0); mViewHolder = mInternetAdapter.onCreateViewHolder(new LinearLayout(mContext), 0); when(mWifiEntry.getTitle()).thenReturn(WIFI_TITLE); when(mWifiEntry.getSummary(false)).thenReturn(WIFI_SUMMARY); when(mInternetDialogController.getWifiEntryList()).thenReturn(Arrays.asList(mWifiEntry)); mViewHolder.mWifiIconInjector = mWifiIconInjector; } @Test public void getItemCount_withApmOnWifiOnNoConnectedWifi_returnFour() { public void getItemCount_withApmOnWifiOnNoDefaultWifi_returnFour() { when(mInternetDialogController.isAirplaneModeEnabled()).thenReturn(true); assertThat(mInternetAdapter.getItemCount()).isEqualTo(4); } @Test public void getItemCount_withApmOnWifiOnHasConnectedWifi_returnThree() { when(mWifiEntry.getConnectedState()).thenReturn(WifiEntry.CONNECTED_STATE_CONNECTED); when(mInternetDialogController.getConnectedWifiEntry()).thenReturn(mWifiEntry); public void getItemCount_withApmOnWifiOnHasDefaultWifi_returnThree() { when(mWifiEntry.isDefaultNetwork()).thenReturn(true); when(mInternetDialogController.getDefaultWifiEntry()).thenReturn(mWifiEntry); when(mInternetDialogController.isAirplaneModeEnabled()).thenReturn(true); assertThat(mInternetAdapter.getItemCount()).isEqualTo(3); } @Test public void getItemCount_withApmOffWifiOnNoConnectedWifi_returnThree() { public void getItemCount_withApmOffWifiOnNoDefaultWifi_returnThree() { when(mInternetDialogController.isAirplaneModeEnabled()).thenReturn(false); assertThat(mInternetAdapter.getItemCount()).isEqualTo(3); } @Test public void getItemCount_withApmOffWifiOnHasConnectedWifi_returnTwo() { when(mWifiEntry.getConnectedState()).thenReturn(WifiEntry.CONNECTED_STATE_CONNECTED); when(mInternetDialogController.getConnectedWifiEntry()).thenReturn(mWifiEntry); public void getItemCount_withApmOffWifiOnHasDefaultWifi_returnTwo() { when(mWifiEntry.isDefaultNetwork()).thenReturn(true); when(mInternetDialogController.getDefaultWifiEntry()).thenReturn(mWifiEntry); when(mInternetDialogController.isAirplaneModeEnabled()).thenReturn(false); assertThat(mInternetAdapter.getItemCount()).isEqualTo(2); Loading @@ -99,4 +106,22 @@ public class InternetAdapterTest extends SysuiTestCase { assertThat(mViewHolder.mWifiIcon.getVisibility()).isEqualTo(View.VISIBLE); assertThat(mViewHolder.mWifiLockedIcon.getVisibility()).isEqualTo(View.VISIBLE); } @Test public void onBindViewHolder_bindDefaultWifiNetwork_getIconWithInternet() { when(mWifiEntry.shouldShowXLevelIcon()).thenReturn(false); mInternetAdapter.onBindViewHolder(mViewHolder, 0); verify(mWifiIconInjector).getIcon(eq(false) /* noInternet */, anyInt()); } @Test public void onBindViewHolder_bindNoDefaultWifiNetwork_getIconWithNoInternet() { when(mWifiEntry.shouldShowXLevelIcon()).thenReturn(true); mInternetAdapter.onBindViewHolder(mViewHolder, 0); verify(mWifiIconInjector).getIcon(eq(true) /* noInternet */, anyInt()); } }
packages/SystemUI/tests/src/com/android/systemui/qs/tiles/dialog/InternetDialogControllerTest.java +67 −26 Original line number Diff line number Diff line Loading @@ -4,7 +4,9 @@ import static com.google.common.truth.Truth.assertThat; import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; Loading @@ -13,6 +15,7 @@ import static org.mockito.Mockito.when; import android.content.Context; import android.content.Intent; import android.graphics.drawable.Drawable; import android.net.ConnectivityManager; import android.net.wifi.ScanResult; import android.net.wifi.WifiInfo; Loading @@ -30,6 +33,8 @@ import androidx.test.filters.SmallTest; import com.android.internal.logging.UiEventLogger; import com.android.keyguard.KeyguardUpdateMonitor; import com.android.settingslib.Utils; import com.android.settingslib.wifi.WifiUtils; import com.android.systemui.SysuiTestCase; import com.android.systemui.broadcast.BroadcastDispatcher; import com.android.systemui.dagger.qualifiers.Main; Loading Loading @@ -60,16 +65,12 @@ public class InternetDialogControllerTest extends SysuiTestCase { private static final String CONNECTED_TITLE = "Connected Wi-Fi Title"; private static final String CONNECTED_SUMMARY = "Connected Wi-Fi Summary"; private final UiEventLogger mUiEventLogger = mock(UiEventLogger.class); private MockInternetDialogController mInternetDialogController; private InternetDialogController.InternetDialogCallback mCallback = mock(InternetDialogController.InternetDialogCallback.class); private ActivityStarter mStarter = mock(ActivityStarter.class); private WifiManager mWifiManager = mock(WifiManager.class); private ConnectivityManager mConnectivityManager = mock(ConnectivityManager.class); private TelephonyManager mTelephonyManager = mock(TelephonyManager.class); private SubscriptionManager mSubscriptionManager = mock(SubscriptionManager.class); private FakeExecutor mExecutor = new FakeExecutor(new FakeSystemClock()); @Mock private WifiManager mWifiManager; @Mock private TelephonyManager mTelephonyManager; @Mock private SubscriptionManager mSubscriptionManager; @Mock private Handler mHandler; @Mock Loading @@ -88,21 +89,31 @@ public class InternetDialogControllerTest extends SysuiTestCase { private ServiceState mServiceState; @Mock private BroadcastDispatcher mBroadcastDispatcher; @Mock private WifiUtils.InternetIconInjector mWifiIconInjector; private MockInternetDialogController mInternetDialogController; private FakeExecutor mExecutor = new FakeExecutor(new FakeSystemClock()); @Before public void setUp() { MockitoAnnotations.initMocks(this); doReturn(mTelephonyManager).when(mTelephonyManager).createForSubscriptionId(SUB_ID); when(mWifiManager.getConnectionInfo()).thenReturn(mWifiInfo); mInternetDialogController = new MockInternetDialogController(mContext, mUiEventLogger, mStarter, mAccessPointController, mSubscriptionManager, mTelephonyManager, mWifiManager, mConnectivityManager, mHandler, mExecutor, mBroadcastDispatcher, when(mConnectedEntry.isDefaultNetwork()).thenReturn(true); mInternetDialogController = new MockInternetDialogController(mContext, mock(UiEventLogger.class), mock(ActivityStarter.class), mAccessPointController, mSubscriptionManager, mTelephonyManager, mWifiManager, mock(ConnectivityManager.class), mHandler, mExecutor, mBroadcastDispatcher, mKeyguardUpdateMonitor, mGlobalSettings); mSubscriptionManager.addOnSubscriptionsChangedListener(mExecutor, mInternetDialogController.mOnSubscriptionsChangedListener); mInternetDialogController.onStart(mCallback); mInternetDialogController.onStart( mock(InternetDialogController.InternetDialogCallback.class)); mInternetDialogController.mActivityStarter = mActivityStarter; mInternetDialogController.mConnectedEntry = mConnectedEntry; mInternetDialogController.mWifiIconInjector = mWifiIconInjector; } @Test Loading Loading @@ -199,35 +210,53 @@ public class InternetDialogControllerTest extends SysuiTestCase { } @Test public void getConnectedWifiTitle_withNoConnectedEntry_returnNull() { public void getDefaultWifiEntry_connectedEntryIsNull_returnNull() { mInternetDialogController.mConnectedEntry = null; assertThat(mInternetDialogController.getDefaultWifiEntry()).isNull(); } @Test public void getDefaultWifiEntry_connectedEntryIsNotDefault_returnNull() { when(mConnectedEntry.isDefaultNetwork()).thenReturn(false); assertThat(mInternetDialogController.getDefaultWifiEntry()).isNull(); } @Test public void getDefaultWifiEntry_connectedEntryIsDefault_returnConnectedEntry() { // The default conditions have been set in setUp(). // - The connected Wi-Fi entry with the default network condition. assertThat(mInternetDialogController.getDefaultWifiEntry()).isEqualTo(mConnectedEntry); } @Test public void getDefaultWifiTitle_withNoDefaultEntry_returnEmpty() { mInternetDialogController.mConnectedEntry = null; assertTrue(TextUtils.equals(mInternetDialogController.getConnectedWifiTitle(), "")); assertThat(mInternetDialogController.getDefaultWifiTitle()).isEmpty(); } @Test public void getConnectedWifiTitle_withConnectedEntry_returnTitle() { public void getDefaultWifiTitle_withDefaultEntry_returnTitle() { when(mConnectedEntry.getTitle()).thenReturn(CONNECTED_TITLE); assertTrue(TextUtils.equals(mInternetDialogController.getConnectedWifiTitle(), CONNECTED_TITLE)); assertThat(mInternetDialogController.getDefaultWifiTitle()).isEqualTo(CONNECTED_TITLE); } @Test public void getConnectedWifiSummary_withNoConnectedEntry_returnNull() { public void getDefaultWifiSummary_withNoDefaultEntry_returnEmpty() { mInternetDialogController.mConnectedEntry = null; assertTrue(TextUtils.equals(mInternetDialogController.getConnectedWifiSummary(), "")); assertThat(mInternetDialogController.getDefaultWifiSummary()).isEmpty(); } @Test public void getConnectedWifiSummary_withConnectedEntry_returnSummary() { public void getDefaultWifiSummary_withDefaultEntry_returnSummary() { when(mConnectedEntry.getSummary(false)).thenReturn(CONNECTED_SUMMARY); assertTrue(TextUtils.equals(mInternetDialogController.getConnectedWifiSummary(), CONNECTED_SUMMARY)); assertThat(mInternetDialogController.getDefaultWifiSummary()).isEqualTo(CONNECTED_SUMMARY); } @Test Loading @@ -251,6 +280,18 @@ public class InternetDialogControllerTest extends SysuiTestCase { assertThat(mInternetDialogController.getWifiDetailsSettingsIntent()).isNotNull(); } @Test public void getWifiConnectedDrawable_withConnectedEntry_returnIntentIconWithColorAccent() { final Drawable drawable = mock(Drawable.class); when(mWifiIconInjector.getIcon(anyBoolean(), anyInt())).thenReturn(drawable); mInternetDialogController.getConnectedWifiDrawable(mConnectedEntry); verify(mWifiIconInjector).getIcon(eq(false), anyInt()); verify(drawable).setTint(Utils.getColorAttrDefaultColor(mContext, com.android.internal.R.attr.colorControlNormal)); } @Test public void launchWifiNetworkDetailsSetting_withNoConnectedEntry_doNothing() { mInternetDialogController.mConnectedEntry = null; Loading