Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 92641463 authored by Sewook Seo's avatar Sewook Seo
Browse files

Pass copied CallState to listeners in same process

If listener is in the same process, original instance can be passed
to the listener via AIDL without serialization/de-serialization. So,
we need to pass copied one to that listners.
Since the element is newly created instead of modification in case
of call attribute change, we can use shallow copy for this.

Bug: 379126049
Flag: com.android.internal.telephony.flags.pass_copied_call_state_list
Test: atest FrameworksTelephonyTests
Change-Id: Icd9d527a4ea56c2bf8532072d3a3592333db5b88
parent f3993d13
Loading
Loading
Loading
Loading
+37 −4
Original line number Diff line number Diff line
@@ -449,6 +449,8 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub {
    private AtomicBoolean mIsSatelliteEnabled;
    private AtomicBoolean mWasSatelliteEnabledNotified;

    private final int mPid = Process.myPid();

    /**
     * Per-phone map of precise data connection state. The key of the map is the pair of transport
     * type and APN setting. This is the cache to prevent redundant callbacks to the listeners.
@@ -1441,7 +1443,17 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub {
                }
                if (events.contains(TelephonyCallback.EVENT_CALL_ATTRIBUTES_CHANGED)) {
                    try {
                        if (Flags.passCopiedCallStateList()) {
                            List<CallState> callList;
                            if (r.callerPid == mPid) {
                                callList = List.copyOf(mCallStateLists.get(r.phoneId));
                            } else {
                                callList = mCallStateLists.get(r.phoneId);
                            }
                            r.callback.onCallStatesChanged(callList);
                        } else {
                            r.callback.onCallStatesChanged(mCallStateLists.get(r.phoneId));
                        }
                    } catch (RemoteException ex) {
                        remove(r.binder);
                    }
@@ -2569,12 +2581,25 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub {
                }

                if (notifyCallState) {
                    List<CallState> copyList = null;
                    for (Record r : mRecords) {
                        if (r.matchTelephonyCallbackEvent(
                                TelephonyCallback.EVENT_CALL_ATTRIBUTES_CHANGED)
                                && idMatch(r, subId, phoneId)) {
                            // If listener is in the same process, original instance can be passed
                            // to the listener via AIDL without serialization/de-serialization. We
                            // will pass the copied list. Since the element is newly created instead
                            // of modification for the change, we can use shallow copy for this.
                            try {
                                if (Flags.passCopiedCallStateList()) {
                                    if (r.callerPid == mPid && copyList == null) {
                                        copyList = List.copyOf(mCallStateLists.get(phoneId));
                                    }
                                    r.callback.onCallStatesChanged(copyList == null
                                            ? mCallStateLists.get(phoneId) : copyList);
                                } else {
                                    r.callback.onCallStatesChanged(mCallStateLists.get(phoneId));
                                }
                            } catch (RemoteException ex) {
                                mRemoveList.add(r.binder);
                            }
@@ -2902,13 +2927,21 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub {
                    log("There is no active call to report CallQuality");
                    return;
                }

                List<CallState> copyList = null;
                for (Record r : mRecords) {
                    if (r.matchTelephonyCallbackEvent(
                            TelephonyCallback.EVENT_CALL_ATTRIBUTES_CHANGED)
                            && idMatch(r, subId, phoneId)) {
                        try {
                            if (Flags.passCopiedCallStateList()) {
                                if (r.callerPid == mPid && copyList == null) {
                                    copyList = List.copyOf(mCallStateLists.get(phoneId));
                                }
                                r.callback.onCallStatesChanged(copyList == null
                                        ? mCallStateLists.get(phoneId) : copyList);
                            } else {
                                r.callback.onCallStatesChanged(mCallStateLists.get(phoneId));
                            }
                        } catch (RemoteException ex) {
                            mRemoveList.add(r.binder);
                        }