From 8e4034d2f2f1b3937cb0c51b827e32eae2f264ab Mon Sep 17 00:00:00 2001 From: Sewook Seo Date: Tue, 17 Jan 2023 03:11:13 +0000 Subject: [PATCH] Notify to listener when CallState is changed. Notify to PreciseCallStateListener when PreciseCallState reported from phone is changed. Notify to CallAttributeListener when there is a change on CallState list. Bug: 265610260 Test: device test. VZW TC VoWiFi 5.15 Change-Id: I10f5b928bd9bacc3e75a167d8a3ee1d36f508eeb --- .../com/android/server/TelephonyRegistry.java | 49 +++++++++++++------ 1 file changed, 33 insertions(+), 16 deletions(-) diff --git a/services/core/java/com/android/server/TelephonyRegistry.java b/services/core/java/com/android/server/TelephonyRegistry.java index 4e5ce8804bb1a..4504f91faf25a 100644 --- a/services/core/java/com/android/server/TelephonyRegistry.java +++ b/services/core/java/com/android/server/TelephonyRegistry.java @@ -2250,14 +2250,19 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub { synchronized (mRecords) { if (validatePhoneId(phoneId)) { + boolean preciseCallStateChanged = false; mRingingCallState[phoneId] = ringingCallState; mForegroundCallState[phoneId] = foregroundCallState; mBackgroundCallState[phoneId] = backgroundCallState; - mPreciseCallState[phoneId] = new PreciseCallState( + PreciseCallState preciseCallState = new PreciseCallState( ringingCallState, foregroundCallState, backgroundCallState, DisconnectCause.NOT_VALID, PreciseDisconnectCause.NOT_VALID); + if (!preciseCallState.equals(mPreciseCallState[phoneId])) { + preciseCallStateChanged = true; + mPreciseCallState[phoneId] = preciseCallState; + } boolean notifyCallState = true; if (mCallQuality == null) { log("notifyPreciseCallState: mCallQuality is null, " @@ -2271,6 +2276,8 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub { mCallNetworkType[phoneId] = TelephonyManager.NETWORK_TYPE_UNKNOWN; mCallQuality[phoneId] = createCallQuality(); } + List prevCallStateList = new ArrayList<>(); + prevCallStateList.addAll(mCallStateLists.get(phoneId)); mCallStateLists.get(phoneId).clear(); if (foregroundCallState != PreciseCallState.PRECISE_CALL_STATE_NOT_VALID && foregroundCallState != PreciseCallState.PRECISE_CALL_STATE_IDLE) { @@ -2330,6 +2337,9 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub { } mCallStateLists.get(phoneId).add(builder.build()); } + if (prevCallStateList.equals(mCallStateLists.get(phoneId))) { + notifyCallState = false; + } boolean hasOngoingCall = false; for (CallState cs : mCallStateLists.get(phoneId)) { if (cs.getCallState() != PreciseCallState.PRECISE_CALL_STATE_DISCONNECTED) { @@ -2343,23 +2353,30 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub { } } - for (Record r : mRecords) { - if (r.matchTelephonyCallbackEvent( - TelephonyCallback.EVENT_PRECISE_CALL_STATE_CHANGED) - && idMatch(r, subId, phoneId)) { - try { - r.callback.onPreciseCallStateChanged(mPreciseCallState[phoneId]); - } catch (RemoteException ex) { - mRemoveList.add(r.binder); + if (preciseCallStateChanged) { + for (Record r : mRecords) { + if (r.matchTelephonyCallbackEvent( + TelephonyCallback.EVENT_PRECISE_CALL_STATE_CHANGED) + && idMatch(r, subId, phoneId)) { + try { + r.callback.onPreciseCallStateChanged(mPreciseCallState[phoneId]); + } catch (RemoteException ex) { + mRemoveList.add(r.binder); + } } } - if (notifyCallState && r.matchTelephonyCallbackEvent( - TelephonyCallback.EVENT_CALL_ATTRIBUTES_CHANGED) - && idMatch(r, subId, phoneId)) { - try { - r.callback.onCallStatesChanged(mCallStateLists.get(phoneId)); - } catch (RemoteException ex) { - mRemoveList.add(r.binder); + } + + if (notifyCallState) { + for (Record r : mRecords) { + if (r.matchTelephonyCallbackEvent( + TelephonyCallback.EVENT_CALL_ATTRIBUTES_CHANGED) + && idMatch(r, subId, phoneId)) { + try { + r.callback.onCallStatesChanged(mCallStateLists.get(phoneId)); + } catch (RemoteException ex) { + mRemoveList.add(r.binder); + } } } }