OsuLogin: Take the UI style from CaptivePortalLogin App

1) Currently OsuLogin application has different color and style
with CaptivePortalLogin.
It is better to have same style with CaptivePortalLogin from user perspective.
2) remove NET_CAPABILITY_TRUSTED cap to catch the disconnect event for
ehpemeral network which was set in ag/5054830

Bug: 118454343
Test: live test with Passpoint R2 service provider AP
Change-Id: I4121d56b843d0ff2ebebb4bd4a063f2a5c5a0dd8
Signed-off-by: Ecco Park <eccopark@google.com>
This commit is contained in:
Ecco Park
2018-10-25 15:36:14 -07:00
parent 7cc7662d6f
commit 1afbb6ce9f
5 changed files with 94 additions and 15 deletions

View File

@@ -3,6 +3,7 @@ include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := optional
LOCAL_USE_AAPT2 := true
LOCAL_STATIC_ANDROID_LIBRARIES := androidx.legacy_legacy-support-v4
LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/res
LOCAL_SRC_FILES := $(call all-java-files-under, src)

View File

@@ -17,10 +17,10 @@
*/
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android.hotspot2">
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
package="com.android.hotspot2">
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:networkSecurityConfig="@xml/network_security_config"
@@ -28,7 +28,10 @@
android:label="@string/app_name"
android:configChanges="keyboardHidden|orientation|screenSize"
android:supportsRtl="true">
<activity android:name="com.android.hotspot2.osu.OsuLoginActivity">
<activity android:name="com.android.hotspot2.osu.OsuLoginActivity"
android:label="@string/action_bar_label"
android:theme="@style/AppTheme"
android:configChanges="keyboardHidden|orientation|screenSize">
<intent-filter>
<action android:name="android.net.wifi.action.PASSPOINT_LAUNCH_OSU_VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>

View File

@@ -1,13 +1,38 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent">
<WebView
android:id="@+id/webview"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.android.hotspot2.osu.OsuLoginActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true" />
android:orientation="vertical">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="4dp">
<!-- Eliminates ProgressBar padding by boxing it into a 4dp high container -->
<ProgressBar
android:id="@+id/progress_bar"
style="@android:style/Widget.Material.Light.ProgressBar.Horizontal"
android:indeterminate="false"
android:max="100"
android:progress="0"
android:layout_gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</FrameLayout>
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/swipe_refresh"
android:layout_width="match_parent"
android:layout_height="match_parent">
<WebView
android:id="@+id/webview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="false"
android:layout_alignParentRight="false"/>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
</LinearLayout>
</FrameLayout>

View File

@@ -1,4 +1,6 @@
<resources>
<!-- application name [CHAR LIMIT=32] -->
<string name="app_name">OsuLogin</string>
<!-- action bar label [CHAR LIMIT=32] -->
<string name="action_bar_label">Online Sign Up</string>
</resources>

View File

@@ -16,9 +16,12 @@
package com.android.hotspot2.osu;
import static android.net.NetworkCapabilities.NET_CAPABILITY_TRUSTED;
import android.annotation.Nullable;
import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.net.ConnectivityManager;
import android.net.Network;
import android.net.NetworkCapabilities;
@@ -27,17 +30,22 @@ import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebResourceError;
import android.webkit.WebResourceRequest;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ProgressBar;
import com.android.hotspot2.R;
import java.net.MalformedURLException;
import java.net.URL;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
/**
* Online Sign Up Login Web View launched during Provision Process of Hotspot 2.0 rel2.
*/
@@ -52,6 +60,8 @@ public class OsuLoginActivity extends Activity {
private ConnectivityManager.NetworkCallback mNetworkCallback;
private WifiManager mWifiManager;
private WebView mWebView;
private SwipeRefreshLayout mSwipeRefreshLayout;
private ProgressBar mProgressBar;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
@@ -117,6 +127,9 @@ public class OsuLoginActivity extends Activity {
}
getActionBar().setDisplayShowHomeEnabled(false);
getActionBar().setElevation(0); // remove shadow
getActionBar().setTitle(getString(R.string.action_bar_label));
getActionBar().setSubtitle("");
setContentView(R.layout.osu_web_view);
// Exit this app if network disappeared.
@@ -134,7 +147,8 @@ public class OsuLoginActivity extends Activity {
mCm.registerNetworkCallback(
new NetworkRequest.Builder().addTransportType(
NetworkCapabilities.TRANSPORT_WIFI).build(),
NetworkCapabilities.TRANSPORT_WIFI).removeCapability(
NET_CAPABILITY_TRUSTED).build(),
mNetworkCallback);
mWebView = findViewById(R.id.webview);
@@ -147,12 +161,25 @@ public class OsuLoginActivity extends Activity {
webSettings.setSupportZoom(true);
webSettings.setBuiltInZoomControls(true);
webSettings.setDisplayZoomControls(false);
mProgressBar = findViewById(R.id.progress_bar);
mWebView.setWebViewClient(new OsuWebViewClient());
mWebView.setWebChromeClient(new WebChromeClient() {
@Override
public void onProgressChanged(WebView view, int newProgress) {
mProgressBar.setProgress(newProgress);
}
});
if (DBG) {
Log.d(TAG, "OSU Web View to " + mUrl);
}
mWebView.loadUrl(mUrl);
mSwipeRefreshLayout = findViewById(R.id.swipe_refresh);
mSwipeRefreshLayout.setOnRefreshListener(() -> {
mWebView.reload();
mSwipeRefreshLayout.setRefreshing(true);
});
}
@Override
@@ -191,11 +218,31 @@ public class OsuLoginActivity extends Activity {
return null;
}
private String getHeaderSubtitle(String urlString) {
try {
URL url = new URL(urlString);
return url.getProtocol() + "://" + url.getHost();
} catch (MalformedURLException e) {
Log.e(TAG, "Invalid URL " + urlString);
}
return "";
}
private class OsuWebViewClient extends WebViewClient {
boolean mPageError = false;
@Override
public void onPageStarted(WebView view, String urlString, Bitmap favicon) {
String subtitle = getHeaderSubtitle(urlString);
getActionBar().setSubtitle(subtitle);
mProgressBar.setVisibility(View.VISIBLE);
}
@Override
public void onPageFinished(WebView view, String url) {
mProgressBar.setVisibility(View.INVISIBLE);
mSwipeRefreshLayout.setRefreshing(false);
// Do not show the page error on UI.
if (mPageError) {
finishAndRemoveTask();
@@ -213,4 +260,5 @@ public class OsuLoginActivity extends Activity {
}
}
}
}