Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1afbb6ce authored by Ecco Park's avatar Ecco Park
Browse files

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: default avatarEcco Park <eccopark@google.com>
parent 7cc7662d
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -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)
+8 −5
Original line number Diff line number Diff line
@@ -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"/>
+33 −8
Original line number Diff line number Diff line
@@ -2,12 +2,37 @@
             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: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="true"
        android:layout_alignParentRight="true" />

            android:layout_alignParentBottom="false"
            android:layout_alignParentRight="false"/>
        </androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
    </LinearLayout>
</FrameLayout>
+2 −0
Original line number Diff line number Diff line
<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>
+50 −2
Original line number Diff line number Diff line
@@ -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 {
            }
         }
    }

}