Android 默认去掉URL网络校验,设置不进行网络校验

Android 系统连接WIFI显示网络连接受限分析处理_安卓13类原生系统网络受限-优快云博客

package\modules\NetworkStack\src\com\android\networkstack\util\NetworkStackUtils.java

    public static final String CAPTIVE_PORTAL_MODE = "captive_portal_mode";
    //0 不检测
    public static final int CAPTIVE_PORTAL_MODE_IGNORE = 0;
   //1默认弹框提示,默认
    public static final int CAPTIVE_PORTAL_MODE_PROMPT = 1;
    //2检测到需要登录则自动断开此热点并不再自动连接
    public static final int CAPTIVE_PORTAL_MODE_AVOID = 2;

/vendor/mediatek/proprietary/packages/apps/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java

   //*/add wifi Not verified
            loadSetting(stmt, Settings.Global.CAPTIVE_PORTAL_MODE, Settings.Global.CAPTIVE_PORTAL_MODE_IGNORE);//0
            //*/

【以上是方法二】

国内访问或使用国外的网址失败,系统提示无法连接并访问网络,不可用或者网络受限

方案修改:一是替换了校验网络的url地址,二是去除整个校验网络过程。

【以下是方法一】

将该网址替换系统默认的校验网址

--- a/packages/modules/NetworkStack/res/values/config.xml
+++ b/packages/modules/NetworkStack/res/values/config.xml
@@ -11,7 +11,7 @@
     <integer name="default_captive_portal_dns_probe_timeout">12500</integer>

     <!-- HTTP URL for network validation, to use for detecting captive portals. -->
-    <string name="default_captive_portal_http_url" translatable="false">http://connectivitycheck.gstatic.com/generate_204</string>
+    <string name="default_captive_portal_http_url" translatable="false">http://xxxxx/generate_204</string>    

     <!-- HTTPS URL for network validation, to use for confirming internet connectivity. -->
   -  <string name="default_captive_portal_https_url" translatable="false">https://www.google.com/generate_204</string>

+ <string name="default_captive_portal_https_url" translatable="false">https://xxxx.xx.xx/generate_204</string>
 

注意overlay地方:

vnd\vendor\mediatek\proprietary\packages\overlay\vendor\NetworkStackResOverlay\res\values\config.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
 
-    <string-array name="config_captive_portal_https_urls" translatable="false">
-        <item>https://connectivitycheck.gstatic.com/generate_204</item>
-        <item>https://www.google.cn/generate_204</item>
-    </string-array>
+    <string-array name="config_captive_portal_https_urls" translatable="false">
+        <item>https://xxx.xxx.xxx/generate_204</item>
+        <item>https://xxxx.xxx.xxx/generate_204</item>
+    </string-array>

    
</resources>

 如果没有特殊要求的话建议将网络评估机制的结果直接手动返回成功

