安卓11 禁用或启用sd卡和USB调试口

  • Post author:
  • Post category:其他




# 首先贴上实现patch下载地址



需求描述:

默认禁用SD卡 和USB调试口;在设置中加一个输入密码的地方,启用sd卡和USB调试口.重启后sd卡和USB口重新禁用掉.



需求分析:

1.sd卡在PublicVolume.cpp中可以doMount()中return -EIO,但是还是可以识别到,sd卡是损坏的状态.

不修改底层目前想到的处理方法是在识别SD卡的时候,再执行卸载sd卡的方法.(设置存储里面可以看到sd卡已卸载的状态,重新挂载是挂载不上的)

2.USB调试口 就强制设置充电状态,屏蔽usb连接通知



代码实现:

代码是直接贴的patch,如下:

diff --git a/build/make/tools/buildinfo.sh b/build/make/tools/buildinfo.sh
index a02a238..aae0a91 100755
--- a/build/make/tools/buildinfo.sh
+++ b/build/make/tools/buildinfo.sh
@@ -14,6 +14,9 @@ echo "ro.build.version.all_codenames=$PLATFORM_VERSION_ALL_CODENAMES"
 echo "ro.build.version.release=$PLATFORM_VERSION_LAST_STABLE"
 echo "ro.build.version.release_or_codename=$PLATFORM_VERSION"
 echo "ro.build.version.security_patch=$PLATFORM_SECURITY_PATCH"
+#modfiy by luoyalong for control USB status 20220424 begin
+echo "persist.sys.defaultpassw=13579" 
+#modfiy by luoyalong for control USB status 20220424 end
 echo "ro.build.version.base_os=$PLATFORM_BASE_OS"
 echo "ro.build.version.min_supported_target_sdk=$PLATFORM_MIN_SUPPORTED_TARGET_SDK_VERSION"
 echo "ro.build.date=`$DATE`"
diff --git a/frameworks/base/packages/SystemUI/src/com/android/systemui/usb/StorageNotification.java b/frameworks/base/packages/SystemUI/src/com/android/systemui/usb/StorageNotification.java
index 32be852..8ea5c83 100755
--- a/frameworks/base/packages/SystemUI/src/com/android/systemui/usb/StorageNotification.java
+++ b/frameworks/base/packages/SystemUI/src/com/android/systemui/usb/StorageNotification.java
@@ -48,7 +48,11 @@ import com.android.systemui.SystemUI;
 import com.android.systemui.util.NotificationChannels;
 
 import java.util.List;
-
+//modfiy by luoyalong for control USB status 20220424 begin
+import android.os.SystemProperties;
+import android.content.ComponentName;
+import android.widget.Toast;
+//modfiy by luoyalong for control USB status 20220424 end
 public class StorageNotification extends SystemUI {
     private static final String TAG = "StorageNotification";
 
@@ -303,7 +307,15 @@ public class StorageNotification extends SystemUI {
             Log.d(TAG, "Ignore public volume state change event of removed user");
             return;
         }
-
+		//modfiy by luoyalong for control USB status 20220424 begin	
+		if(vol.state==vol.STATE_MOUNTED && !"1".equals(SystemProperties.get("ro.sdcard.usb.status"))){
+			 mStorageManager.unmount(vol.getId());
+			 return;
+		}	
+		//modfiy by luoyalong for control USB status 20220424 end
+		if(vol.state!= 2){
+			return;
+		}
         final Notification notif;
         switch (vol.getState()) {
             case VolumeInfo.STATE_UNMOUNTED:
diff --git a/frameworks/base/services/core/java/com/android/server/StorageManagerService.java b/frameworks/base/services/core/java/com/android/server/StorageManagerService.java
old mode 100644
new mode 100755
index 11f083b..6e7b36f
--- a/frameworks/base/services/core/java/com/android/server/StorageManagerService.java
+++ b/frameworks/base/services/core/java/com/android/server/StorageManagerService.java
@@ -2307,7 +2307,14 @@ class StorageManagerService extends IStorageManager.Stub
             } catch (Installer.InstallerException e) {
                 Slog.e(TAG, "Failed unmount mirror data", e);
             }
-            mVold.unmount(vol.id);
+			//modfiy by luoyalong for control USB status 20220424 begin
+			try{
+				if(mVold==null){
+					connectVold();
+				}
+				mVold.unmount(vol.id);
+			}catch(Exception e){}
+			//modfiy by luoyalong for control USB status 20220424 end
             mStorageSessionController.onVolumeUnmount(vol);
         } catch (Exception e) {
             Slog.wtf(TAG, e);
diff --git a/frameworks/base/services/java/com/android/server/SystemServer.java b/frameworks/base/services/java/com/android/server/SystemServer.java
index 5613c5f..ba263fc 100755
--- a/frameworks/base/services/java/com/android/server/SystemServer.java
+++ b/frameworks/base/services/java/com/android/server/SystemServer.java
@@ -1255,7 +1255,9 @@ public final class SystemServer {
             Settings.Global.putInt(context.getContentResolver(),
                     Settings.Global.AIRPLANE_MODE_ON, 1);
         }
-
+		//modfiy by luoyalong for control USB status 20220424 begin
+		Settings.Global.putInt(context.getContentResolver(),Settings.Global.DEVELOPMENT_SETTINGS_ENABLED,0);
+		//modfiy by luoyalong for control USB status 20220424 end		
         StatusBarManagerService status



版权声明:本文为m1126125223原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。