Loading packages/Tethering/src/com/android/networkstack/tethering/Tethering.java +12 −6 Original line number Diff line number Diff line Loading @@ -1006,6 +1006,11 @@ public class Tethering { } } @VisibleForTesting boolean isTetheringActive() { return mActiveTetheringRequests.size() > 0; } @VisibleForTesting protected static class UserRestrictionActionListener { private final UserManager mUserManager; Loading Loading @@ -1043,13 +1048,14 @@ public class Tethering { return; } if (mWrapper.isTetheringActive()) { // Restricted notification is shown when tethering function is disallowed on // user's device. mNotificationUpdater.notifyTetheringDisabledByRestriction(); // Untether from all downstreams since tethering is disallowed. mWrapper.untetherAll(); } // TODO(b/148139325): send tetheringSupported on restriction change } } Loading packages/Tethering/src/com/android/networkstack/tethering/TetheringNotificationUpdater.java +6 −6 Original line number Diff line number Diff line Loading @@ -267,7 +267,7 @@ public class TetheringNotificationUpdater { null /* options */); showNotification(R.drawable.stat_sys_tether_general, title, message, RESTRICTED_NOTIFICATION_ID, pi, new Action[0]); RESTRICTED_NOTIFICATION_ID, false /* ongoing */, pi, new Action[0]); } private void notifyTetheringNoUpstream() { Loading @@ -288,7 +288,7 @@ public class TetheringNotificationUpdater { final Action action = new Action.Builder(NO_ICON_ID, disableButton, pi).build(); showNotification(R.drawable.stat_sys_tether_general, title, message, NO_UPSTREAM_NOTIFICATION_ID, null /* pendingIntent */, action); NO_UPSTREAM_NOTIFICATION_ID, true /* ongoing */, null /* pendingIntent */, action); } private boolean setupRoamingNotification() { Loading @@ -310,7 +310,7 @@ public class TetheringNotificationUpdater { null /* options */); showNotification(R.drawable.stat_sys_tether_general, title, message, ROAMING_NOTIFICATION_ID, pi, new Action[0]); ROAMING_NOTIFICATION_ID, true /* ongoing */, pi, new Action[0]); return NOTIFY_DONE; } Loading @@ -327,14 +327,14 @@ public class TetheringNotificationUpdater { } private void showNotification(@DrawableRes final int iconId, @NonNull final String title, @NonNull final String message, @NotificationId final int id, @Nullable PendingIntent pi, @NonNull final Action... actions) { @NonNull final String message, @NotificationId final int id, final boolean ongoing, @Nullable PendingIntent pi, @NonNull final Action... actions) { final Notification notification = new Notification.Builder(mContext, mChannel.getId()) .setSmallIcon(iconId) .setContentTitle(title) .setContentText(message) .setOngoing(true) .setOngoing(ongoing) .setColor(mContext.getColor( android.R.color.system_notification_accent_color)) .setVisibility(Notification.VISIBILITY_PUBLIC) Loading packages/Tethering/tests/unit/src/com/android/networkstack/tethering/TetheringTest.java +18 −18 Original line number Diff line number Diff line Loading @@ -1079,12 +1079,12 @@ public class TetheringTest { } private void runUserRestrictionsChange( boolean currentDisallow, boolean nextDisallow, String[] activeTetheringIfacesList, 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.getTetheredIfaces()).thenReturn(activeTetheringIfacesList); when(mockTethering.isTetheringActive()).thenReturn(isTetheringActive); when(mUserManager.getUserRestrictions()).thenReturn(newRestrictions); final Tethering.UserRestrictionActionListener ural = Loading @@ -1100,63 +1100,63 @@ public class TetheringTest { } @Test public void testDisallowTetheringWhenNoTetheringInterfaceIsActive() throws Exception { final String[] emptyActiveIfacesList = new String[]{}; public void testDisallowTetheringWhenTetheringIsNotActive() throws Exception { final boolean isTetheringActive = false; final boolean currDisallow = false; final boolean nextDisallow = true; final int expectedInteractionsWithShowNotification = 1; final int expectedInteractionsWithShowNotification = 0; runUserRestrictionsChange(currDisallow, nextDisallow, emptyActiveIfacesList, runUserRestrictionsChange(currDisallow, nextDisallow, isTetheringActive, expectedInteractionsWithShowNotification); } @Test public void testDisallowTetheringWhenAtLeastOneTetheringInterfaceIsActive() throws Exception { final String[] nonEmptyActiveIfacesList = new String[]{TEST_WLAN_IFNAME}; public void testDisallowTetheringWhenTetheringIsActive() throws Exception { final boolean isTetheringActive = true; final boolean currDisallow = false; final boolean nextDisallow = true; final int expectedInteractionsWithShowNotification = 1; runUserRestrictionsChange(currDisallow, nextDisallow, nonEmptyActiveIfacesList, runUserRestrictionsChange(currDisallow, nextDisallow, isTetheringActive, expectedInteractionsWithShowNotification); } @Test public void testAllowTetheringWhenNoTetheringInterfaceIsActive() throws Exception { final String[] nonEmptyActiveIfacesList = new String[]{}; public void testAllowTetheringWhenTetheringIsNotActive() throws Exception { final boolean isTetheringActive = false; final boolean currDisallow = true; final boolean nextDisallow = false; final int expectedInteractionsWithShowNotification = 0; runUserRestrictionsChange(currDisallow, nextDisallow, nonEmptyActiveIfacesList, runUserRestrictionsChange(currDisallow, nextDisallow, isTetheringActive, expectedInteractionsWithShowNotification); } @Test public void testAllowTetheringWhenAtLeastOneTetheringInterfaceIsActive() throws Exception { final String[] nonEmptyActiveIfacesList = new String[]{TEST_WLAN_IFNAME}; public void testAllowTetheringWhenTetheringIsActive() throws Exception { final boolean isTetheringActive = true; final boolean currDisallow = true; final boolean nextDisallow = false; final int expectedInteractionsWithShowNotification = 0; runUserRestrictionsChange(currDisallow, nextDisallow, nonEmptyActiveIfacesList, runUserRestrictionsChange(currDisallow, nextDisallow, isTetheringActive, expectedInteractionsWithShowNotification); } @Test public void testDisallowTetheringUnchanged() throws Exception { final String[] nonEmptyActiveIfacesList = new String[]{TEST_WLAN_IFNAME}; final boolean isTetheringActive = true; final int expectedInteractionsWithShowNotification = 0; boolean currDisallow = true; boolean nextDisallow = true; runUserRestrictionsChange(currDisallow, nextDisallow, nonEmptyActiveIfacesList, runUserRestrictionsChange(currDisallow, nextDisallow, isTetheringActive, expectedInteractionsWithShowNotification); currDisallow = false; nextDisallow = false; runUserRestrictionsChange(currDisallow, nextDisallow, nonEmptyActiveIfacesList, runUserRestrictionsChange(currDisallow, nextDisallow, isTetheringActive, expectedInteractionsWithShowNotification); } Loading Loading
packages/Tethering/src/com/android/networkstack/tethering/Tethering.java +12 −6 Original line number Diff line number Diff line Loading @@ -1006,6 +1006,11 @@ public class Tethering { } } @VisibleForTesting boolean isTetheringActive() { return mActiveTetheringRequests.size() > 0; } @VisibleForTesting protected static class UserRestrictionActionListener { private final UserManager mUserManager; Loading Loading @@ -1043,13 +1048,14 @@ public class Tethering { return; } if (mWrapper.isTetheringActive()) { // Restricted notification is shown when tethering function is disallowed on // user's device. mNotificationUpdater.notifyTetheringDisabledByRestriction(); // Untether from all downstreams since tethering is disallowed. mWrapper.untetherAll(); } // TODO(b/148139325): send tetheringSupported on restriction change } } Loading
packages/Tethering/src/com/android/networkstack/tethering/TetheringNotificationUpdater.java +6 −6 Original line number Diff line number Diff line Loading @@ -267,7 +267,7 @@ public class TetheringNotificationUpdater { null /* options */); showNotification(R.drawable.stat_sys_tether_general, title, message, RESTRICTED_NOTIFICATION_ID, pi, new Action[0]); RESTRICTED_NOTIFICATION_ID, false /* ongoing */, pi, new Action[0]); } private void notifyTetheringNoUpstream() { Loading @@ -288,7 +288,7 @@ public class TetheringNotificationUpdater { final Action action = new Action.Builder(NO_ICON_ID, disableButton, pi).build(); showNotification(R.drawable.stat_sys_tether_general, title, message, NO_UPSTREAM_NOTIFICATION_ID, null /* pendingIntent */, action); NO_UPSTREAM_NOTIFICATION_ID, true /* ongoing */, null /* pendingIntent */, action); } private boolean setupRoamingNotification() { Loading @@ -310,7 +310,7 @@ public class TetheringNotificationUpdater { null /* options */); showNotification(R.drawable.stat_sys_tether_general, title, message, ROAMING_NOTIFICATION_ID, pi, new Action[0]); ROAMING_NOTIFICATION_ID, true /* ongoing */, pi, new Action[0]); return NOTIFY_DONE; } Loading @@ -327,14 +327,14 @@ public class TetheringNotificationUpdater { } private void showNotification(@DrawableRes final int iconId, @NonNull final String title, @NonNull final String message, @NotificationId final int id, @Nullable PendingIntent pi, @NonNull final Action... actions) { @NonNull final String message, @NotificationId final int id, final boolean ongoing, @Nullable PendingIntent pi, @NonNull final Action... actions) { final Notification notification = new Notification.Builder(mContext, mChannel.getId()) .setSmallIcon(iconId) .setContentTitle(title) .setContentText(message) .setOngoing(true) .setOngoing(ongoing) .setColor(mContext.getColor( android.R.color.system_notification_accent_color)) .setVisibility(Notification.VISIBILITY_PUBLIC) Loading
packages/Tethering/tests/unit/src/com/android/networkstack/tethering/TetheringTest.java +18 −18 Original line number Diff line number Diff line Loading @@ -1079,12 +1079,12 @@ public class TetheringTest { } private void runUserRestrictionsChange( boolean currentDisallow, boolean nextDisallow, String[] activeTetheringIfacesList, 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.getTetheredIfaces()).thenReturn(activeTetheringIfacesList); when(mockTethering.isTetheringActive()).thenReturn(isTetheringActive); when(mUserManager.getUserRestrictions()).thenReturn(newRestrictions); final Tethering.UserRestrictionActionListener ural = Loading @@ -1100,63 +1100,63 @@ public class TetheringTest { } @Test public void testDisallowTetheringWhenNoTetheringInterfaceIsActive() throws Exception { final String[] emptyActiveIfacesList = new String[]{}; public void testDisallowTetheringWhenTetheringIsNotActive() throws Exception { final boolean isTetheringActive = false; final boolean currDisallow = false; final boolean nextDisallow = true; final int expectedInteractionsWithShowNotification = 1; final int expectedInteractionsWithShowNotification = 0; runUserRestrictionsChange(currDisallow, nextDisallow, emptyActiveIfacesList, runUserRestrictionsChange(currDisallow, nextDisallow, isTetheringActive, expectedInteractionsWithShowNotification); } @Test public void testDisallowTetheringWhenAtLeastOneTetheringInterfaceIsActive() throws Exception { final String[] nonEmptyActiveIfacesList = new String[]{TEST_WLAN_IFNAME}; public void testDisallowTetheringWhenTetheringIsActive() throws Exception { final boolean isTetheringActive = true; final boolean currDisallow = false; final boolean nextDisallow = true; final int expectedInteractionsWithShowNotification = 1; runUserRestrictionsChange(currDisallow, nextDisallow, nonEmptyActiveIfacesList, runUserRestrictionsChange(currDisallow, nextDisallow, isTetheringActive, expectedInteractionsWithShowNotification); } @Test public void testAllowTetheringWhenNoTetheringInterfaceIsActive() throws Exception { final String[] nonEmptyActiveIfacesList = new String[]{}; public void testAllowTetheringWhenTetheringIsNotActive() throws Exception { final boolean isTetheringActive = false; final boolean currDisallow = true; final boolean nextDisallow = false; final int expectedInteractionsWithShowNotification = 0; runUserRestrictionsChange(currDisallow, nextDisallow, nonEmptyActiveIfacesList, runUserRestrictionsChange(currDisallow, nextDisallow, isTetheringActive, expectedInteractionsWithShowNotification); } @Test public void testAllowTetheringWhenAtLeastOneTetheringInterfaceIsActive() throws Exception { final String[] nonEmptyActiveIfacesList = new String[]{TEST_WLAN_IFNAME}; public void testAllowTetheringWhenTetheringIsActive() throws Exception { final boolean isTetheringActive = true; final boolean currDisallow = true; final boolean nextDisallow = false; final int expectedInteractionsWithShowNotification = 0; runUserRestrictionsChange(currDisallow, nextDisallow, nonEmptyActiveIfacesList, runUserRestrictionsChange(currDisallow, nextDisallow, isTetheringActive, expectedInteractionsWithShowNotification); } @Test public void testDisallowTetheringUnchanged() throws Exception { final String[] nonEmptyActiveIfacesList = new String[]{TEST_WLAN_IFNAME}; final boolean isTetheringActive = true; final int expectedInteractionsWithShowNotification = 0; boolean currDisallow = true; boolean nextDisallow = true; runUserRestrictionsChange(currDisallow, nextDisallow, nonEmptyActiveIfacesList, runUserRestrictionsChange(currDisallow, nextDisallow, isTetheringActive, expectedInteractionsWithShowNotification); currDisallow = false; nextDisallow = false; runUserRestrictionsChange(currDisallow, nextDisallow, nonEmptyActiveIfacesList, runUserRestrictionsChange(currDisallow, nextDisallow, isTetheringActive, expectedInteractionsWithShowNotification); } Loading