From a9af8434a6bf165fd2628bc4377ae8f8a2e8dfba Mon Sep 17 00:00:00 2001 From: Ecco Park Date: Tue, 29 Jan 2019 17:59:29 -0800 Subject: [PATCH] OsuLogin: disconnect wifi network when activitiy is destroyed When the OsuLogin activity is killed during OSU Procedure such as swiping it from apps list, it needs to disconnect AP to reset provisioning flow. Otherwise, provisioing flow is stucked in waiting for response up to 4 mins. Bug: 124778422 Test: verified that AP is disconnected and provisioning flow is reset when killing the application on recent app list. Change-Id: Ic52fc9f4225bf60eb2ff10635a0659c08273b37d Signed-off-by: Ecco Park --- .../hotspot2/osu/OsuLoginActivity.java | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/packages/OsuLogin/src/com/android/hotspot2/osu/OsuLoginActivity.java b/packages/OsuLogin/src/com/android/hotspot2/osu/OsuLoginActivity.java index 28b05396accee..82e33cc4aff92 100644 --- a/packages/OsuLogin/src/com/android/hotspot2/osu/OsuLoginActivity.java +++ b/packages/OsuLogin/src/com/android/hotspot2/osu/OsuLoginActivity.java @@ -46,8 +46,6 @@ import com.android.hotspot2.R; import java.net.MalformedURLException; import java.net.URL; - - /** * Online Sign Up Login Web View launched during Provision Process of Hotspot 2.0 rel2. */ @@ -64,6 +62,7 @@ public class OsuLoginActivity extends Activity { private WebView mWebView; private SwipeRefreshLayout mSwipeRefreshLayout; private ProgressBar mProgressBar; + private boolean mForceDisconnect = true; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { @@ -141,6 +140,7 @@ public class OsuLoginActivity extends Activity { if (DBG) { Log.d(TAG, "Lost for the current Network, close the browser"); } + mForceDisconnect = false; // It is already disconnected. if (mNetwork.equals(network)) { finishAndRemoveTask(); } @@ -193,12 +193,6 @@ public class OsuLoginActivity extends Activity { mWebView.goBack(); return true; } - - // In case of back key, it needs to disconnect current connection with OSU AP to - // abort current Provisioning flow. - if (mWifiManager != null) { - mWifiManager.disconnect(); - } } return super.onKeyDown(keyCode, event); } @@ -207,6 +201,11 @@ public class OsuLoginActivity extends Activity { protected void onDestroy() { if (mNetworkCallback != null) { mCm.unregisterNetworkCallback(mNetworkCallback); + mNetworkCallback = null; + } + if (mWifiManager != null && mForceDisconnect) { + mWifiManager.disconnect(); + mWifiManager = null; } super.onDestroy(); } @@ -232,6 +231,7 @@ public class OsuLoginActivity extends Activity { private class OsuWebViewClient extends WebViewClient { boolean mPageError = false; + boolean mRedirectResponseReceived = false; @Override public void onPageStarted(WebView view, String urlString, Bitmap favicon) { @@ -247,6 +247,10 @@ public class OsuLoginActivity extends Activity { // Do not show the page error on UI. if (mPageError) { + if (mRedirectResponseReceived) { + // Do not disconnect current connection while provisioning is in progress. + mForceDisconnect = false; + } finishAndRemoveTask(); } } @@ -255,6 +259,7 @@ public class OsuLoginActivity extends Activity { public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) { if (request.getUrl().toString().startsWith("http://127.0.0.1")) { + mRedirectResponseReceived = true; view.stopLoading(); } @@ -266,5 +271,4 @@ public class OsuLoginActivity extends Activity { } } } - }