Merge "[Telephony] Implement onDataEnabled callback"

This commit is contained in:
Zoey Chen
2021-02-26 09:30:44 +00:00
committed by Gerrit Code Review
3 changed files with 59 additions and 43 deletions

View File

@@ -332,12 +332,12 @@ public class TelephonyRegistryManager {
/** /**
* Notify {@link ServiceState} update on certain subscription. * Notify {@link ServiceState} update on certain subscription.
* *
* @param subId for which the service state changed.
* @param slotIndex for which the service state changed. Can be derived from subId except * @param slotIndex for which the service state changed. Can be derived from subId except
* subId is invalid. * subId is invalid.
* @param subId for which the service state changed.
* @param state service state e.g, in service, out of service or roaming status. * @param state service state e.g, in service, out of service or roaming status.
*/ */
public void notifyServiceStateChanged(int subId, int slotIndex, @NonNull ServiceState state) { public void notifyServiceStateChanged(int slotIndex, int subId, @NonNull ServiceState state) {
try { try {
sRegistry.notifyServiceStateForPhoneId(slotIndex, subId, state); sRegistry.notifyServiceStateForPhoneId(slotIndex, subId, state);
} catch (RemoteException ex) { } catch (RemoteException ex) {
@@ -348,12 +348,12 @@ public class TelephonyRegistryManager {
/** /**
* Notify {@link SignalStrength} update on certain subscription. * Notify {@link SignalStrength} update on certain subscription.
* *
* @param subId for which the signalstrength changed.
* @param slotIndex for which the signalstrength changed. Can be derived from subId except when * @param slotIndex for which the signalstrength changed. Can be derived from subId except when
* subId is invalid. * subId is invalid.
* @param subId for which the signalstrength changed.
* @param signalStrength e.g, signalstrength level {@see SignalStrength#getLevel()} * @param signalStrength e.g, signalstrength level {@see SignalStrength#getLevel()}
*/ */
public void notifySignalStrengthChanged(int subId, int slotIndex, public void notifySignalStrengthChanged(int slotIndex, int subId,
@NonNull SignalStrength signalStrength) { @NonNull SignalStrength signalStrength) {
try { try {
sRegistry.notifySignalStrengthForPhoneId(slotIndex, subId, signalStrength); sRegistry.notifySignalStrengthForPhoneId(slotIndex, subId, signalStrength);
@@ -366,13 +366,13 @@ public class TelephonyRegistryManager {
* Notify changes to the message-waiting indicator on certain subscription. e.g, The status bar * Notify changes to the message-waiting indicator on certain subscription. e.g, The status bar
* uses message waiting indicator to determine when to display the voicemail icon. * uses message waiting indicator to determine when to display the voicemail icon.
* *
* @param subId for which message waiting indicator changed.
* @param slotIndex for which message waiting indicator changed. Can be derived from subId * @param slotIndex for which message waiting indicator changed. Can be derived from subId
* except when subId is invalid. * except when subId is invalid.
* @param subId for which message waiting indicator changed.
* @param msgWaitingInd {@code true} indicates there is message-waiting indicator, {@code false} * @param msgWaitingInd {@code true} indicates there is message-waiting indicator, {@code false}
* otherwise. * otherwise.
*/ */
public void notifyMessageWaitingChanged(int subId, int slotIndex, boolean msgWaitingInd) { public void notifyMessageWaitingChanged(int slotIndex, int subId, boolean msgWaitingInd) {
try { try {
sRegistry.notifyMessageWaitingChangedForPhoneId(slotIndex, subId, msgWaitingInd); sRegistry.notifyMessageWaitingChangedForPhoneId(slotIndex, subId, msgWaitingInd);
} catch (RemoteException ex) { } catch (RemoteException ex) {
@@ -413,9 +413,9 @@ public class TelephonyRegistryManager {
/** /**
* Notify changes to default (Internet) data connection state on certain subscription. * Notify changes to default (Internet) data connection state on certain subscription.
* *
* @param subId for which data connection state changed.
* @param slotIndex for which data connections state changed. Can be derived from subId except * @param slotIndex for which data connections state changed. Can be derived from subId except
* when subId is invalid. * when subId is invalid.
* @param subId for which data connection state changed.
* @param preciseState the PreciseDataConnectionState * @param preciseState the PreciseDataConnectionState
* *
* @see PreciseDataConnectionState * @see PreciseDataConnectionState
@@ -434,13 +434,13 @@ public class TelephonyRegistryManager {
/** /**
* Notify {@link CallQuality} change on certain subscription. * Notify {@link CallQuality} change on certain subscription.
* *
* @param subId for which call quality state changed.
* @param slotIndex for which call quality state changed. Can be derived from subId except when * @param slotIndex for which call quality state changed. Can be derived from subId except when
* subId is invalid. * subId is invalid.
* @param subId for which call quality state changed.
* @param callQuality Information about call quality e.g, call quality level * @param callQuality Information about call quality e.g, call quality level
* @param networkType associated with this data connection. e.g, LTE * @param networkType associated with this data connection. e.g, LTE
*/ */
public void notifyCallQualityChanged(int subId, int slotIndex, @NonNull CallQuality callQuality, public void notifyCallQualityChanged(int slotIndex, int subId, @NonNull CallQuality callQuality,
@NetworkType int networkType) { @NetworkType int networkType) {
try { try {
sRegistry.notifyCallQualityChanged(callQuality, slotIndex, subId, networkType); sRegistry.notifyCallQualityChanged(callQuality, slotIndex, subId, networkType);
@@ -452,11 +452,11 @@ public class TelephonyRegistryManager {
/** /**
* Notify emergency number list changed on certain subscription. * Notify emergency number list changed on certain subscription.
* *
* @param subId for which emergency number list changed.
* @param slotIndex for which emergency number list changed. Can be derived from subId except * @param slotIndex for which emergency number list changed. Can be derived from subId except
* when subId is invalid. * when subId is invalid.
* @param subId for which emergency number list changed.
*/ */
public void notifyEmergencyNumberList(int subId, int slotIndex) { public void notifyEmergencyNumberList( int slotIndex, int subId) {
try { try {
sRegistry.notifyEmergencyNumberList(slotIndex, subId); sRegistry.notifyEmergencyNumberList(slotIndex, subId);
} catch (RemoteException ex) { } catch (RemoteException ex) {
@@ -497,13 +497,13 @@ public class TelephonyRegistryManager {
/** /**
* Notify radio power state changed on certain subscription. * Notify radio power state changed on certain subscription.
* *
* @param subId for which radio power state changed.
* @param slotIndex for which radio power state changed. Can be derived from subId except when * @param slotIndex for which radio power state changed. Can be derived from subId except when
* subId is invalid. * subId is invalid.
* @param subId for which radio power state changed.
* @param radioPowerState the current modem radio state. * @param radioPowerState the current modem radio state.
*/ */
public void notifyRadioPowerStateChanged(int subId, int slotIndex, public void notifyRadioPowerStateChanged(int slotIndex, int subId,
@RadioPowerState int radioPowerState) { @RadioPowerState int radioPowerState) {
try { try {
sRegistry.notifyRadioPowerStateChanged(slotIndex, subId, radioPowerState); sRegistry.notifyRadioPowerStateChanged(slotIndex, subId, radioPowerState);
} catch (RemoteException ex) { } catch (RemoteException ex) {
@@ -541,13 +541,13 @@ public class TelephonyRegistryManager {
* Notify data activation state changed on certain subscription. * Notify data activation state changed on certain subscription.
* @see TelephonyManager#getDataActivationState() * @see TelephonyManager#getDataActivationState()
* *
* @param subId for which data activation state changed.
* @param slotIndex for which data activation state changed. Can be derived from subId except * @param slotIndex for which data activation state changed. Can be derived from subId except
* when subId is invalid. * when subId is invalid.
* @param subId for which data activation state changed.
* @param activationState sim activation state e.g, activated. * @param activationState sim activation state e.g, activated.
*/ */
public void notifyDataActivationStateChanged(int subId, int slotIndex, public void notifyDataActivationStateChanged(int slotIndex, int subId,
@SimActivationState int activationState) { @SimActivationState int activationState) {
try { try {
sRegistry.notifySimActivationStateChangedForPhoneId(slotIndex, subId, sRegistry.notifySimActivationStateChangedForPhoneId(slotIndex, subId,
SIM_ACTIVATION_TYPE_DATA, activationState); SIM_ACTIVATION_TYPE_DATA, activationState);
@@ -560,13 +560,13 @@ public class TelephonyRegistryManager {
* Notify voice activation state changed on certain subscription. * Notify voice activation state changed on certain subscription.
* @see TelephonyManager#getVoiceActivationState() * @see TelephonyManager#getVoiceActivationState()
* *
* @param subId for which voice activation state changed.
* @param slotIndex for which voice activation state changed. Can be derived from subId except * @param slotIndex for which voice activation state changed. Can be derived from subId except
* subId is invalid. * subId is invalid.
* @param subId for which voice activation state changed.
* @param activationState sim activation state e.g, activated. * @param activationState sim activation state e.g, activated.
*/ */
public void notifyVoiceActivationStateChanged(int subId, int slotIndex, public void notifyVoiceActivationStateChanged(int slotIndex, int subId,
@SimActivationState int activationState) { @SimActivationState int activationState) {
try { try {
sRegistry.notifySimActivationStateChangedForPhoneId(slotIndex, subId, sRegistry.notifySimActivationStateChangedForPhoneId(slotIndex, subId,
SIM_ACTIVATION_TYPE_VOICE, activationState); SIM_ACTIVATION_TYPE_VOICE, activationState);
@@ -579,9 +579,9 @@ public class TelephonyRegistryManager {
* Notify User mobile data state changed on certain subscription. e.g, mobile data is enabled * Notify User mobile data state changed on certain subscription. e.g, mobile data is enabled
* or disabled. * or disabled.
* *
* @param subId for which mobile data state has changed.
* @param slotIndex for which mobile data state has changed. Can be derived from subId except * @param slotIndex for which mobile data state has changed. Can be derived from subId except
* when subId is invalid. * when subId is invalid.
* @param subId for which mobile data state has changed.
* @param state {@code true} indicates mobile data is enabled/on. {@code false} otherwise. * @param state {@code true} indicates mobile data is enabled/on. {@code false} otherwise.
*/ */
public void notifyUserMobileDataStateChanged(int slotIndex, int subId, boolean state) { public void notifyUserMobileDataStateChanged(int slotIndex, int subId, boolean state) {
@@ -602,7 +602,7 @@ public class TelephonyRegistryManager {
* @param telephonyDisplayInfo The display info. * @param telephonyDisplayInfo The display info.
*/ */
public void notifyDisplayInfoChanged(int slotIndex, int subscriptionId, public void notifyDisplayInfoChanged(int slotIndex, int subscriptionId,
@NonNull TelephonyDisplayInfo telephonyDisplayInfo) { @NonNull TelephonyDisplayInfo telephonyDisplayInfo) {
try { try {
sRegistry.notifyDisplayInfoChanged(slotIndex, subscriptionId, telephonyDisplayInfo); sRegistry.notifyDisplayInfoChanged(slotIndex, subscriptionId, telephonyDisplayInfo);
} catch (RemoteException ex) { } catch (RemoteException ex) {
@@ -643,14 +643,14 @@ public class TelephonyRegistryManager {
* Notify precise call state changed on certain subscription, including foreground, background * Notify precise call state changed on certain subscription, including foreground, background
* and ringcall states. * and ringcall states.
* *
* @param subId for which precise call state changed.
* @param slotIndex for which precise call state changed. Can be derived from subId except when * @param slotIndex for which precise call state changed. Can be derived from subId except when
* subId is invalid. * subId is invalid.
* @param subId for which precise call state changed.
* @param ringCallPreciseState ringCall state. * @param ringCallPreciseState ringCall state.
* @param foregroundCallPreciseState foreground call state. * @param foregroundCallPreciseState foreground call state.
* @param backgroundCallPreciseState background call state. * @param backgroundCallPreciseState background call state.
*/ */
public void notifyPreciseCallState(int subId, int slotIndex, public void notifyPreciseCallState(int slotIndex, int subId,
@PreciseCallStates int ringCallPreciseState, @PreciseCallStates int ringCallPreciseState,
@PreciseCallStates int foregroundCallPreciseState, @PreciseCallStates int foregroundCallPreciseState,
@PreciseCallStates int backgroundCallPreciseState) { @PreciseCallStates int backgroundCallPreciseState) {
@@ -793,9 +793,10 @@ public class TelephonyRegistryManager {
* @param reason Reason for data enabled/disabled. See {@code REASON_*} in * @param reason Reason for data enabled/disabled. See {@code REASON_*} in
* {@link TelephonyManager}. * {@link TelephonyManager}.
*/ */
public void notifyDataEnabled(boolean enabled, @TelephonyManager.DataEnabledReason int reason) { public void notifyDataEnabled(int slotIndex, int subId, boolean enabled,
@TelephonyManager.DataEnabledReason int reason) {
try { try {
sRegistry.notifyDataEnabled(enabled, reason); sRegistry.notifyDataEnabled(slotIndex, subId, enabled, reason);
} catch (RemoteException ex) { } catch (RemoteException ex) {
// system server crash // system server crash
} }

View File

@@ -93,5 +93,5 @@ interface ITelephonyRegistry {
void notifyBarringInfoChanged(int slotIndex, int subId, in BarringInfo barringInfo); void notifyBarringInfoChanged(int slotIndex, int subId, in BarringInfo barringInfo);
void notifyPhysicalChannelConfigForSubscriber(in int subId, void notifyPhysicalChannelConfigForSubscriber(in int subId,
in List<PhysicalChannelConfig> configs); in List<PhysicalChannelConfig> configs);
void notifyDataEnabled(boolean enabled, int reason); void notifyDataEnabled(in int phoneId, int subId, boolean enabled, int reason);
} }

View File

@@ -312,9 +312,9 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub {
private List<PhysicalChannelConfig> mPhysicalChannelConfigs; private List<PhysicalChannelConfig> mPhysicalChannelConfigs;
private boolean mIsDataEnabled = false; private boolean[] mIsDataEnabled;
private int mDataEnabledReason; private int[] mDataEnabledReason;
/** /**
* Per-phone map of precise data connection state. The key of the map is the pair of transport * Per-phone map of precise data connection state. The key of the map is the pair of transport
@@ -521,6 +521,8 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub {
mOutgoingCallEmergencyNumber = copyOf(mOutgoingCallEmergencyNumber, mNumPhones); mOutgoingCallEmergencyNumber = copyOf(mOutgoingCallEmergencyNumber, mNumPhones);
mOutgoingSmsEmergencyNumber = copyOf(mOutgoingSmsEmergencyNumber, mNumPhones); mOutgoingSmsEmergencyNumber = copyOf(mOutgoingSmsEmergencyNumber, mNumPhones);
mTelephonyDisplayInfos = copyOf(mTelephonyDisplayInfos, mNumPhones); mTelephonyDisplayInfos = copyOf(mTelephonyDisplayInfos, mNumPhones);
mIsDataEnabled= copyOf(mIsDataEnabled, mNumPhones);
mDataEnabledReason = copyOf(mDataEnabledReason, mNumPhones);
// ds -> ss switch. // ds -> ss switch.
if (mNumPhones < oldNumPhones) { if (mNumPhones < oldNumPhones) {
@@ -563,6 +565,8 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub {
mBarringInfo.add(i, new BarringInfo()); mBarringInfo.add(i, new BarringInfo());
mTelephonyDisplayInfos[i] = null; mTelephonyDisplayInfos[i] = null;
mPhysicalChannelConfigs.add(i, new PhysicalChannelConfig.Builder().build()); mPhysicalChannelConfigs.add(i, new PhysicalChannelConfig.Builder().build());
mIsDataEnabled[i] = false;
mDataEnabledReason[i] = TelephonyManager.DATA_ENABLED_REASON_USER;
} }
} }
@@ -622,6 +626,8 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub {
mBarringInfo = new ArrayList<>(); mBarringInfo = new ArrayList<>();
mTelephonyDisplayInfos = new TelephonyDisplayInfo[numPhones]; mTelephonyDisplayInfos = new TelephonyDisplayInfo[numPhones];
mPhysicalChannelConfigs = new ArrayList<>(); mPhysicalChannelConfigs = new ArrayList<>();
mIsDataEnabled = new boolean[numPhones];
mDataEnabledReason = new int[numPhones];
for (int i = 0; i < numPhones; i++) { for (int i = 0; i < numPhones; i++) {
mCallState[i] = TelephonyManager.CALL_STATE_IDLE; mCallState[i] = TelephonyManager.CALL_STATE_IDLE;
mDataActivity[i] = TelephonyManager.DATA_ACTIVITY_NONE; mDataActivity[i] = TelephonyManager.DATA_ACTIVITY_NONE;
@@ -652,6 +658,8 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub {
mBarringInfo.add(i, new BarringInfo()); mBarringInfo.add(i, new BarringInfo());
mTelephonyDisplayInfos[i] = null; mTelephonyDisplayInfos[i] = null;
mPhysicalChannelConfigs.add(i, new PhysicalChannelConfig.Builder().build()); mPhysicalChannelConfigs.add(i, new PhysicalChannelConfig.Builder().build());
mIsDataEnabled[i] = false;
mDataEnabledReason[i] = TelephonyManager.DATA_ENABLED_REASON_USER;
} }
mAppOps = mContext.getSystemService(AppOpsManager.class); mAppOps = mContext.getSystemService(AppOpsManager.class);
@@ -1146,7 +1154,8 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub {
if (events.contains( if (events.contains(
PhoneStateListener.EVENT_DATA_ENABLED_CHANGED)) { PhoneStateListener.EVENT_DATA_ENABLED_CHANGED)) {
try { try {
r.callback.onDataEnabledChanged(mIsDataEnabled, mDataEnabledReason); r.callback.onDataEnabledChanged(
mIsDataEnabled[phoneId], mDataEnabledReason[phoneId]);
} catch (RemoteException ex) { } catch (RemoteException ex) {
remove(r.binder); remove(r.binder);
} }
@@ -2358,30 +2367,36 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub {
/** /**
* Notify that the data enabled has changed. * Notify that the data enabled has changed.
* *
* @param phoneId the phone id.
* @param subId the subId.
* @param enabled True if data is enabled, otherwise disabled. * @param enabled True if data is enabled, otherwise disabled.
* @param reason Reason for data enabled/disabled. See {@code DATA_*} in * @param reason Reason for data enabled/disabled. See {@code DATA_*} in
* {@link TelephonyManager}. * {@link TelephonyManager}.
*/ */
public void notifyDataEnabled(boolean enabled, public void notifyDataEnabled(int phoneId, int subId, boolean enabled,
@TelephonyManager.DataEnabledReason int reason) { @TelephonyManager.DataEnabledReason int reason) {
if (!checkNotifyPermission("notifyDataEnabled()")) { if (!checkNotifyPermission("notifyDataEnabled()")) {
return; return;
} }
if (VDBG) { if (VDBG) {
log("notifyDataEnabled: enabled=" + enabled + " reason=" + reason); log("notifyDataEnabled: PhoneId=" + phoneId + " subId=" + subId +
" enabled=" + enabled + " reason=" + reason);
} }
mIsDataEnabled = enabled;
mDataEnabledReason = reason;
synchronized (mRecords) { synchronized (mRecords) {
for (Record r : mRecords) { if (validatePhoneId(phoneId)) {
if (r.matchPhoneStateListenerEvent( mIsDataEnabled[phoneId] = enabled;
PhoneStateListener.EVENT_DATA_ENABLED_CHANGED)) { mDataEnabledReason[phoneId] = reason;
try { for (Record r : mRecords) {
r.callback.onDataEnabledChanged(enabled, reason); if (r.matchPhoneStateListenerEvent(
} catch (RemoteException ex) { PhoneStateListener.EVENT_DATA_ENABLED_CHANGED)
mRemoveList.add(r.binder); && idMatch(r.subId, subId, phoneId)) {
try {
r.callback.onDataEnabledChanged(enabled, reason);
} catch (RemoteException ex) {
mRemoveList.add(r.binder);
}
} }
} }
} }
@@ -2431,6 +2446,8 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub {
pw.println("mOutgoingSmsEmergencyNumber=" + mOutgoingSmsEmergencyNumber[i]); pw.println("mOutgoingSmsEmergencyNumber=" + mOutgoingSmsEmergencyNumber[i]);
pw.println("mBarringInfo=" + mBarringInfo.get(i)); pw.println("mBarringInfo=" + mBarringInfo.get(i));
pw.println("mTelephonyDisplayInfo=" + mTelephonyDisplayInfos[i]); pw.println("mTelephonyDisplayInfo=" + mTelephonyDisplayInfos[i]);
pw.println("mIsDataEnabled=" + mIsDataEnabled);
pw.println("mDataEnabledReason=" + mDataEnabledReason);
pw.decreaseIndent(); pw.decreaseIndent();
} }
pw.println("mCarrierNetworkChangeState=" + mCarrierNetworkChangeState); pw.println("mCarrierNetworkChangeState=" + mCarrierNetworkChangeState);
@@ -2441,8 +2458,6 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub {
pw.println("mDefaultPhoneId=" + mDefaultPhoneId); pw.println("mDefaultPhoneId=" + mDefaultPhoneId);
pw.println("mDefaultSubId=" + mDefaultSubId); pw.println("mDefaultSubId=" + mDefaultSubId);
pw.println("mPhysicalChannelConfigs=" + mPhysicalChannelConfigs); pw.println("mPhysicalChannelConfigs=" + mPhysicalChannelConfigs);
pw.println("mIsDataEnabled=" + mIsDataEnabled);
pw.println("mDataEnabledReason=" + mDataEnabledReason);
pw.decreaseIndent(); pw.decreaseIndent();