Merge cherrypicks of [12820899, 12820921, 12820267, 12820924, 12820699, 12820781, 12821235, 12821236, 12820925, 12821237, 12820545, 12821039, 12820926, 12820927, 12820928, 12820929, 12820930, 12820590, 12820471, 12820591, 12820592, 12820593, 12820594, 12821255, 12821256, 12821257, 12820998, 12820932, 12821258, 12820546, 12820933, 12820934, 12820547, 12820548, 12821275, 12821238, 12821239, 12821240, 12821241, 12821199, 12821276, 12821277, 12821278, 12821279, 12821280] into rvc-qpr1-release
Change-Id: I45feeefbdb027cafe726330ec39b41dd91b838be
This commit is contained in:
@@ -50,6 +50,7 @@ public class UsbBackend {
|
||||
private final boolean mTetheringRestrictedBySystem;
|
||||
private final boolean mMidiSupported;
|
||||
private final boolean mTetheringSupported;
|
||||
private final boolean mIsAdminUser;
|
||||
|
||||
private UsbManager mUsbManager;
|
||||
|
||||
@@ -70,6 +71,7 @@ public class UsbBackend {
|
||||
mFileTransferRestrictedBySystem = isUsbFileTransferRestrictedBySystem(userManager);
|
||||
mTetheringRestricted = isUsbTetheringRestricted(userManager);
|
||||
mTetheringRestrictedBySystem = isUsbTetheringRestrictedBySystem(userManager);
|
||||
mIsAdminUser = userManager.isAdminUser();
|
||||
|
||||
mMidiSupported = context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_MIDI);
|
||||
ConnectivityManager cm =
|
||||
@@ -100,7 +102,8 @@ public class UsbBackend {
|
||||
|| (!mTetheringSupported && (functions & UsbManager.FUNCTION_RNDIS) != 0)) {
|
||||
return false;
|
||||
}
|
||||
return !(areFunctionDisallowed(functions) || areFunctionsDisallowedBySystem(functions));
|
||||
return !(areFunctionDisallowed(functions) || areFunctionsDisallowedBySystem(functions)
|
||||
|| areFunctionsDisallowedByNonAdminUser(functions));
|
||||
}
|
||||
|
||||
public int getPowerRole() {
|
||||
@@ -207,6 +210,11 @@ public class UsbBackend {
|
||||
|| (mTetheringRestrictedBySystem && ((functions & UsbManager.FUNCTION_RNDIS) != 0));
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
boolean areFunctionsDisallowedByNonAdminUser(long functions) {
|
||||
return !mIsAdminUser && (functions & UsbManager.FUNCTION_RNDIS) != 0;
|
||||
}
|
||||
|
||||
private void updatePorts() {
|
||||
mPort = null;
|
||||
mPortStatus = null;
|
||||
|
@@ -181,4 +181,24 @@ public class UsbBackendTest {
|
||||
|
||||
assertThat(usbBackend.areFunctionsSupported(UsbManager.FUNCTION_MTP)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void areFunctionsDisallowedByNonAdminUser_isAdminUser_returnFalse() {
|
||||
when(mUserManager.isAdminUser()).thenReturn(true);
|
||||
|
||||
final UsbBackend usbBackend = new UsbBackend(mContext, mUserManager);
|
||||
|
||||
assertThat(usbBackend.areFunctionsDisallowedByNonAdminUser(
|
||||
UsbManager.FUNCTION_RNDIS)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void areFunctionsDisallowedByNonAdminUser_isNotAdminUser_returnTrue() {
|
||||
when(mUserManager.isAdminUser()).thenReturn(false);
|
||||
|
||||
final UsbBackend usbBackend = new UsbBackend(mContext, mUserManager);
|
||||
|
||||
assertThat(usbBackend.areFunctionsDisallowedByNonAdminUser(
|
||||
UsbManager.FUNCTION_RNDIS)).isTrue();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user