实战

您所在的位置:网站首页 mac不能访问网页认证界面 实战

实战

2024-06-18 14:22:41| 来源: 网络整理| 查看: 265

认证Wifi简介

Wifi Portal portal认证就是连接Wifi成功后,还需要去一个登录页面,登录后才能正常使用wifi。在现在商店比如肯德基,万科,万达等很多外场,都有这样的认证方式。 Google 官方介绍: 在这里插入图片描述 判断是否是认证WIfi

frameworks/base/packages/CaptivePortalLogin/src/com/android/captiveportallogin/CaptivePortalLoginActivity.java private static final String DEFAULT_CAPTIVE_PORTAL_HTTP_URL = "http://connectivitycheck.gstatic.com/generate_204"; private void testForCaptivePortal() { new Thread(new Runnable() { public void run() { // Give time for captive portal to open. try { Thread.sleep(1000); } catch (InterruptedException e) { } HttpURLConnection urlConnection = null; int httpResponseCode = 500; try { urlConnection = (HttpURLConnection) mURL.openConnection(); urlConnection.setInstanceFollowRedirects(false); urlConnection.setConnectTimeout(SOCKET_TIMEOUT_MS); urlConnection.setReadTimeout(SOCKET_TIMEOUT_MS); urlConnection.setUseCaches(false); urlConnection.getInputStream(); httpResponseCode = urlConnection.getResponseCode(); } catch (IOException e) { } finally { if (urlConnection != null) urlConnection.disconnect(); } if (httpResponseCode == 204) { done(CAPTIVE_PORTAL_APP_RETURN_APPEASED); } } }).start(); } 认证WIif自动弹框认证

直接在ConnectivityService 的maybeHandleNetworkMonitorMessage 函数中处理,并跳转:

private boolean maybeHandleNetworkMonitorMessage(Message msg) { case NetworkMonitor.EVENT_PROVISIONING_NOTIFICATION: { ... PendingIntent intent = (PendingIntent) msg.obj; if (DBG) log("start PendingIntent"); intent.send(); }

完整修改记录:

--- a/services/core/java/com/android/server/ConnectivityService.java +++ b/services/core/java/com/android/server/ConnectivityService.java @@ -2288,6 +2288,7 @@ public class ConnectivityService extends IConnectivityManager.Stub final boolean visible = toBool(msg.arg1); final NetworkAgentInfo nai = getNetworkAgentInfoForNetId(netId); // If captive portal status has changed, update capabilities or disconnect. + if (DBG) log("Avoiding captive portal network: " + nai); if (nai != null && (visible != nai.lastCaptivePortalDetected)) { final int oldScore = nai.getCurrentScore(); nai.lastCaptivePortalDetected = visible; @@ -2310,8 +2311,19 @@ public class ConnectivityService extends IConnectivityManager.Stub break; } if (!nai.networkMisc.provisioningNotificationDisabled) { + if (DBG) log("Avoiding captive portal network: showNotification"); mNotifier.showNotification(netId, NotificationType.SIGN_IN, nai, null, (PendingIntent) msg.obj, nai.networkMisc.explicitlySelected); + if (nai.networkInfo.getType() == ConnectivityManager.TYPE_WIFI) { + try { + PendingIntent intent = (PendingIntent) msg.obj; + if (DBG) log("start PendingIntent"); + intent.send(); + } catch (PendingIntent.CanceledException e) { + log("PendingIntent.CanceledException " + e.toString()); + e.getStackTrace(); + } + } } } break; --

使用自定义的服务器地址判断是否Wifi Port成功:

--- a/packages/CaptivePortalLogin/src/com/android/captiveportallogin/CaptivePortalLoginActivity.java +++ b/packages/CaptivePortalLogin/src/com/android/captiveportallogin/CaptivePortalLoginActivity.java @@ -71,12 +71,16 @@ import java.lang.reflect.Method; import java.util.Objects; import java.util.Random; import java.util.concurrent.atomic.AtomicBoolean; +import android.os.SystemClock; +import java.io.BufferedReader; +import java.io.InputStream; +import java.io.InputStreamReader; public class CaptivePortalLoginActivity extends Activity { private static final String TAG = CaptivePortalLoginActivity.class.getSimpleName(); private static final boolean DBG = true; private static final boolean VDBG = false; - + private static final String DEFAULT_SERVER = "xxx.xxx.xxx";//自定义的服务器 private static final int SOCKET_TIMEOUT_MS = 10000; private enum Result { @@ -302,11 +306,11 @@ public class CaptivePortalLoginActivity extends Activity { } private URL getUrl() { - String url = getIntent().getStringExtra(ConnectivityManager.EXTRA_CAPTIVE_PORTAL_URL); - if (url == null) { - url = mCm.getCaptivePortalServerUrl(); + try { + return new URL("http",DEFAULT_SERVER, "/link.html?t=" + SystemClock.uptimeMillis()); + }catch (MalformedURLException|NumberFormatException e) { + return null; } - return makeURL(url); } private static URL makeURL(String url) { @@ -342,6 +346,7 @@ public class CaptivePortalLoginActivity extends Activity { } HttpURLConnection urlConnection = null; int httpResponseCode = 500; + String msg = ""; String locationHeader = null; try { urlConnection = (HttpURLConnection) network.openConnection(mUrl); @@ -354,13 +359,22 @@ public class CaptivePortalLoginActivity extends Activity { } // cannot read request header after connection String requestHeader = urlConnection.getRequestProperties().toString(); - + InputStream input = urlConnection.getInputStream(); + BufferedReader br = new BufferedReader(new InputStreamReader(input)); + String line = null; + StringBuffer sb = new StringBuffer(); + } + input.close(); + msg = sb.toString(); urlConnection.getInputStream(); httpResponseCode = urlConnection.getResponseCode(); locationHeader = urlConnection.getHeaderField(HTTP_LOCATION_HEADER_NAME); if (DBG) { Log.d(TAG, "probe at " + mUrl + " ret=" + httpResponseCode + + " msg=" + msg + " request=" + requestHeader + " headers=" + urlConnection.getHeaderFields()); } @@ -368,7 +382,7 @@ public class CaptivePortalLoginActivity extends Activity { } finally { if (urlConnection != null) urlConnection.disconnect(); } - if (isDismissed(httpResponseCode, locationHeader, mProbeSpec)) { + if (!TextUtils.isEmpty(msg) && msg.contains("success")) {//返回SUCCESS 表示认证WIIF成功 done(Result.DISMISSED); } }


【本文地址】

公司简介

联系我们

今日新闻


点击排行

实验室常用的仪器、试剂和
说到实验室常用到的东西,主要就分为仪器、试剂和耗
不用再找了,全球10大实验
01、赛默飞世尔科技(热电)Thermo Fisher Scientif
三代水柜的量产巅峰T-72坦
作者:寞寒最近,西边闹腾挺大,本来小寞以为忙完这
通风柜跟实验室通风系统有
说到通风柜跟实验室通风,不少人都纠结二者到底是不
集消毒杀菌、烘干收纳为一
厨房是家里细菌较多的地方,潮湿的环境、没有完全密
实验室设备之全钢实验台如
全钢实验台是实验室家具中较为重要的家具之一,很多

推荐新闻


图片新闻

实验室药品柜的特性有哪些
实验室药品柜是实验室家具的重要组成部分之一,主要
小学科学实验中有哪些教学
计算机 计算器 一般 打孔器 打气筒 仪器车 显微镜
实验室各种仪器原理动图讲
1.紫外分光光谱UV分析原理:吸收紫外光能量,引起分
高中化学常见仪器及实验装
1、可加热仪器:2、计量仪器:(1)仪器A的名称:量
微生物操作主要设备和器具
今天盘点一下微生物操作主要设备和器具,别嫌我啰嗦
浅谈通风柜使用基本常识
 众所周知,通风柜功能中最主要的就是排气功能。在

专题文章

    CopyRight 2018-2019 实验室设备网 版权所有 win10的实时保护怎么永久关闭