Suppress Notifications for Hidden Subs
For subscriptions that are hidden (visible == false),
they can still be set to use manual network selection mode.
Since users don't even know about these subscriptions and
cannot do anything with them, if the manual network selection
procedure is unsuccessful, the user shouldn't be notified.
In addition to not showing these notifications, if a subscription
transitions from non-opportunistic to opportunistic, meaning that
it goes from visible to hidden, any active notifications will now
be cancelled.
Bug: 261064637
Test: atest NotificationMgrTest#\
testUpdateNetworkSelection_opportunisticSubscription\
_notificationNotSent
Flag: EXEMPT bugfix
Change-Id: I5a4681162a8cb8722f2dd501316fff2ce33991fe
diff --git a/src/com/android/phone/NotificationMgr.java b/src/com/android/phone/NotificationMgr.java
index 3c7b321..4fb96a2 100644
--- a/src/com/android/phone/NotificationMgr.java
+++ b/src/com/android/phone/NotificationMgr.java
@@ -878,7 +878,9 @@
+ (isManualSelection ? selectedNetworkOperatorName : ""));
}
- if (isManualSelection) {
+ if (isManualSelection
+ && isSubscriptionVisibleToUser(
+ mSubscriptionManager.getActiveSubscriptionInfo(subId))) {
mSelectedNetworkOperatorName.put(subId, selectedNetworkOperatorName);
shouldShowNotification(serviceState, subId);
} else {
@@ -934,7 +936,9 @@
+ (isManualSelection ? selectedNetworkOperatorName : ""));
}
- if (isManualSelection) {
+ if (isManualSelection
+ && isSubscriptionVisibleToUser(
+ mSubscriptionManager.getActiveSubscriptionInfo(subId))) {
mSelectedNetworkOperatorName.put(subId, selectedNetworkOperatorName);
shouldShowNotification(serviceState, subId);
} else {
@@ -949,6 +953,12 @@
}
}
+ // TODO(b/261916533) This should be handled by SubscriptionManager#isSubscriptionVisible(),
+ // but that method doesn't support system callers, so here we are.
+ private boolean isSubscriptionVisibleToUser(SubscriptionInfo subInfo) {
+ return subInfo != null && (!subInfo.isOpportunistic() || subInfo.getGroupUuid() == null);
+ }
+
private void dismissNetworkSelectionNotification(int subId) {
if (mSelectedUnavailableNotify.get(subId, false)) {
cancelNetworkSelection(subId);
diff --git a/tests/src/com/android/phone/NotificationMgrTest.java b/tests/src/com/android/phone/NotificationMgrTest.java
index 98c6a4a..2b0ff94 100644
--- a/tests/src/com/android/phone/NotificationMgrTest.java
+++ b/tests/src/com/android/phone/NotificationMgrTest.java
@@ -59,6 +59,7 @@
import android.content.pm.ApplicationInfo;
import android.content.res.Resources;
import android.os.Build;
+import android.os.ParcelUuid;
import android.os.PersistableBundle;
import android.os.SystemClock;
import android.os.UserHandle;
@@ -409,6 +410,35 @@
}
@Test
+ public void testUpdateNetworkSelection_opportunisticSubscription_notificationNotSent()
+ throws Exception {
+ prepareResourcesForNetworkSelection();
+ when(mSubscriptionManager.getActiveSubscriptionInfo(eq(TEST_SUB_ID))).thenReturn(
+ mSubscriptionInfo);
+
+ when(mTelephonyManager.isManualNetworkSelectionAllowed()).thenReturn(true);
+ PersistableBundle config = new PersistableBundle();
+ config.putBoolean(CarrierConfigManager.KEY_OPERATOR_SELECTION_EXPAND_BOOL, true);
+ config.putBoolean(CarrierConfigManager.KEY_HIDE_CARRIER_NETWORK_SETTINGS_BOOL, false);
+ config.putBoolean(CarrierConfigManager.KEY_CSP_ENABLED_BOOL, false);
+ config.putBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL, true);
+ when(mCarrierConfigManager.getConfigForSubId(TEST_SUB_ID)).thenReturn(config);
+
+ when(mSubscriptionInfo.isOpportunistic()).thenReturn(true);
+ when(mSubscriptionInfo.getGroupUuid()).thenReturn(
+ ParcelUuid.fromString("5be5c5f3-3412-452e-86a0-6f18558ae8c8"));
+
+ mNotificationMgr.updateNetworkSelection(ServiceState.STATE_OUT_OF_SERVICE, TEST_SUB_ID);
+ try {
+ Thread.sleep(10000);
+ } catch (InterruptedException ignored) {
+ }
+ mNotificationMgr.updateNetworkSelection(ServiceState.STATE_OUT_OF_SERVICE, TEST_SUB_ID);
+
+ verify(mNotificationManager, never()).notify(any(), anyInt(), any());
+ }
+
+ @Test
public void testUpdateNetworkSelection_worldMode_userSetLTE_notificationNotSent() {
prepareResourcesForNetworkSelection();
@@ -632,6 +662,8 @@
when(mApp.getString(R.string.mobile_network_settings_class)).thenReturn(
MOBILE_NETWORK_SELECTION_CLASS);
when(mSubscriptionManager.isActiveSubId(anyInt())).thenReturn(true);
+ when(mSubscriptionManager.getActiveSubscriptionInfo(eq(TEST_SUB_ID))).thenReturn(
+ mSubscriptionInfo);
}
private void moveTimeForward(long seconds) {