在上一篇 RK7.1平台连接Captive Portal wifi时自动跳转到登录界面
在系统开机时间与当前网络时间不一致时,在WebView登录页面会弹出警告“您尝试加入的网络存在安全问题”,导致无法进行Portal wifi登录操作,当前是无网络的情况,无法进行网络时间同步,必须手动设置系统时间后才能进行登录操作,这样的操作还是十分麻烦的。
所以要想办法避开WebView的这个警告
查看警告时的log
01-01 20:24:12.721 1566 1566 W CaptivePortalLoginActivity: SSL error (error: 4 host: portal.ikuai8-wifi.com certificate: Issued to: CN=portal.ikuai8-wifi.com;
01-01 20:24:12.721 1566 1566 W CaptivePortalLoginActivity: Issued by: CN=TrustAsia TLS RSA CA,OU=Domain Validated SSL,O=TrustAsia Technologies\, Inc.,C=CN;
01-01 20:24:12.721 1566 1566 W CaptivePortalLoginActivity: ); displaying SSL warning.
找到警告源码:frameworks/base/packages/CaptivePortalLogin/src/com/android/captiveportallogin/CaptivePortalLoginActivity.java
@Override
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
Log.w(TAG, "SSL error (error: " + error.getPrimaryError() + " host: " +
// Only show host to avoid leaking private info.
Uri.parse(error.getUrl()).getHost() + " certificate: " +
error.getCertificate() + "); displaying SSL warning.");
final String html = String.format(SSL_ERROR_HTML, getString(R.string.ssl_error_warning),
getString(R.string.ssl_error_example), mBrowserBailOutToken,
getString(R.string.ssl_error_continue));
view.loadDataWithBaseURL(INTERNAL_ASSETS, html, "text/HTML", "UTF-8", null);
}
为避免谷歌安全警告,要重写WebView的onReceivedSslError方法
--- a/frameworks/base/packages/CaptivePortalLogin/src/com/android/captiveportallogin/CaptivePortalLoginActivity.java
+++ b/frameworks/base/packages/CaptivePortalLogin/src/com/android/captiveportallogin/CaptivePortalLoginActivity.java
@@ -379,10 +379,11 @@ public class CaptivePortalLoginActivity extends Activity {
// Only show host to avoid leaking private info.
Uri.parse(error.getUrl()).getHost() + " certificate: " +
error.getCertificate() + "); displaying SSL warning.");
- final String html = String.format(SSL_ERROR_HTML, getString(R.string.ssl_error_warning),
+ /*final String html = String.format(SSL_ERROR_HTML, getString(R.string.ssl_error_warning),
getString(R.string.ssl_error_example), mBrowserBailOutToken,
getString(R.string.ssl_error_continue));
- view.loadDataWithBaseURL(INTERNAL_ASSETS, html, "text/HTML", "UTF-8", null);
+ view.loadDataWithBaseURL(INTERNAL_ASSETS, html, "text/HTML", "UTF-8", null);*/
+ handler.proceed();//Ignore the time mismatch error and continue accessing by lpz 20210714
}
@Override
在onReceivedSslError中加入handler.proceed()表示继续访问操作
若无弹框提示,出现了SSL错误,应用会被google以[违反了广告ID“ ("advertising ID")”政策]为由拒绝。
我这里在重写这个方法时并未加入提示,而是直接跳过继续操作。我这个是系统应用,不用过gms,也不用发布到Google应用适应,应该是没有影响的
参考:
WebView的onReceivedSslError()方法
|