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

Commit 93145c5d authored by 0000105584's avatar 0000105584 Committed by Henry Fang
Browse files

Fix unnecessary sync waiting on Filter notifications

Negative impact to performance because onFilterStatus() and onFilterEvent() are waiting unnecessarily.

Test: refactoring CL.
Bug: 288361915
Change-Id: Ic9f130bfe7a48630eabda76c53975c5b5bf53295
parent 9994945d
Loading
Loading
Loading
Loading
+25 −21
Original line number Diff line number Diff line
@@ -32,7 +32,6 @@ import android.util.Log;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.NullPointerException;
import java.util.concurrent.Executor;

/**
@@ -270,15 +269,19 @@ public class Filter implements AutoCloseable {
        synchronized (mCallbackLock) {
            if (mCallback != null && mExecutor != null) {
                mExecutor.execute(() -> {
                    FilterCallback callback;
                    synchronized (mCallbackLock) {
                        if (mCallback != null) {
                            try {
                                mCallback.onFilterStatusChanged(this, status);
                        callback = mCallback;
                    }
                            catch (NullPointerException e) {
                    if (callback != null) {
                        try {
                            callback.onFilterStatusChanged(this, status);
                        } catch (NullPointerException e) {
                            Log.d(TAG, "catch exception:" + e);
                        }
                    }
                    if (callback != null) {
                        callback.onFilterStatusChanged(this, status);
                    }
                });
            }
@@ -289,12 +292,14 @@ public class Filter implements AutoCloseable {
        synchronized (mCallbackLock) {
            if (mCallback != null && mExecutor != null) {
                mExecutor.execute(() -> {
                    FilterCallback callback;
                    synchronized (mCallbackLock) {
                        if (mCallback != null) {
                            try {
                                mCallback.onFilterEvent(this, events);
                        callback = mCallback;
                    }
                            catch (NullPointerException e) {
                    if (callback != null) {
                        try {
                            callback.onFilterEvent(this, events);
                        } catch (NullPointerException e) {
                            Log.d(TAG, "catch exception:" + e);
                        }
                    } else {
@@ -304,7 +309,6 @@ public class Filter implements AutoCloseable {
                            }
                        }
                    }
                    }
                });
            } else {
                for (FilterEvent event : events) {