Fix ONS to only return opportunistic subs
As part of the auto-data-switch, it became possible for
the ONS to accidentally return a preferred data sub-ID
that was not opportunistic, which broke the contract of
TelephonyManager#getPreferredOpportunisticDataSubscription.
Since there's no reason for ONS to mess with non-opportunistic
subs, it's safe to just have it not find one in the case that
the preferred sub is not an opportunistic sub.
Bug: 316031997
Test: atest ONSProfileSelectorTest
Flag: EXEMPT bugfix
Change-Id: I4c21309c0898a52332be8e9f9483c92b59cc08c5
diff --git a/src/com/android/ons/ONSProfileSelector.java b/src/com/android/ons/ONSProfileSelector.java
index ecb69be..ba2c877 100644
--- a/src/com/android/ons/ONSProfileSelector.java
+++ b/src/com/android/ons/ONSProfileSelector.java
@@ -883,7 +883,10 @@
}
public int getPreferredDataSubscriptionId() {
- return mSubscriptionManager.getPreferredDataSubscriptionId();
+ final int preferredDataSubId = mSubscriptionManager.getPreferredDataSubscriptionId();
+ return isOpportunisticSub(preferredDataSubId)
+ ? preferredDataSubId
+ : SubscriptionManager.DEFAULT_SUBSCRIPTION_ID;
}
/**