diff options
author | Quang Luong <qal@google.com> | 2020-08-03 22:08:15 -0700 |
---|---|---|
committer | Quang Luong <qal@google.com> | 2020-08-10 18:36:23 +0000 |
commit | 6ae159b62a595ca7dc4e121be4df175d15b49014 (patch) | |
tree | 888a5a4bd22dac35d7175f85ca0d79ec84e1cc69 /libs | |
parent | 058fc1de39ed8c11473bf9d60aac92dbf21106c0 (diff) |
[WifiTrackerLib] Use SSID as title for Osu entries with no friendly name
OsuProviders with null friendly name is a possible scenario that could
crash Wifi Settings. If the friendly name is not available, default to
the SSID and then to the server uri if needed.
Bug: 160748340
Test: manual visual verification that SSID appears as title if friendly
name is hardcoded as null.
Change-Id: I8f2b1b7a5a2c12d1c1ad43a9e8f786016355c2c1
(cherry picked from commit f02e7c63519548630221badd760651d55bbb99cb)
Merged-In: I8f2b1b7a5a2c12d1c1ad43a9e8f786016355c2c1
Diffstat (limited to 'libs')
-rw-r--r-- | libs/WifiTrackerLib/src/com/android/wifitrackerlib/OsuWifiEntry.java | 33 |
1 files changed, 24 insertions, 9 deletions
diff --git a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/OsuWifiEntry.java b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/OsuWifiEntry.java index 134ceef96..b1d7d4ae1 100644 --- a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/OsuWifiEntry.java +++ b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/OsuWifiEntry.java @@ -24,6 +24,7 @@ import static com.android.wifitrackerlib.WifiEntry.ConnectCallback.CONNECT_STATU import android.annotation.MainThread; import android.content.Context; import android.net.NetworkInfo; +import android.net.Uri; import android.net.wifi.ScanResult; import android.net.wifi.WifiConfiguration; import android.net.wifi.WifiInfo; @@ -60,11 +61,12 @@ class OsuWifiEntry extends WifiEntry { @NonNull private final String mKey; @NonNull private final Context mContext; @NonNull private OsuProvider mOsuProvider; + private String mSsid; private String mOsuStatusString; private boolean mIsAlreadyProvisioned = false; /** - * Create n OsuWifiEntry with the associated OsuProvider + * Create an OsuWifiEntry with the associated OsuProvider */ OsuWifiEntry(@NonNull Context context, @NonNull Handler callbackHandler, @NonNull OsuProvider osuProvider, @@ -87,7 +89,18 @@ class OsuWifiEntry extends WifiEntry { @Override public String getTitle() { - return mOsuProvider.getFriendlyName(); + final String friendlyName = mOsuProvider.getFriendlyName(); + if (!TextUtils.isEmpty(friendlyName)) { + return friendlyName; + } + if (!TextUtils.isEmpty(mSsid)) { + return mSsid; + } + final Uri serverUri = mOsuProvider.getServerUri(); + if (serverUri != null) { + return serverUri.toString(); + } + return ""; } @Override @@ -105,8 +118,7 @@ class OsuWifiEntry extends WifiEntry { @Override public String getSsid() { - // TODO(b/70983952): Fill this method in in case we need the SSID for verbose logging - return ""; + return mSsid; } @Override @@ -267,10 +279,13 @@ class OsuWifiEntry extends WifiEntry { } final ScanResult bestScanResult = getBestScanResultByLevel(scanResults); - if (getConnectedState() == CONNECTED_STATE_DISCONNECTED) { - mLevel = bestScanResult != null - ? mWifiManager.calculateSignalLevel(bestScanResult.level) - : WIFI_LEVEL_UNREACHABLE; + if (bestScanResult != null) { + mSsid = bestScanResult.SSID; + if (getConnectedState() == CONNECTED_STATE_DISCONNECTED) { + mLevel = mWifiManager.calculateSignalLevel(bestScanResult.level); + } + } else { + mLevel = WIFI_LEVEL_UNREACHABLE; } notifyOnUpdated(); } @@ -336,7 +351,7 @@ class OsuWifiEntry extends WifiEntry { case OSU_STATUS_WAITING_FOR_REDIRECT_RESPONSE: newStatusString = String.format(mContext.getString( R.string.osu_opening_provider), - mOsuProvider.getFriendlyName()); + getTitle()); break; case OSU_STATUS_REDIRECT_RESPONSE_RECEIVED: case OSU_STATUS_SECOND_SOAP_EXCHANGE: |