[TNU09] Adjust restricted notification
1. Let restricted notification that can be dismissed.
2. Only put up restricted notification when any of tethering is
activating.
Bug: 154214549
Test: atest TetheringTests
Change-Id: Ib980aca154036828abdab35e3bb11d42f85ff610
Merged-In: Ib980aca154036828abdab35e3bb11d42f85ff610
(cherry picked from commit 2eb66bdbe4, aosp/1290334)
This commit is contained in:
@@ -1006,6 +1006,11 @@ public class Tethering {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@VisibleForTesting
|
||||||
|
boolean isTetheringActive() {
|
||||||
|
return mActiveTetheringRequests.size() > 0;
|
||||||
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
protected static class UserRestrictionActionListener {
|
protected static class UserRestrictionActionListener {
|
||||||
private final UserManager mUserManager;
|
private final UserManager mUserManager;
|
||||||
@@ -1043,13 +1048,14 @@ public class Tethering {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (mWrapper.isTetheringActive()) {
|
||||||
// Restricted notification is shown when tethering function is disallowed on
|
// Restricted notification is shown when tethering function is disallowed on
|
||||||
// user's device.
|
// user's device.
|
||||||
mNotificationUpdater.notifyTetheringDisabledByRestriction();
|
mNotificationUpdater.notifyTetheringDisabledByRestriction();
|
||||||
|
|
||||||
// Untether from all downstreams since tethering is disallowed.
|
// Untether from all downstreams since tethering is disallowed.
|
||||||
mWrapper.untetherAll();
|
mWrapper.untetherAll();
|
||||||
|
}
|
||||||
// TODO(b/148139325): send tetheringSupported on restriction change
|
// TODO(b/148139325): send tetheringSupported on restriction change
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -267,7 +267,7 @@ public class TetheringNotificationUpdater {
|
|||||||
null /* options */);
|
null /* options */);
|
||||||
|
|
||||||
showNotification(R.drawable.stat_sys_tether_general, title, message,
|
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() {
|
private void notifyTetheringNoUpstream() {
|
||||||
@@ -288,7 +288,7 @@ public class TetheringNotificationUpdater {
|
|||||||
final Action action = new Action.Builder(NO_ICON_ID, disableButton, pi).build();
|
final Action action = new Action.Builder(NO_ICON_ID, disableButton, pi).build();
|
||||||
|
|
||||||
showNotification(R.drawable.stat_sys_tether_general, title, message,
|
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() {
|
private boolean setupRoamingNotification() {
|
||||||
@@ -310,7 +310,7 @@ public class TetheringNotificationUpdater {
|
|||||||
null /* options */);
|
null /* options */);
|
||||||
|
|
||||||
showNotification(R.drawable.stat_sys_tether_general, title, message,
|
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;
|
return NOTIFY_DONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -327,14 +327,14 @@ public class TetheringNotificationUpdater {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void showNotification(@DrawableRes final int iconId, @NonNull final String title,
|
private void showNotification(@DrawableRes final int iconId, @NonNull final String title,
|
||||||
@NonNull final String message, @NotificationId final int id, @Nullable PendingIntent pi,
|
@NonNull final String message, @NotificationId final int id, final boolean ongoing,
|
||||||
@NonNull final Action... actions) {
|
@Nullable PendingIntent pi, @NonNull final Action... actions) {
|
||||||
final Notification notification =
|
final Notification notification =
|
||||||
new Notification.Builder(mContext, mChannel.getId())
|
new Notification.Builder(mContext, mChannel.getId())
|
||||||
.setSmallIcon(iconId)
|
.setSmallIcon(iconId)
|
||||||
.setContentTitle(title)
|
.setContentTitle(title)
|
||||||
.setContentText(message)
|
.setContentText(message)
|
||||||
.setOngoing(true)
|
.setOngoing(ongoing)
|
||||||
.setColor(mContext.getColor(
|
.setColor(mContext.getColor(
|
||||||
android.R.color.system_notification_accent_color))
|
android.R.color.system_notification_accent_color))
|
||||||
.setVisibility(Notification.VISIBILITY_PUBLIC)
|
.setVisibility(Notification.VISIBILITY_PUBLIC)
|
||||||
|
|||||||
@@ -1079,12 +1079,12 @@ public class TetheringTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void runUserRestrictionsChange(
|
private void runUserRestrictionsChange(
|
||||||
boolean currentDisallow, boolean nextDisallow, String[] activeTetheringIfacesList,
|
boolean currentDisallow, boolean nextDisallow, boolean isTetheringActive,
|
||||||
int expectedInteractionsWithShowNotification) throws Exception {
|
int expectedInteractionsWithShowNotification) throws Exception {
|
||||||
final Bundle newRestrictions = new Bundle();
|
final Bundle newRestrictions = new Bundle();
|
||||||
newRestrictions.putBoolean(UserManager.DISALLOW_CONFIG_TETHERING, nextDisallow);
|
newRestrictions.putBoolean(UserManager.DISALLOW_CONFIG_TETHERING, nextDisallow);
|
||||||
final Tethering mockTethering = mock(Tethering.class);
|
final Tethering mockTethering = mock(Tethering.class);
|
||||||
when(mockTethering.getTetheredIfaces()).thenReturn(activeTetheringIfacesList);
|
when(mockTethering.isTetheringActive()).thenReturn(isTetheringActive);
|
||||||
when(mUserManager.getUserRestrictions()).thenReturn(newRestrictions);
|
when(mUserManager.getUserRestrictions()).thenReturn(newRestrictions);
|
||||||
|
|
||||||
final Tethering.UserRestrictionActionListener ural =
|
final Tethering.UserRestrictionActionListener ural =
|
||||||
@@ -1100,63 +1100,63 @@ public class TetheringTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDisallowTetheringWhenNoTetheringInterfaceIsActive() throws Exception {
|
public void testDisallowTetheringWhenTetheringIsNotActive() throws Exception {
|
||||||
final String[] emptyActiveIfacesList = new String[]{};
|
final boolean isTetheringActive = false;
|
||||||
|
final boolean currDisallow = false;
|
||||||
|
final boolean nextDisallow = true;
|
||||||
|
final int expectedInteractionsWithShowNotification = 0;
|
||||||
|
|
||||||
|
runUserRestrictionsChange(currDisallow, nextDisallow, isTetheringActive,
|
||||||
|
expectedInteractionsWithShowNotification);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDisallowTetheringWhenTetheringIsActive() throws Exception {
|
||||||
|
final boolean isTetheringActive = true;
|
||||||
final boolean currDisallow = false;
|
final boolean currDisallow = false;
|
||||||
final boolean nextDisallow = true;
|
final boolean nextDisallow = true;
|
||||||
final int expectedInteractionsWithShowNotification = 1;
|
final int expectedInteractionsWithShowNotification = 1;
|
||||||
|
|
||||||
runUserRestrictionsChange(currDisallow, nextDisallow, emptyActiveIfacesList,
|
runUserRestrictionsChange(currDisallow, nextDisallow, isTetheringActive,
|
||||||
expectedInteractionsWithShowNotification);
|
expectedInteractionsWithShowNotification);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDisallowTetheringWhenAtLeastOneTetheringInterfaceIsActive() throws Exception {
|
public void testAllowTetheringWhenTetheringIsNotActive() throws Exception {
|
||||||
final String[] nonEmptyActiveIfacesList = new String[]{TEST_WLAN_IFNAME};
|
final boolean isTetheringActive = false;
|
||||||
final boolean currDisallow = false;
|
|
||||||
final boolean nextDisallow = true;
|
|
||||||
final int expectedInteractionsWithShowNotification = 1;
|
|
||||||
|
|
||||||
runUserRestrictionsChange(currDisallow, nextDisallow, nonEmptyActiveIfacesList,
|
|
||||||
expectedInteractionsWithShowNotification);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testAllowTetheringWhenNoTetheringInterfaceIsActive() throws Exception {
|
|
||||||
final String[] nonEmptyActiveIfacesList = new String[]{};
|
|
||||||
final boolean currDisallow = true;
|
final boolean currDisallow = true;
|
||||||
final boolean nextDisallow = false;
|
final boolean nextDisallow = false;
|
||||||
final int expectedInteractionsWithShowNotification = 0;
|
final int expectedInteractionsWithShowNotification = 0;
|
||||||
|
|
||||||
runUserRestrictionsChange(currDisallow, nextDisallow, nonEmptyActiveIfacesList,
|
runUserRestrictionsChange(currDisallow, nextDisallow, isTetheringActive,
|
||||||
expectedInteractionsWithShowNotification);
|
expectedInteractionsWithShowNotification);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAllowTetheringWhenAtLeastOneTetheringInterfaceIsActive() throws Exception {
|
public void testAllowTetheringWhenTetheringIsActive() throws Exception {
|
||||||
final String[] nonEmptyActiveIfacesList = new String[]{TEST_WLAN_IFNAME};
|
final boolean isTetheringActive = true;
|
||||||
final boolean currDisallow = true;
|
final boolean currDisallow = true;
|
||||||
final boolean nextDisallow = false;
|
final boolean nextDisallow = false;
|
||||||
final int expectedInteractionsWithShowNotification = 0;
|
final int expectedInteractionsWithShowNotification = 0;
|
||||||
|
|
||||||
runUserRestrictionsChange(currDisallow, nextDisallow, nonEmptyActiveIfacesList,
|
runUserRestrictionsChange(currDisallow, nextDisallow, isTetheringActive,
|
||||||
expectedInteractionsWithShowNotification);
|
expectedInteractionsWithShowNotification);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDisallowTetheringUnchanged() throws Exception {
|
public void testDisallowTetheringUnchanged() throws Exception {
|
||||||
final String[] nonEmptyActiveIfacesList = new String[]{TEST_WLAN_IFNAME};
|
final boolean isTetheringActive = true;
|
||||||
final int expectedInteractionsWithShowNotification = 0;
|
final int expectedInteractionsWithShowNotification = 0;
|
||||||
boolean currDisallow = true;
|
boolean currDisallow = true;
|
||||||
boolean nextDisallow = true;
|
boolean nextDisallow = true;
|
||||||
|
|
||||||
runUserRestrictionsChange(currDisallow, nextDisallow, nonEmptyActiveIfacesList,
|
runUserRestrictionsChange(currDisallow, nextDisallow, isTetheringActive,
|
||||||
expectedInteractionsWithShowNotification);
|
expectedInteractionsWithShowNotification);
|
||||||
|
|
||||||
currDisallow = false;
|
currDisallow = false;
|
||||||
nextDisallow = false;
|
nextDisallow = false;
|
||||||
|
|
||||||
runUserRestrictionsChange(currDisallow, nextDisallow, nonEmptyActiveIfacesList,
|
runUserRestrictionsChange(currDisallow, nextDisallow, isTetheringActive,
|
||||||
expectedInteractionsWithShowNotification);
|
expectedInteractionsWithShowNotification);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user