Andriod phone 连接网络中关于网络连接限制(connect limit)

现象:
连接wifi后 可以上网 但是网络状态显示 网络不可用 ,并且wifi图标上有个小×,这是由于连接wifi后系统会自动检测 captive portal 服务器地址,高通默认代码的地址是google的,由于大部分国内用户访问不到 google网站 ,即使可以上网 但网络状态显示不可用
修改网址:
framework里面我们可以找到服务器地址:

private static final String DEFAULT_HTTPS_URL     = "https://www.google.com/generate_204";
private static final String DEFAULT_HTTP_URL      =
            "http://connectivitycheck.gstatic.com/generate_204";
private static String getCaptivePortalServerHttpsUrl(Context context) {
    
    
        return getSetting(context, Settings.Global.CAPTIVE_PORTAL_HTTPS_URL, DEFAULT_HTTPS_URL);                                                                                                                  
    }
    public static String getCaptivePortalServerHttpUrl(Context context) {
    
    
        return getSetting(context, Settings.Global.CAPTIVE_PORTAL_HTTP_URL, DEFAULT_HTTP_URL);
    }

可以通过命令改数据库的默认地址 :

adb shell "settings put global captive_portal_http_url http://**************"

adb shell "settings put global captive_portal_https_url https://**************"

改为vendor想要的网址。
也可以屏蔽监测:
方式一:

adb shell settings put global captive_portal_mode 0

方式二:

adb shell settings put global captive_portal_detection_enabled 0

在源码frameworks/base/services/core/java/com/android/server/ConnectivityService.java里面

case NetworkMonitor.EVENT_PROVISIONING_NOTIFICATION: {
    
    
                    final int netId = msg.arg2;
                    final boolean visible = (msg.arg1 != 0);
                    final NetworkAgentInfo nai;
                    synchronized (mNetworkForNetId) {
    
    
                        nai = mNetworkForNetId.get(netId);
                    }
                    // If captive portal status has changed, update capabilities or disconnect.
                    if (nai != null && (visible != nai.lastCaptivePortalDetected)) {
    
    
                        final int oldScore = nai.getCurrentScore();
                        nai.lastCaptivePortalDetected = visible;
                        nai.everCaptivePortalDetected |= visible;
                        if (nai.lastCaptivePortalDetected &&
                            Settings.Global.CAPTIVE_PORTAL_MODE_AVOID == getCaptivePortalMode()) {
    
    
                            if (DBG) log("Avoiding captive portal network: " + nai.name());
                            nai.asyncChannel.sendMessage(
                                    NetworkAgent.CMD_PREVENT_AUTOMATIC_RECONNECT);
                            teardownUnneededNetwork(nai);
                            break;
                        }
                        updateCapabilities(oldScore, nai, nai.networkCapabilities);
                    }
                    if (!visible) {
    
    
                        mNotifier.clearNotification(netId);
                    } else {
    
    
                        if (nai == null) {
    
    
                            loge("EVENT_PROVISIONING_NOTIFICATION from unknown NetworkMonitor");
                            break;
                        }
                        if (!nai.networkMisc.provisioningNotificationDisabled) {
    
    
                            mNotifier.showNotification(netId, NotificationType.SIGN_IN, nai, null,
                                    (PendingIntent) msg.obj, nai.networkMisc.explicitlySelected);
                        }
                    }

        private int getCaptivePortalMode() {
    
    
            return Settings.Global.getInt(mContext.getContentResolver(),
                    Settings.Global.CAPTIVE_PORTAL_MODE,
                    Settings.Global.CAPTIVE_PORTAL_MODE_PROMPT);
        }

改变 Settings.Global.CAPTIVE_PORTAL_MODE_PROMPT默认值就可以

猜你喜欢

转载自blog.csdn.net/weixin_42271802/article/details/113204426