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

Commit 9a64d59f authored by Malcolm Chen's avatar Malcolm Chen Committed by Xiangyu/Malcolm Chen
Browse files

Update TelephonyRegistryMock with new APIs

Bug: 92796390
Test: existing unittest
Change-Id: I401b6ede24915bf5256be3a48a215365b75f1062
Merged-In: I401b6ede24915bf5256be3a48a215365b75f1062
parent 9d03c0c8
Loading
Loading
Loading
Loading
+79 −7
Original line number Diff line number Diff line
@@ -45,6 +45,7 @@ public class TelephonyRegistryMock extends ITelephonyRegistry.Stub {

        IPhoneStateListener callback;
        IOnSubscriptionsChangedListener onSubscriptionsChangedListenerCallback;
        IOnSubscriptionsChangedListener onOpportunisticSubscriptionsChangedListenerCallback;

        int callerUserId;

@@ -64,12 +65,19 @@ public class TelephonyRegistryMock extends ITelephonyRegistry.Stub {
            return (onSubscriptionsChangedListenerCallback != null);
        }

        boolean matchOnOpportunisticSubscriptionsChangedListener() {
            return (onOpportunisticSubscriptionsChangedListenerCallback != null);
        }


        @Override
        public String toString() {
            return "{callingPackage=" + callingPackage + " binder=" + binder
                    + " callback=" + callback
                    + " onSubscriptionsChangedListenererCallback="
                    + " onSubscriptionsChangedListenerCallback="
                    + onSubscriptionsChangedListenerCallback
                    + " onOpportunisticSubscriptionsChangedListenerCallback="
                    + onOpportunisticSubscriptionsChangedListenerCallback
                    + " callerUserId=" + callerUserId + " subId=" + subId + " phoneId=" + phoneId
                    + " events=" + Integer.toHexString(events)
                    + " canReadPhoneState=" + canReadPhoneState + "}";
@@ -78,7 +86,8 @@ public class TelephonyRegistryMock extends ITelephonyRegistry.Stub {

    private final ArrayList<IBinder> mRemoveList = new ArrayList<IBinder>();
    private final ArrayList<Record> mRecords = new ArrayList<Record>();
    private boolean hasNotifySubscriptionInfoChangedOccurred = false;
    private boolean mHasNotifySubscriptionInfoChangedOccurred = false;
    private boolean mHasNotifyOpportunisticSubscriptionInfoChangedOccurred = false;

    public TelephonyRegistryMock() {
    }
@@ -133,14 +142,54 @@ public class TelephonyRegistryMock extends ITelephonyRegistry.Stub {
            r.events = 0;
            r.canReadPhoneState = true; // permission has been enforced above
            // Always notify when registration occurs if there has been a notification.
            if (hasNotifySubscriptionInfoChangedOccurred) {
            if (mHasNotifySubscriptionInfoChangedOccurred) {
                try {
                    r.onSubscriptionsChangedListenerCallback.onSubscriptionsChanged();
                } catch (RemoteException e) {
                    remove(r.binder);
                }
            } else {
                //log("listen oscl: hasNotifySubscriptionInfoChangedOccurred==false no callback");
                //log("listen oscl: mHasNotifySubscriptionInfoChangedOccurred==false no callback");
            }
        }

    }

    @Override
    public void addOnOpportunisticSubscriptionsChangedListener(String callingPackage,
            IOnSubscriptionsChangedListener callback) {
        Record r;

        synchronized (mRecords) {
            // register
            find_and_add: {
                IBinder b = callback.asBinder();
                final int n = mRecords.size();
                for (int i = 0; i < n; i++) {
                    r = mRecords.get(i);
                    if (b == r.binder) {
                        break find_and_add;
                    }
                }
                r = new Record();
                r.binder = b;
                mRecords.add(r);
            }

            r.onOpportunisticSubscriptionsChangedListenerCallback = callback;
            r.callingPackage = callingPackage;
            r.callerUserId = UserHandle.getCallingUserId();
            r.events = 0;
            r.canReadPhoneState = true; // permission has been enforced above
            // Always notify when registration occurs if there has been a notification.
            if (mHasNotifyOpportunisticSubscriptionInfoChangedOccurred) {
                try {
                    r.onOpportunisticSubscriptionsChangedListenerCallback.onSubscriptionsChanged();
                } catch (RemoteException e) {
                    remove(r.binder);
                }
            } else {
                //log("listen oscl: mHasNotifySubscriptionInfoChangedOccurred==false no callback");
            }
        }

@@ -155,11 +204,11 @@ public class TelephonyRegistryMock extends ITelephonyRegistry.Stub {
    @Override
    public void notifySubscriptionInfoChanged() {
        synchronized (mRecords) {
            if (!hasNotifySubscriptionInfoChangedOccurred) {
            if (!mHasNotifySubscriptionInfoChangedOccurred) {
                //log("notifySubscriptionInfoChanged: first invocation mRecords.size="
                //        + mRecords.size());
            }
            hasNotifySubscriptionInfoChangedOccurred = true;
            mHasNotifySubscriptionInfoChangedOccurred = true;
            mRemoveList.clear();
            for (Record r : mRecords) {
                if (r.matchOnSubscriptionsChangedListener()) {
@@ -174,6 +223,29 @@ public class TelephonyRegistryMock extends ITelephonyRegistry.Stub {
        }
    }

    @Override
    public void notifyOpportunisticSubscriptionInfoChanged() {
        synchronized (mRecords) {
            if (!mHasNotifyOpportunisticSubscriptionInfoChangedOccurred) {
                //log("notifySubscriptionInfoChanged: first invocation mRecords.size="
                //        + mRecords.size());
            }
            mHasNotifyOpportunisticSubscriptionInfoChangedOccurred = true;
            mRemoveList.clear();
            for (Record r : mRecords) {
                if (r.matchOnOpportunisticSubscriptionsChangedListener()) {
                    try {
                        r.onOpportunisticSubscriptionsChangedListenerCallback
                                .onSubscriptionsChanged();
                    } catch (RemoteException ex) {
                        mRemoveList.add(r.binder);
                    }
                }
            }
            handleRemoveListLocked();
        }
    }

    @Override
    public void listen(String pkg, IPhoneStateListener callback, int events, boolean notifyNow) {
        throw new RuntimeException("Not implemented");