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

Commit 64ef04b4 authored by Lee Shombert's avatar Lee Shombert
Browse files

Handle autocork message on the background thread

The autocork feature implements a timeout with messages on a
looper.  When the timeout expires, the message handler sets a system
property.  This is I/O (socket read/write).

The original design handled these messages on the main thread but the
I/O causes delays.  This change moves message handling to the
background thread, which is less sensitive to delays.

Flag: EXEMPT bugfix
Test: atest
 * FrameworksCoreTests:PropertyInvalidatedCacheTests
Bug: 356335509
Change-Id: Ia8a416726f6aa6e9067c92ef4fd998211fc66eae
parent a23abe6b
Loading
Loading
Loading
Loading
+11 −2
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import android.text.TextUtils;
import android.util.Log;

import com.android.internal.annotations.GuardedBy;
import com.android.internal.os.BackgroundThread;
import com.android.internal.util.FastPrintWriter;

import java.lang.annotation.Retention;
@@ -1260,7 +1261,7 @@ public class PropertyInvalidatedCache<Query, Result> {
        }

        public void autoCork() {
            if (Looper.getMainLooper() == null) {
            if (getLooper() == null) {
                // We're not ready to auto-cork yet, so just invalidate the cache immediately.
                if (DEBUG) {
                    Log.w(TAG, "invalidating instead of autocorking early in init: "
@@ -1322,7 +1323,7 @@ public class PropertyInvalidatedCache<Query, Result> {
        @GuardedBy("mLock")
        private Handler getHandlerLocked() {
            if (mHandler == null) {
                mHandler = new Handler(Looper.getMainLooper()) {
                mHandler = new Handler(getLooper()) {
                        @Override
                        public void handleMessage(Message msg) {
                            AutoCorker.this.handleMessage(msg);
@@ -1331,6 +1332,14 @@ public class PropertyInvalidatedCache<Query, Result> {
            }
            return mHandler;
        }

        /**
         * Return a looper for auto-uncork messages.  Messages should be processed on the
         * background thread, not on the main thread.
         */
        private static Looper getLooper() {
            return BackgroundThread.getHandler().getLooper();
        }
    }

    /**