Fix tethering doesn't turn off issue
When user restriction turns on, all tethering functions should
be disabled. But tethering functions still work after
restrication is on. Because tethering request would be removed
from mActiveTetheringRequests after starting tethering that
will result in Tethering#isTetheringActive() always returns
false. Thus, update the design to check tethered interface to
ensure that any of tethering function is working.
Bug: 169596583
Test: atest TetheringTests
Test: Manually test that tethering function would be disabled
and notification would show to user after restriction
was on.
Change-Id: Icb9649a5ecdec2d029ac763b5b9b80042ad50eb9
This commit is contained in:
@@ -1079,9 +1079,14 @@ public class Tethering {
|
||||
}
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
SparseArray<TetheringRequestParcel> getActiveTetheringRequests() {
|
||||
return mActiveTetheringRequests;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
boolean isTetheringActive() {
|
||||
return mActiveTetheringRequests.size() > 0;
|
||||
return getTetheredIfaces().length > 0;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
|
||||
@@ -52,6 +52,7 @@ import static android.net.wifi.WifiManager.WIFI_AP_STATE_ENABLED;
|
||||
import static android.telephony.SubscriptionManager.INVALID_SUBSCRIPTION_ID;
|
||||
|
||||
import static com.android.net.module.util.Inet4AddressUtils.intToInet4AddressHTH;
|
||||
import static com.android.networkstack.tethering.Tethering.UserRestrictionActionListener;
|
||||
import static com.android.networkstack.tethering.TetheringNotificationUpdater.DOWNSTREAM_NONE;
|
||||
import static com.android.networkstack.tethering.UpstreamNetworkMonitor.EVENT_ON_CAPABILITIES;
|
||||
|
||||
@@ -735,9 +736,12 @@ public class TetheringTest {
|
||||
initTetheringUpstream(upstreamState);
|
||||
|
||||
// Emulate pressing the USB tethering button in Settings UI.
|
||||
mTethering.startTethering(createTetheringRequestParcel(TETHERING_USB), null);
|
||||
final TetheringRequestParcel request = createTetheringRequestParcel(TETHERING_USB);
|
||||
mTethering.startTethering(request, null);
|
||||
mLooper.dispatchAll();
|
||||
verify(mUsbManager, times(1)).setCurrentFunctions(UsbManager.FUNCTION_RNDIS);
|
||||
assertEquals(1, mTethering.getActiveTetheringRequests().size());
|
||||
assertEquals(request, mTethering.getActiveTetheringRequests().get(TETHERING_USB));
|
||||
|
||||
mTethering.interfaceStatusChanged(TEST_USB_IFNAME, true);
|
||||
}
|
||||
@@ -1174,20 +1178,26 @@ public class TetheringTest {
|
||||
verifyNoMoreInteractions(mNetd);
|
||||
}
|
||||
|
||||
private UserRestrictionActionListener makeUserRestrictionActionListener(
|
||||
final Tethering tethering, final boolean currentDisallow, final boolean nextDisallow) {
|
||||
final Bundle newRestrictions = new Bundle();
|
||||
newRestrictions.putBoolean(UserManager.DISALLOW_CONFIG_TETHERING, nextDisallow);
|
||||
when(mUserManager.getUserRestrictions()).thenReturn(newRestrictions);
|
||||
|
||||
final UserRestrictionActionListener ural =
|
||||
new UserRestrictionActionListener(mUserManager, tethering, mNotificationUpdater);
|
||||
ural.mDisallowTethering = currentDisallow;
|
||||
return ural;
|
||||
}
|
||||
|
||||
private void runUserRestrictionsChange(
|
||||
boolean currentDisallow, boolean nextDisallow, boolean isTetheringActive,
|
||||
int expectedInteractionsWithShowNotification) throws Exception {
|
||||
final Bundle newRestrictions = new Bundle();
|
||||
newRestrictions.putBoolean(UserManager.DISALLOW_CONFIG_TETHERING, nextDisallow);
|
||||
final Tethering mockTethering = mock(Tethering.class);
|
||||
when(mockTethering.isTetheringActive()).thenReturn(isTetheringActive);
|
||||
when(mUserManager.getUserRestrictions()).thenReturn(newRestrictions);
|
||||
|
||||
final Tethering.UserRestrictionActionListener ural =
|
||||
new Tethering.UserRestrictionActionListener(
|
||||
mUserManager, mockTethering, mNotificationUpdater);
|
||||
ural.mDisallowTethering = currentDisallow;
|
||||
|
||||
final UserRestrictionActionListener ural =
|
||||
makeUserRestrictionActionListener(mockTethering, currentDisallow, nextDisallow);
|
||||
ural.onUserRestrictionsChanged();
|
||||
|
||||
verify(mNotificationUpdater, times(expectedInteractionsWithShowNotification))
|
||||
@@ -1256,6 +1266,27 @@ public class TetheringTest {
|
||||
expectedInteractionsWithShowNotification);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUntetherUsbWhenRestrictionIsOn() {
|
||||
// Start usb tethering and check that usb interface is tethered.
|
||||
final UpstreamNetworkState upstreamState = buildMobileIPv4UpstreamState();
|
||||
runUsbTethering(upstreamState);
|
||||
assertContains(Arrays.asList(mTethering.getTetheredIfaces()), TEST_USB_IFNAME);
|
||||
assertTrue(mTethering.isTetheringActive());
|
||||
assertEquals(0, mTethering.getActiveTetheringRequests().size());
|
||||
|
||||
final Tethering.UserRestrictionActionListener ural = makeUserRestrictionActionListener(
|
||||
mTethering, false /* currentDisallow */, true /* nextDisallow */);
|
||||
|
||||
ural.onUserRestrictionsChanged();
|
||||
mLooper.dispatchAll();
|
||||
|
||||
// Verify that restriction notification has showed to user.
|
||||
verify(mNotificationUpdater, times(1)).notifyTetheringDisabledByRestriction();
|
||||
// Verify that usb tethering has been disabled.
|
||||
verify(mUsbManager, times(1)).setCurrentFunctions(UsbManager.FUNCTION_NONE);
|
||||
}
|
||||
|
||||
private class TestTetheringEventCallback extends ITetheringEventCallback.Stub {
|
||||
private final ArrayList<Network> mActualUpstreams = new ArrayList<>();
|
||||
private final ArrayList<TetheringConfigurationParcel> mTetheringConfigs =
|
||||
|
||||
Reference in New Issue
Block a user