欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

[RK3399][Android7.1.1]Android-」Tethering:修复使用USB共享网络,拔出USB后 USB共享没有自动关闭的问题

程序员文章站 2022-08-28 11:33:50
From cae95ac20d61d50ff3f31978619a1013e90f631f Mon Sep 17 00:00:00 2001From: sjf sjf@t-chip.com.cnDate: Wed, 13 May 2020 15:51:20 +0800Subject: [PATCH] =?UTF-8?q?Android->Tethering:=E4=BF=AE=E5=A4=8D=E4=BD=BF?==?UTF-8?q?=E7=94=A8USB=E5=85=B1=E4=BA=AB...

测试平台

Platform: RK3399
OS: Android 7.1.1

现象

热点:使用USB共享网络时,当USB拔出后,共享没有自动关闭的问题

解决方案

From 166712b80a4efd6f1e25b3f0c36b03ae1f96452f Mon Sep 17 00:00:00 2001
From: sjf <sjf@t-chip.com.cn>
Date: Wed, 13 May 2020 15:51:20 +0800
Subject: [PATCH] =?UTF-8?q?Android->Tethering:=E4=BF=AE=E5=A4=8D=E4=BD=BF?=
 =?UTF-8?q?=E7=94=A8USB=E5=85=B1=E4=BA=AB=E7=BD=91=E7=BB=9C,=E6=8B=94?=
 =?UTF-8?q?=E5=87=BAUSB=E5=90=8E=20USB=E5=85=B1=E4=BA=AB=E6=B2=A1=E6=9C=89?=
 =?UTF-8?q?=E8=87=AA=E5=8A=A8=E5=85=B3=E9=97=AD=E7=9A=84=E9=97=AE=E9=A2=98?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../core/java/com/android/server/connectivity/Tethering.java   | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/frameworks/base/services/core/java/com/android/server/connectivity/Tethering.java b/frameworks/base/services/core/java/com/android/server/connectivity/Tethering.java
index 5a5dc31..0b32099 100644
--- a/frameworks/base/services/core/java/com/android/server/connectivity/Tethering.java
+++ b/frameworks/base/services/core/java/com/android/server/connectivity/Tethering.java
@@ -782,12 +782,16 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering
             if (action.equals(UsbManager.ACTION_USB_STATE)) {
                 synchronized (Tethering.this.mPublicSync) {
                     boolean usbConnected = intent.getBooleanExtra(UsbManager.USB_CONNECTED, false);
-                    mRndisEnabled = intent.getBooleanExtra(UsbManager.USB_FUNCTION_RNDIS, false);
-                    // start tethering if we have a request pending
-                    if (usbConnected && mRndisEnabled && mUsbTetherRequested) {
+                    boolean rndisEnabled = intent.getBooleanExtra(UsbManager.USB_FUNCTION_RNDIS, false);
+                    //mRndisEnabled = intent.getBooleanExtra(UsbManager.USB_FUNCTION_RNDIS, false);
+                    boolean usbConfigured = intent.getBooleanExtra(UsbManager.USB_CONFIGURED, false);
+                    if (!usbConnected && mRndisEnabled){
+                        tetherMatchingInterfaces(false, ConnectivityManager.TETHERING_USB);
+                    }else if (usbConnected && rndisEnabled && mUsbTetherRequested) {// start tethering if we have a request pending
                         tetherMatchingInterfaces(true, ConnectivityManager.TETHERING_USB);
                     }
                     mUsbTetherRequested = false;
+                    mRndisEnabled = usbConfigured && rndisEnabled;
                 }
             } else if (action.equals(ConnectivityManager.CONNECTIVITY_ACTION)) {
                 NetworkInfo networkInfo = (NetworkInfo)intent.getParcelableExtra(
-- 
2.7.4

本文地址:https://blog.csdn.net/weixin_39966398/article/details/106100026