Merge "Add PhoneStateListener#onPreferredDataSubIdChanged"

This commit is contained in:
Xiangyu/Malcolm Chen
2018-10-01 21:47:19 +00:00
committed by Android (Google) Code Review
5 changed files with 71 additions and 3 deletions

View File

@@ -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();

View File

@@ -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;
}
}
};
@@ -646,6 +659,18 @@ public class PhoneStateListener {
// default implementation empty
}
/**
* 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
@@ -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);
}
}
/**

View File

@@ -2157,10 +2157,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
*
*/

View File

@@ -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);
}

View File

@@ -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);
}