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

Commit 2df4e144 authored by daqi's avatar daqi
Browse files

Fix ContentObserver unregister issue

[Cause of Defect]
In the ContentObserver callback procedure, the binder thread
has no sync mechanism with handler thread.
The ContentObserver#onChange method can get called after
ContentResolver#unregisterContentObserver called in the
very low probability.

Bug: https://issuetracker.google.com/issues/63154326
Test: manual - check https://github.com/nanjingdaqi/ContentObserverDemo


Change-Id: I0e3831eba7a9cc1a5bf0d30abe5dd0ec8259b0d4
Signed-off-by: default avatardaqi <daqi@xiaomi.com>
parent 10c314e1
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -193,6 +193,11 @@ public abstract class ContentObserver {
     */
    private void dispatchChange(boolean selfChange, Uri uri, int userId) {
        if (mHandler == null) {
            synchronized (mLock) {
                if (mTransport == null) {
                    return;
                }
            }
            onChange(selfChange, uri, userId);
        } else {
            mHandler.post(new NotificationRunnable(selfChange, uri, userId));
@@ -213,6 +218,11 @@ public abstract class ContentObserver {

        @Override
        public void run() {
            synchronized (mLock) {
                if (mTransport == null) {
                    return;
                }
            }
            ContentObserver.this.onChange(mSelfChange, mUri, mUserId);
        }
    }