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

Commit 52f31f18 authored by Sewook Seo's avatar Sewook Seo Committed by Android (Google) Code Review
Browse files

Merge "Pass copied CallState to listeners in same process" into main

parents be043ed9 92641463
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);
                    }
@@ -2573,12 +2585,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);
                            }
@@ -2906,13 +2931,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);
                        }