Hide tethering option when in a guest account
- Before this CL, users can share their mobile data through enabling
tethering in the USB menu when in a guest account.
It will cause main users to spend their money unexpectedly.
This CL will hide the tethering option on the USB menu when in the
guest account.
- Add test cases.
Bug: 166125765
Test: 1. make -j42 RunSettingsRoboTests. 2. Switch to a guest account
to verify whether the tethering option is hiding.
Change-Id: I7523b3f3c3a1372bb128a58a6a7fac973d27cfbe
Merged-In: I7523b3f3c3a1372bb128a58a6a7fac973d27cfbe
(cherry picked from commit bde627b263
)
This commit is contained in:
@@ -50,6 +50,7 @@ public class UsbBackend {
|
|||||||
private final boolean mTetheringRestrictedBySystem;
|
private final boolean mTetheringRestrictedBySystem;
|
||||||
private final boolean mMidiSupported;
|
private final boolean mMidiSupported;
|
||||||
private final boolean mTetheringSupported;
|
private final boolean mTetheringSupported;
|
||||||
|
private final boolean mIsAdminUser;
|
||||||
|
|
||||||
private UsbManager mUsbManager;
|
private UsbManager mUsbManager;
|
||||||
|
|
||||||
@@ -70,6 +71,7 @@ public class UsbBackend {
|
|||||||
mFileTransferRestrictedBySystem = isUsbFileTransferRestrictedBySystem(userManager);
|
mFileTransferRestrictedBySystem = isUsbFileTransferRestrictedBySystem(userManager);
|
||||||
mTetheringRestricted = isUsbTetheringRestricted(userManager);
|
mTetheringRestricted = isUsbTetheringRestricted(userManager);
|
||||||
mTetheringRestrictedBySystem = isUsbTetheringRestrictedBySystem(userManager);
|
mTetheringRestrictedBySystem = isUsbTetheringRestrictedBySystem(userManager);
|
||||||
|
mIsAdminUser = userManager.isAdminUser();
|
||||||
|
|
||||||
mMidiSupported = context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_MIDI);
|
mMidiSupported = context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_MIDI);
|
||||||
ConnectivityManager cm =
|
ConnectivityManager cm =
|
||||||
@@ -100,7 +102,8 @@ public class UsbBackend {
|
|||||||
|| (!mTetheringSupported && (functions & UsbManager.FUNCTION_RNDIS) != 0)) {
|
|| (!mTetheringSupported && (functions & UsbManager.FUNCTION_RNDIS) != 0)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return !(areFunctionDisallowed(functions) || areFunctionsDisallowedBySystem(functions));
|
return !(areFunctionDisallowed(functions) || areFunctionsDisallowedBySystem(functions)
|
||||||
|
|| areFunctionsDisallowedByNonAdminUser(functions));
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getPowerRole() {
|
public int getPowerRole() {
|
||||||
@@ -207,6 +210,11 @@ public class UsbBackend {
|
|||||||
|| (mTetheringRestrictedBySystem && ((functions & UsbManager.FUNCTION_RNDIS) != 0));
|
|| (mTetheringRestrictedBySystem && ((functions & UsbManager.FUNCTION_RNDIS) != 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@VisibleForTesting
|
||||||
|
boolean areFunctionsDisallowedByNonAdminUser(long functions) {
|
||||||
|
return !mIsAdminUser && (functions & UsbManager.FUNCTION_RNDIS) != 0;
|
||||||
|
}
|
||||||
|
|
||||||
private void updatePorts() {
|
private void updatePorts() {
|
||||||
mPort = null;
|
mPort = null;
|
||||||
mPortStatus = null;
|
mPortStatus = null;
|
||||||
|
@@ -181,4 +181,24 @@ public class UsbBackendTest {
|
|||||||
|
|
||||||
assertThat(usbBackend.areFunctionsSupported(UsbManager.FUNCTION_MTP)).isTrue();
|
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