summaryrefslogtreecommitdiff
path: root/libs
diff options
context:
space:
mode:
authorArc Wang <arcwang@google.com>2020-01-21 16:41:50 +0800
committerArc Wang <arcwang@google.com>2020-01-27 16:05:47 +0800
commit8f5d4564d16a360419c59c10fdd4972da8d4a9de (patch)
tree996b1e7f0607d2b3689b7da5f270937d8a27b0dc /libs
parent906c8a9fec16f8bebc65c59d5c2e12c6dc27a1a1 (diff)
Implement PasspointWifiEntry#isExpired()
Bug: 141474717 Bug: 70983952 Test: atest PasspointWifiEntryTest Change-Id: Ia513757d58b21748293e0b6c00ccd06af8d0aa5a
Diffstat (limited to 'libs')
-rw-r--r--libs/WifiTrackerLib/res/values/strings.xml3
-rw-r--r--libs/WifiTrackerLib/src/com/android/wifitrackerlib/PasspointWifiEntry.java19
-rw-r--r--libs/WifiTrackerLib/src/com/android/wifitrackerlib/StandardWifiEntry.java6
-rw-r--r--libs/WifiTrackerLib/src/com/android/wifitrackerlib/WifiEntry.java3
-rw-r--r--libs/WifiTrackerLib/tests/src/com/android/wifitrackerlib/PasspointWifiEntryTest.java90
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 cda52adc2..b4c7524bc 100644
--- a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/PasspointWifiEntry.java
+++ b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/PasspointWifiEntry.java
@@ -65,6 +65,7 @@ class PasspointWifiEntry extends WifiEntry {
private boolean mCalledDisconnect = false;
private int mLevel = WIFI_LEVEL_UNREACHABLE;
+ protected long mSubscriptionExpirationTimeInMillis;
/**
* Create a PasspointWifiEntry with the associated PasspointConfiguration
@@ -81,6 +82,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
@@ -107,6 +110,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 string
}
@@ -293,11 +300,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 2b6dd2566..e90c49c98 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 39b30dfb3..369200525 100644
--- a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/WifiEntry.java
+++ b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/WifiEntry.java
@@ -382,6 +382,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;
+ }
+}