diff options
author | Arc Wang <arcwang@google.com> | 2020-01-29 05:12:05 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2020-01-29 05:12:05 +0000 |
commit | cf16f8e4b91fa751abdf16cecec064733b7b8284 (patch) | |
tree | cc12ecd4c4399c672b4e812ffae8f3145f2e866c | |
parent | e306c726c87b6941753e054e00420826656b5997 (diff) | |
parent | 8f5d4564d16a360419c59c10fdd4972da8d4a9de (diff) |
Merge "Implement PasspointWifiEntry#isExpired()"
5 files changed, 120 insertions, 1 deletions
diff --git a/libs/WifiTrackerLib/res/values/strings.xml b/libs/WifiTrackerLib/res/values/strings.xml index 50a173051..eaa057f91 100644 --- a/libs/WifiTrackerLib/res/values/strings.xml +++ b/libs/WifiTrackerLib/res/values/strings.xml @@ -141,4 +141,7 @@ <!-- Used in Wi-Fi settings dialogs when Wi-Fi does not have any security. [CHAR LIMIT=40] --> <string name="wifi_security_none">None</string> + + <!-- Passpoint summary for an expired passpoint [CHAR LIMIT=40] --> + <string name="wifi_passpoint_expired">Expired</string> </resources> diff --git a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/PasspointWifiEntry.java b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/PasspointWifiEntry.java index a2d43c0f0..87a18adb8 100644 --- a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/PasspointWifiEntry.java +++ b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/PasspointWifiEntry.java @@ -59,6 +59,7 @@ class PasspointWifiEntry extends WifiEntry { private boolean mIsRoaming = false; private int mLevel = WIFI_LEVEL_UNREACHABLE; + protected long mSubscriptionExpirationTimeInMillis; /** * Create a PasspointWifiEntry with the associated PasspointConfiguration @@ -76,6 +77,8 @@ class PasspointWifiEntry extends WifiEntry { mKey = fqdnToPasspointWifiEntryKey(homeSp.getFqdn()); mFriendlyName = homeSp.getFriendlyName(); mSecurity = SECURITY_NONE; //TODO: Should this always be Enterprise? + mSubscriptionExpirationTimeInMillis = + passpointConfig.getSubscriptionExpirationTimeInMillis(); } @Override @@ -95,6 +98,10 @@ class PasspointWifiEntry extends WifiEntry { @Override public String getSummary(boolean concise) { + if (isExpired()) { + return mContext.getString(R.string.wifi_passpoint_expired); + } + // TODO(b/70983952): Fill this method in return "Passpoint (Placeholder Text)"; // Placeholder string } @@ -277,11 +284,23 @@ class PasspointWifiEntry extends WifiEntry { mContext.getString(R.string.wifi_security_eap); } + @Override + public boolean isExpired() { + if (mSubscriptionExpirationTimeInMillis <= 0) { + // Expiration time not specified. + return false; + } else { + return System.currentTimeMillis() >= mSubscriptionExpirationTimeInMillis; + } + } + @WorkerThread void updatePasspointConfig(@NonNull PasspointConfiguration passpointConfig) { checkNotNull(passpointConfig, "Cannot update with null PasspointConfiguration!"); mPasspointConfig = passpointConfig; mFriendlyName = passpointConfig.getHomeSp().getFriendlyName(); + mSubscriptionExpirationTimeInMillis = + passpointConfig.getSubscriptionExpirationTimeInMillis(); notifyOnUpdated(); } diff --git a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/StandardWifiEntry.java b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/StandardWifiEntry.java index 0db155243..65ec356d0 100644 --- a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/StandardWifiEntry.java +++ b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/StandardWifiEntry.java @@ -310,7 +310,6 @@ class StandardWifiEntry extends WifiEntry { return ""; } - @Override public int getLevel() { return mLevel; @@ -651,6 +650,11 @@ class StandardWifiEntry extends WifiEntry { } } + @Override + public boolean isExpired() { + return false; + } + @WorkerThread void updateScanResultInfo(@Nullable List<ScanResult> scanResults) throws IllegalArgumentException { diff --git a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/WifiEntry.java b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/WifiEntry.java index 52eb6eb2a..2c73b5de9 100644 --- a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/WifiEntry.java +++ b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/WifiEntry.java @@ -383,6 +383,9 @@ public abstract class WifiEntry implements Comparable<WifiEntry> { public abstract void setAutoJoinEnabled(boolean enabled); /** Returns the string displayed for @Security */ public abstract String getSecurityString(boolean concise); + /** Returns whether subscription of the entry is expired */ + public abstract boolean isExpired(); + /** Returns the ScanResult information of a WifiEntry */ abstract String getScanResultDescription(); diff --git a/libs/WifiTrackerLib/tests/src/com/android/wifitrackerlib/PasspointWifiEntryTest.java b/libs/WifiTrackerLib/tests/src/com/android/wifitrackerlib/PasspointWifiEntryTest.java new file mode 100644 index 000000000..982950e19 --- /dev/null +++ b/libs/WifiTrackerLib/tests/src/com/android/wifitrackerlib/PasspointWifiEntryTest.java @@ -0,0 +1,90 @@ +/* + * Copyright (C) 2020 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.wifitrackerlib; + + +import static com.google.common.truth.Truth.assertThat; + +import static org.mockito.Mockito.when; + +import android.content.Context; +import android.content.res.Resources; +import android.net.wifi.WifiManager; +import android.net.wifi.hotspot2.PasspointConfiguration; +import android.net.wifi.hotspot2.pps.HomeSp; +import android.os.Handler; +import android.os.test.TestLooper; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; + +public class PasspointWifiEntryTest { + @Mock private Context mMockContext; + @Mock private WifiManager mMockWifiManager; + @Mock private Resources mMockResources; + + private TestLooper mTestLooper; + private Handler mTestHandler; + + @Before + public void setUp() { + MockitoAnnotations.initMocks(this); + + mTestLooper = new TestLooper(); + mTestHandler = new Handler(mTestLooper.getLooper()); + + when(mMockContext.getResources()).thenReturn(mMockResources); + } + + @Test + public void testGetSummary_expiredTimeNotAvailable_notShowExpired() { + long notSpecifiedExpiredTimeMilli = -1; + PasspointConfiguration passpointConfiguration = getPasspointConfiguration(); + passpointConfiguration.setSubscriptionExpirationTimeInMillis(notSpecifiedExpiredTimeMilli); + String expired = "Expired"; + when(mMockResources.getString(R.string.wifi_passpoint_expired)).thenReturn(expired); + + PasspointWifiEntry passpointWifiEntry = new PasspointWifiEntry(mMockContext, mTestHandler, + passpointConfiguration, mMockWifiManager); + + assertThat(passpointWifiEntry.getSummary()).isNotEqualTo(expired); + } + + @Test + public void testGetSummary_expired_showExpired() { + long expiredTimeMilli = 100; + PasspointConfiguration passpointConfiguration = getPasspointConfiguration(); + passpointConfiguration.setSubscriptionExpirationTimeInMillis(expiredTimeMilli); + String expired = "Expired"; + when(mMockResources.getString(R.string.wifi_passpoint_expired)).thenReturn(expired); + + PasspointWifiEntry passpointWifiEntry = new PasspointWifiEntry(mMockContext, mTestHandler, + passpointConfiguration, mMockWifiManager); + + assertThat(passpointWifiEntry.getSummary()).isEqualTo(expired); + } + + private PasspointConfiguration getPasspointConfiguration() { + PasspointConfiguration passpointConfiguration = new PasspointConfiguration(); + HomeSp homeSp = new HomeSp(); + homeSp.setFqdn("fqdn"); + passpointConfiguration.setHomeSp(homeSp); + return passpointConfiguration; + } +} |