添加变量:b/packages/modules/NetworkStack/src/com/android/server/connectivity/NetworkMonitor.java
@@ -1468,6 +1468,7 @@ public class NetworkMonitor extends StateMachine {

     @VisibleForTesting
     protected CaptivePortalProbeResult isCaptivePortal() {
+               mIsCaptivePortalCheckEnabled = false;
         if (!mIsCaptivePortalCheckEnabled) {
             validationLog("Validation disabled.");
             return CaptivePortalProbeResult.SUCCESS;

或者:构造方法里面:

//*/

mIsCaptivePortalCheckEnabled = false;

/*/

mIsCaptivePortalCheckEnabled = getIsCaptivePortalCheckEnabled();

//*/

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ nginx配置文件 user zceo; worker_processes auto; error_log /data/openresty/logs/error.log; pid /apps/openresty/run/nginx.pid; events { worker_connections 10240; } http { server_tokens off; include mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" | $http_accept | "$http_x_forwarded_for" | $host | ' '$request_time | $request_length | $upstream_addr | $upstream_status | $upstream_response_time | ' '$connection | $connection_requests '; access_log /data/openresty/logs/access.log main; sendfile on; tcp_nopush on; keepalive_timeout 65; gzip on; gzip_min_length 1k; gzip_buffers 4 16k; #gzip_http_version 1.0; gzip_comp_level 3; gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/javascript; gzip_vary on; gzip_disable "MSIE [1-6]\."; gzip_proxied any; # 指定服务器名称hash表的框大小 server_names_hash_bucket_size 512; # header头缓冲区大小,cookie内容较大时可加大 client_header_buffer_size 3072k; large_client_header_buffers 8 3072k; #设置允许发布内容为8M client_max_body_size 500M; client_body_buffer_size 3072k; # websocket配置 map $http_upgrade $connection_upgrade { default upgrade; '' close; } #获取真实请求IP map $http_x_forwarded_for $clientRealIp { "" $remote_addr; ~^(?P<firstAddr>[0-9\.]+),?.*$ $firstAddr; } map $http_user_agent $root_path { default /data/vue/bsp-workbenches-web; # 默认是 PC "~*Mobile" /data/vue/bsp-workbenches-h5; # 如果是移动设备,设置为 h5 路径 "~*Android" /data/vue/bsp-workbenches-h5; "~*iPhone" /data/vue/bsp-workbenches-h5; "~*iPad" /data/vue/bsp-workbenches-h5; "~*Windows Phone" /data/vue/bsp-workbenches-h5; } map $http_origin $cors_origin { default ""; ~^http?://(localhost|127\.0\.0\.1)(:\d+)?$ $http_origin; ~^https?://(.*\.)?gboss\.tech(?::\d+)?$ $http_origin; ~^https?://(.*\.)?ceboss\.cn(?::\d+)?$ $http_origin; ~^https?://(.*\.)?gmarketing\.cn(?::\d+)?$ $http_origin; } include vhosts/upstream.config; include vhosts/server.config; include vhosts/localhost.config; } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ vhosts/upstream.config内容 upstream tsdasdaweb { server xxx.xxx.xxx.xxx:8080; keepalive 2000; } upstream csadasdweb { server xxx.xx.xxx.xxx:80; keepalive 2000; } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ vhosts/server.config内容 多个下面类似配置 server { listen 80; server_name test-resource.gmarketing.tech; access_log /data/openresty/logs/access-test-resource.log main; error_log /data/openresty/logs/error-test-resource.log error; include /apps/openresty/nginx/conf/vhosts/test-resource-location.conf; } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ vhosts/localhost.config内容: server { listen 80; server_name 127.0.0.1; location /ssadas { stub_status on; } location ^~ /csasdasdweb/ { proxy_pass http://asdasdadweb; include /apps/openresty/nginx/conf/vhosts/common-proxy.conf; } } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ test-resource-location.conf内容 location ^~ /file-api/ { proxy_pass http://file-api/; include /apps/openresty/nginx/conf/vhosts/common-x-form.conf; include /apps/openresty/nginx/conf/vhosts/common-proxy.conf; } location /file { include /apps/openresty/nginx/conf/vhosts/file-from.conf; alias /data/share/files/; } location /robots.txt { alias /data/vue/robots/robots.txt; add_header Content-Type text/plain; } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /apps/openresty/nginx/conf/vhosts/common-x-form.conf内容 add_header Content-Security-Policy "frame-ancestors https://*.ceboss.cn https://*.gmarketing.tech https://*.gboss.tech;"; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /apps/openresty/nginx/conf/vhosts/common-proxy.conf内容 proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_connect_timeout 6000; proxy_read_timeout 6000; proxy_send_timeout 6000; proxy_buffer_size 3072k; proxy_buffers 16 3072k; proxy_busy_buffers_size 3072k; proxy_http_version 1.1; proxy_set_header Connection "Keep-Alive"; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /apps/openresty/nginx/conf/vhosts/file-from.conf内容 # CORS 配置 if ($http_origin ~* (https?://([^/]+\.)?(gmarketing\.tech|gboss\.tech|ceboss\.cn)(:\d+)?$)) { set $cors "true"; } if ($http_origin ~* (http?://([^/]+\.)?(gmarketing\.tech|gboss\.tech|ceboss\.cn|localhost:5173|localhost|localhost:5177)(:\d+)?$)) { set $cors "true"; } # 处理 .tiff 文件的 CORS 头 location ~* \.tiff$ { if ($cors = "true") { add_header 'Access-Control-Allow-Origin' "$http_origin" always; add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS' always; add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always; add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always; add_header 'Access-Control-Allow-Credentials' 'true' always; } try_files $uri =404; } # 核心 CORS 头 add_header 'Access-Control-Allow-Origin' "$http_origin" always; add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS' always; add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always; add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always; add_header 'Access-Control-Allow-Credentials' 'true' always; # 预检请求处理 if ($request_method = 'OPTIONS') { add_header 'Access-Control-Max-Age' 1728000; add_header 'Content-Type' 'text/plain; charset=utf-8'; add_header 'Content-Length' 0; return 204; } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 后端页面文件代码: public class SecureUrlGenerator { /** * ??? Nginx secure_link ????? URL. * * @param uri ????????? (??: "/images/secret/document.jpg") * @param secretKey ? Nginx ?????????? * @param durationInSeconds ???????(?) * @return ?????? URL (????) */ public static String generate(String uri, String secretKey, int durationInSeconds) { try { // 1. ??????? (Unix apoch time in seconds) long expires = System.currentTimeMillis() / 1000 + durationInSeconds; // 2. ????????? // ????? Nginx ? secure_link_md5 ?????????? // ??: "$secure_link_expires$uri secret_key" String stringToSign = expires + uri + " " + secretKey; // 3. ?? MD5 ?? MessageDigest md = MessageDigest.getInstance("MD5"); byte[] md5Bytes = md.digest(stringToSign.getBytes(StandardCharsets.UTF_8)); // 4. ? MD5 ???? URL ??? Base64 ?? // Nginx ? secure_link ????????: // - ?? '-' ?? '+' // - ?? '_' ?? '/' // - ????? padding '=' // Java 8 ? Base64.getUrlEncoder().withoutPadding() ?????????? String signature = Base64.getUrlEncoder().withoutPadding().encodeToString(md5Bytes); // 5. ????? URL // ??: /path/to/resource?md5=<signature>&expires=<timestamp> return String.format("%s?sign=%s&t=%d", uri, signature, expires); } catch (NoSuchAlgorithmException e) { // ??????,?????????????????? e.printStackTrace(); throw new RuntimeException("MD5 apoch_time is not available.", e); } } /** * ???,??????? */ public static void main(String[] args) { // --- ???? --- https://pre-file.gmarketing.tech/file/sm9pS0sF6oK/20250611/2b2e90fca62e41b4a048b424dfb75234.jpg String resourceUri = "24Gy8U0OlRbQ/20250616/04fa62de6149b4d11e79fce3ac7638b4.jpg"; String mySecretKey = "q8xyMiuJJAomkrk"; // ????????,??Nginx???? int validDuration = 43200; // ?????12?? (43200?) // --- ???? URL --- String signedUrl = generate(resourceUri, mySecretKey, validDuration); // --- ???? --- System.out.println("?? URI: " + resourceUri); System.out.println("????? URL: " + signedUrl); } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 请结合提供内容,修改nginx配置完成如下需求 测试环境Nginx 新的文件服务https://test-resource.gmarketing.tech 只允许通过含有码(sm9pS0sF6oK|24Gy8U0OlRbQ)的链接,并且需要对Referer进行验证,只允许通过含有以下Referer的链接访问【test-wb.gboss.tech test-console.gmarketing.tech test-sw.ceboss.cn】 测试环境Nginx 新的文件服务https://test-resource.gmarketing.tech 需要对sign和时间戳进行校验,加密Key是(q8xyMiuJJAomkrk 请勿泄露),加密方式见截图,加密后的链接示例(https://test-resource.gmarketing.tech/file/24Gy8U0OlRbQ/20250616/04fa62de6149b4d11e79fce3ac7638b4.jpg?sign=ei6aaK9I3H-9ph88m4mrpQ&t=1750103291)
最新发布
06-20
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值