summaryrefslogtreecommitdiff
path: root/core/java/android
diff options
context:
space:
mode:
authorLorenzo Colitti <lorenzo@google.com>2020-12-18 00:57:15 +0900
committerLorenzo Colitti <lorenzo@google.com>2021-01-23 11:30:29 +0000
commit79c9c9e365e30dc08452f7dd245559a431e06d0a (patch)
tree05d9e5d38913eb9a761862ff0be907dc14de43f5 /core/java/android
parent94f23cd4c55e722f180e439b0f6e39db38dea7ca (diff)
Allow RNDIS and NCM to be enabled at the same time.
Currently, UsbManager#setCurrentFunctions takes a bitmask of functions to enable, but will only allow callers to enable one function at a time. Allow it to enable both RNDIS and NCM together as well. This is because from the user's point of view the two functions are the same (i.e., USB tethering). Android has historically used RNDIS for tethering. NCM performs better, but it doesn't work on older OSes like Windows 8.1. Also change the import order to keep the linter happy. Bug: 172793258 Test: added unit test for UsbManager.areSettableFunctions Change-Id: I51b6752781528b09f8929e1fb3b1fa7e4ac36aae
Diffstat (limited to 'core/java/android')
-rw-r--r--core/java/android/hardware/usb/UsbManager.java9
1 files changed, 7 insertions, 2 deletions
diff --git a/core/java/android/hardware/usb/UsbManager.java b/core/java/android/hardware/usb/UsbManager.java
index 0ef55f4a60f9..3730790b92e0 100644
--- a/core/java/android/hardware/usb/UsbManager.java
+++ b/core/java/android/hardware/usb/UsbManager.java
@@ -954,7 +954,10 @@ public class UsbManager {
/**
* Returns whether the given functions are valid inputs to UsbManager.
- * Currently the empty functions or any of MTP, PTP, RNDIS, MIDI are accepted.
+ * Currently the empty functions or any of MTP, PTP, RNDIS, MIDI, NCM are accepted.
+ *
+ * Only one function may be set at a time, except for RNDIS and NCM, which can be set together
+ * because from a user perspective they are the same function (tethering).
*
* @return Whether the mask is settable.
*
@@ -962,7 +965,9 @@ public class UsbManager {
*/
public static boolean areSettableFunctions(long functions) {
return functions == FUNCTION_NONE
- || ((~SETTABLE_FUNCTIONS & functions) == 0 && Long.bitCount(functions) == 1);
+ || ((~SETTABLE_FUNCTIONS & functions) == 0
+ && ((Long.bitCount(functions) == 1)
+ || (functions == (FUNCTION_RNDIS | FUNCTION_NCM))));
}
/**