[Telephony] Implement onDataEnabled callback

Bug: 147577230
Test: atest CtsTelephonyTestCases:PhoneStateListenerTest
Change-Id: I1b9fe50e4b805f5117fb6e03438dd0a09fbcfebc
This commit is contained in:
Zoey Chen
2020-11-04 18:05:33 +08:00
parent 8740b1ea93
commit 4ad5f0a7c7
3 changed files with 52 additions and 0 deletions

View File

@@ -786,6 +786,21 @@ public class TelephonyRegistryManager {
}
}
/**
* Notify that the data enabled has changed.
*
* @param enabled True if data is enabled, otherwise disabled.
* @param reason Reason for data enabled/disabled. See {@code REASON_*} in
* {@link TelephonyManager}.
*/
public void notifyDataEnabled(boolean enabled, @TelephonyManager.DataEnabledReason int reason) {
try {
sRegistry.notifyDataEnabled(enabled, reason);
} catch (RemoteException ex) {
// system server crash
}
}
public @NonNull Set<Integer> getEventsFromListener(@NonNull PhoneStateListener listener) {
Set<Integer> eventList = new ArraySet<>();

View File

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

View File

@@ -2362,6 +2362,40 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub {
}
}
/**
* Notify that the data enabled has changed.
*
* @param enabled True if data is enabled, otherwise disabled.
* @param reason Reason for data enabled/disabled. See {@code DATA_*} in
* {@link TelephonyManager}.
*/
public void notifyDataEnabled(boolean enabled,
@TelephonyManager.DataEnabledReason int reason) {
if (!checkNotifyPermission("notifyDataEnabled()")) {
return;
}
if (VDBG) {
log("notifyDataEnabled: enabled=" + enabled + " reason=" + reason);
}
mIsDataEnabled = enabled;
mDataEnabledReason = reason;
synchronized (mRecords) {
for (Record r : mRecords) {
if (r.matchPhoneStateListenerEvent(
PhoneStateListener.EVENT_DATA_ENABLED_CHANGED)) {
try {
r.callback.onDataEnabledChanged(enabled, reason);
} catch (RemoteException ex) {
mRemoveList.add(r.binder);
}
}
}
handleRemoveListLocked();
}
}
@Override
public void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
final IndentingPrintWriter pw = new IndentingPrintWriter(writer, " ");
@@ -2414,6 +2448,8 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub {
pw.println("mDefaultPhoneId=" + mDefaultPhoneId);
pw.println("mDefaultSubId=" + mDefaultSubId);
pw.println("mPhysicalChannelConfigs=" + mPhysicalChannelConfigs);
pw.println("mIsDataEnabled=" + mIsDataEnabled);
pw.println("mDataEnabledReason=" + mDataEnabledReason);
pw.decreaseIndent();