From 4a71bc90f41bdb27d730a6d9b2f992cf59f5a76a Mon Sep 17 00:00:00 2001 From: Arc Wang Date: Wed, 16 Oct 2019 15:34:31 +0800 Subject: [PATCH] [Wi-Fi] Support passport R1 expiration handling 1. Keep expired networks in the Saved Networks / Subscriptions area 2. Saved Networks Screen: add "Expired" subtext to the expired network list item 3. Wi-Fi detail page: also add "Expired" subtext under the network name 4. Wi-Fi detail page: hide the "Connect" button Bug: 141474717 Test: WifiDetailPreferenceControllerTest manual: Download passpoint profile and connect to a passpoint AP. Change-Id: Id5f5cf97bb25578ca08ebf9e77b06a2a02521e1c --- .../WifiDetailPreferenceController.java | 47 ++++++++++++++++--- .../WifiDetailPreferenceControllerTest.java | 24 ++++++++-- 2 files changed, 59 insertions(+), 12 deletions(-) diff --git a/src/com/android/settings/wifi/details/WifiDetailPreferenceController.java b/src/com/android/settings/wifi/details/WifiDetailPreferenceController.java index 3ed561bd835..6cd9569f009 100644 --- a/src/com/android/settings/wifi/details/WifiDetailPreferenceController.java +++ b/src/com/android/settings/wifi/details/WifiDetailPreferenceController.java @@ -191,6 +191,13 @@ public class WifiDetailPreferenceController extends AbstractPreferenceController private final IconInjector mIconInjector; private final IntentFilter mFilter; + + // Passpoint information - cache it in case of losing these information after + // updateAccessPointFromScannedList(). For R2, we should update these data from + // WifiManager#getPasspointConfigurations() after users manage the passpoint profile. + private boolean mIsExpired; + private boolean mIsPasspointConfigurationR1; + private final BroadcastReceiver mReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { @@ -358,6 +365,9 @@ public class WifiDetailPreferenceController extends AbstractPreferenceController updateConnectingState(STATE_FAILED); } }; + + mIsExpired = mAccessPoint.isExpired(); + mIsPasspointConfigurationR1 = mAccessPoint.isPasspointConfigurationR1(); } @Override @@ -392,6 +402,11 @@ public class WifiDetailPreferenceController extends AbstractPreferenceController .setButton4Icon(R.drawable.ic_qrcode_24dp) .setButton4OnClickListener(view -> shareNetwork()); + if (isPasspointConfigurationR1Expired()) { + // Hide Connect button. + mButtonsPref.setButton3Visible(false); + } + mSignalStrengthPref = screen.findPreference(KEY_SIGNAL_STRENGTH_PREF); mTxLinkSpeedPref = screen.findPreference(KEY_TX_LINK_SPEED); mRxLinkSpeedPref = screen.findPreference(KEY_RX_LINK_SPEED); @@ -440,9 +455,18 @@ public class WifiDetailPreferenceController extends AbstractPreferenceController if (usingDataUsageHeader(mContext)) { mSummaryHeaderController.updateState(mDataUsageSummaryPref); } else { + String summary; + if (isPasspointConfigurationR1Expired()) { + // Not able to get summary from AccessPoint because we may lost + // PasspointConfiguration information after updateAccessPointFromScannedList(). + summary = mContext.getResources().getString( + com.android.settingslib.R.string.wifi_passpoint_expired); + } else { + summary = mAccessPoint.getSettingsSummary(true /* convertSavedAsDisconnected */); + } + mEntityHeaderController - .setSummary( - mAccessPoint.getSettingsSummary(true /*convertSavedAsDisconnected*/)) + .setSummary(summary) .setRecyclerView(mFragment.getListView(), mLifecycle) .done(mFragment.getActivity(), true /* rebind */); } @@ -730,7 +754,7 @@ public class WifiDetailPreferenceController extends AbstractPreferenceController boolean canForgetNetwork = canForgetNetwork(); boolean canSignIntoNetwork = canSignIntoNetwork(); - boolean canConnectNetwork = canConnectNetwork(); + boolean canConnectNetwork = canConnectNetwork() && !isPasspointConfigurationR1Expired(); boolean canShareNetwork = canShareNetwork(); mButtonsPref.setButton1Visible(canForgetNetwork); @@ -748,6 +772,10 @@ public class WifiDetailPreferenceController extends AbstractPreferenceController return !mAccessPoint.isActive(); } + private boolean isPasspointConfigurationR1Expired() { + return mIsPasspointConfigurationR1 && mIsExpired; + } + private void refreshIpLayerInfo() { // Hide IP layer info if not a connected network. if (!mAccessPoint.isActive() || mNetwork == null || mLinkProperties == null) { @@ -1095,10 +1123,15 @@ public class WifiDetailPreferenceController extends AbstractPreferenceController case STATE_NOT_IN_RANGE: case STATE_FAILED: case STATE_ENABLE_WIFI_FAILED: - mButtonsPref.setButton3Text(R.string.wifi_connect) - .setButton3Icon(R.drawable.ic_settings_wireless) - .setButton3Enabled(true) - .setButton3Visible(true); + if (isPasspointConfigurationR1Expired()) { + // Hide Connect button. + mButtonsPref.setButton3Visible(false); + } else { + mButtonsPref.setButton3Text(R.string.wifi_connect) + .setButton3Icon(R.drawable.ic_settings_wireless) + .setButton3Enabled(true) + .setButton3Visible(true); + } break; default: Log.e(TAG, "Invalid connect button state : " + state); diff --git a/tests/robotests/src/com/android/settings/wifi/details/WifiDetailPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/wifi/details/WifiDetailPreferenceControllerTest.java index 7f65b0663e9..4be0f01f54b 100644 --- a/tests/robotests/src/com/android/settings/wifi/details/WifiDetailPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/wifi/details/WifiDetailPreferenceControllerTest.java @@ -17,8 +17,8 @@ package com.android.settings.wifi.details; import static com.google.common.truth.Truth.assertThat; -import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.nullable; @@ -35,8 +35,8 @@ import static org.mockito.Mockito.when; import android.content.ComponentName; import android.content.Context; import android.content.Intent; -import android.content.res.Resources; import android.content.pm.PackageManager; +import android.content.res.Resources; import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.Drawable; @@ -56,7 +56,6 @@ import android.net.wifi.WifiInfo; import android.net.wifi.WifiManager; import android.os.Handler; import android.provider.Settings; -import android.util.FeatureFlagUtils; import android.view.View; import android.view.View.OnClickListener; import android.widget.ImageView; @@ -69,9 +68,9 @@ import androidx.preference.PreferenceScreen; import com.android.internal.logging.nano.MetricsProto; import com.android.settings.R; +import com.android.settings.Utils; import com.android.settings.core.FeatureFlags; import com.android.settings.development.featureflags.FeatureFlagPersistent; -import com.android.settings.Utils; import com.android.settings.testutils.shadow.ShadowDevicePolicyManager; import com.android.settings.testutils.shadow.ShadowEntityHeaderController; import com.android.settings.widget.EntityHeaderController; @@ -101,8 +100,8 @@ import org.robolectric.shadows.ShadowToast; import java.net.Inet4Address; import java.net.InetAddress; import java.net.UnknownHostException; -import java.util.Arrays; import java.util.ArrayList; +import java.util.Arrays; import java.util.stream.Collectors; @RunWith(RobolectricTestRunner.class) @@ -1870,6 +1869,21 @@ public class WifiDetailPreferenceControllerTest { verify(mockMacAddressPref).setTitle(R.string.wifi_advanced_factory_mac_address_title); } + @Test + public void entityHeader_expiredPasspointR1_shouldHandleExpiration() { + setUpForDisconnectedNetwork(); + when(mockAccessPoint.isPasspoint()).thenReturn(true); + when(mockAccessPoint.isPasspointConfigurationR1()).thenReturn(true); + when(mockAccessPoint.isExpired()).thenReturn(true); + String expireSummary = mContext.getResources().getString( + com.android.settingslib.R.string.wifi_passpoint_expired); + + displayAndResume(); + + verify(mockButtonsPref).setButton3Visible(false); + verify(mockHeaderController).setSummary(expireSummary); + } + private ActionButtonsPreference createMock() { final ActionButtonsPreference pref = mock(ActionButtonsPreference.class); when(pref.setButton1Text(anyInt())).thenReturn(pref);