From 6e0af90a70db24a23d581e06e0e9386acdcf6290 Mon Sep 17 00:00:00 2001 From: Ray Chi Date: Thu, 8 Apr 2021 17:48:49 +0800 Subject: [PATCH] Check usb functions support with USB Gadget Hal version Currently, UsbDeviceManager will send usb functions in GadgetFunction to Hal implementation without any check. It is possible to send the functions defined in newer Hal to older Hal implementation. This patch will add a check to avoid this symptom before sending the usb function. Bug: 182507868 Test: verified pass Change-Id: I621809b8c7236937ab4c76e3fa943d00f761922f --- .../usb/java/com/android/server/usb/UsbDeviceManager.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/services/usb/java/com/android/server/usb/UsbDeviceManager.java b/services/usb/java/com/android/server/usb/UsbDeviceManager.java index 2e692e6e68f72..7f24c365237d3 100644 --- a/services/usb/java/com/android/server/usb/UsbDeviceManager.java +++ b/services/usb/java/com/android/server/usb/UsbDeviceManager.java @@ -2139,6 +2139,12 @@ public class UsbDeviceManager implements ActivityTaskManagerInternal.ScreenObser Slog.d(TAG, "setEnabledFunctions functions=" + functions + ", " + "forceRestart=" + forceRestart); } + if (mCurrentGadgetHalVersion < UsbManager.GADGET_HAL_V1_2) { + if ((functions & UsbManager.FUNCTION_NCM) != 0) { + Slog.e(TAG, "Could not set unsupported function for the GadgetHal"); + return; + } + } if (mCurrentFunctions != functions || !mCurrentFunctionsApplied || forceRestart) {