diff options
5 files changed, 71 insertions, 3 deletions
diff --git a/services/core/java/com/android/server/TelephonyRegistry.java b/services/core/java/com/android/server/TelephonyRegistry.java index 98b88cb557af..32c9ce13a249 100644 --- a/services/core/java/com/android/server/TelephonyRegistry.java +++ b/services/core/java/com/android/server/TelephonyRegistry.java @@ -213,6 +213,8 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub { private PhoneCapability mPhoneCapability = null; + private int mPreferredDataSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; + private final LocalLog mLocalLog = new LocalLog(100); private PreciseDataConnectionState mPreciseDataConnectionState = @@ -752,6 +754,13 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub { remove(r.binder); } } + if ((events & PhoneStateListener.LISTEN_PREFERRED_DATA_SUBID_CHANGE) != 0) { + try { + r.callback.onPreferredDataSubIdChanged(mPreferredDataSubId); + } catch (RemoteException ex) { + remove(r.binder); + } + } } } } else { @@ -1573,6 +1582,31 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub { } } + public void notifyPreferredDataSubIdChanged(int preferredSubId) { + if (!checkNotifyPermission("notifyPreferredDataSubIdChanged()")) { + return; + } + + if (VDBG) { + log("notifyPreferredDataSubIdChanged: preferredSubId=" + preferredSubId); + } + + synchronized (mRecords) { + mPreferredDataSubId = preferredSubId; + + for (Record r : mRecords) { + if (r.matchPhoneStateListenerEvent( + PhoneStateListener.LISTEN_PREFERRED_DATA_SUBID_CHANGE)) { + try { + r.callback.onPreferredDataSubIdChanged(preferredSubId); + } catch (RemoteException ex) { + mRemoveList.add(r.binder); + } + } + } + handleRemoveListLocked(); + } + } @Override public void dump(FileDescriptor fd, PrintWriter writer, String[] args) { @@ -1610,6 +1644,7 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub { pw.println("mBackgroundCallState=" + mBackgroundCallState); pw.println("mVoLteServiceState=" + mVoLteServiceState); pw.println("mPhoneCapability=" + mPhoneCapability); + pw.println("mPreferredDataSubId=" + mPreferredDataSubId); pw.decreaseIndent(); diff --git a/telephony/java/android/telephony/PhoneStateListener.java b/telephony/java/android/telephony/PhoneStateListener.java index 498be968265f..3ea018af97cf 100644 --- a/telephony/java/android/telephony/PhoneStateListener.java +++ b/telephony/java/android/telephony/PhoneStateListener.java @@ -281,6 +281,16 @@ public class PhoneStateListener { */ public static final int LISTEN_PHONE_CAPABILITY_CHANGE = 0x00200000; + /** + * Listen for changes to preferred data subId. + * See {@link SubscriptionManager#setPreferredData(int)} + * for more details. + * + * @see #onPreferredDataSubIdChanged + * @hide + */ + public static final int LISTEN_PREFERRED_DATA_SUBID_CHANGE = 0x00400000; + /* * Subscription used to listen to the phone state changes * @hide @@ -407,6 +417,9 @@ public class PhoneStateListener { PhoneStateListener.this.onPhoneCapabilityChanged( (PhoneCapability) msg.obj); break; + case LISTEN_PREFERRED_DATA_SUBID_CHANGE: + PhoneStateListener.this.onPreferredDataSubIdChanged((int) msg.obj); + break; } } }; @@ -647,6 +660,18 @@ public class PhoneStateListener { } /** + * Callback invoked when preferred data subId changes. Requires + * the READ_PRIVILEGED_PHONE_STATE permission. + * @param subId the new preferred data subId. If it's INVALID_SUBSCRIPTION_ID, + * it means it's unset and defaultDataSub is used to determine which + * modem is preferred. + * @hide + */ + public void onPreferredDataSubIdChanged(int subId) { + // default implementation empty + } + + /** * Callback invoked when telephony has received notice from a carrier * app that a network action that could result in connectivity loss * has been requested by an app using @@ -777,6 +802,11 @@ public class PhoneStateListener { public void onPhoneCapabilityChanged(PhoneCapability capability) { send(LISTEN_PHONE_CAPABILITY_CHANGE, 0, 0, capability); } + + public void onPreferredDataSubIdChanged(int subId) { + send(LISTEN_PREFERRED_DATA_SUBID_CHANGE, 0, 0, subId); + } + } /** diff --git a/telephony/java/android/telephony/SubscriptionManager.java b/telephony/java/android/telephony/SubscriptionManager.java index d4da58974c90..4199d18b99f5 100644 --- a/telephony/java/android/telephony/SubscriptionManager.java +++ b/telephony/java/android/telephony/SubscriptionManager.java @@ -2121,10 +2121,11 @@ public class SubscriptionManager { * It's also usually what we set up internet connection on. * * PreferredData overwrites user setting of default data subscription. And it's used - * by ANAS or carrier apps to switch primary and CBRS subscription dynamically in multi-SIM - * devices. + * by AlternativeNetworkAccessService or carrier apps to switch primary and CBRS + * subscription dynamically in multi-SIM devices. * - * @param slotId which slot is preferred to for cellular data. + * @param slotId which slot is preferred to for cellular data. If it's INVALID, it means + * it's unset and defaultDataSubId is used to determine which modem is preferred. * @hide * */ diff --git a/telephony/java/com/android/internal/telephony/IPhoneStateListener.aidl b/telephony/java/com/android/internal/telephony/IPhoneStateListener.aidl index 1ebb6976b45e..38a1bc73c94d 100644 --- a/telephony/java/com/android/internal/telephony/IPhoneStateListener.aidl +++ b/telephony/java/com/android/internal/telephony/IPhoneStateListener.aidl @@ -52,5 +52,6 @@ oneway interface IPhoneStateListener { void onCarrierNetworkChange(in boolean active); void onUserMobileDataStateChanged(in boolean enabled); void onPhoneCapabilityChanged(in PhoneCapability capability); + void onPreferredDataSubIdChanged(in int subId); } diff --git a/telephony/java/com/android/internal/telephony/ITelephonyRegistry.aidl b/telephony/java/com/android/internal/telephony/ITelephonyRegistry.aidl index 43d56b39e0c4..c03065c34ca8 100644 --- a/telephony/java/com/android/internal/telephony/ITelephonyRegistry.aidl +++ b/telephony/java/com/android/internal/telephony/ITelephonyRegistry.aidl @@ -79,4 +79,5 @@ interface ITelephonyRegistry { void notifyCarrierNetworkChange(in boolean active); void notifyUserMobileDataStateChangedForPhoneId(in int phoneId, in int subId, in boolean state); void notifyPhoneCapabilityChanged(in PhoneCapability capability); + void notifyPreferredDataSubIdChanged(int preferredSubId); } |