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

Commit 5968855a authored by Lucas Dupin's avatar Lucas Dupin
Browse files

Do not block main thread to register debug hook

Test: atest DozeScreenBrightness
Fixes: 118935318
Change-Id: Ib06e33c59e175ffbe4a4cd3d66450506d8670cb8
parent 4e7b7c1a
Loading
Loading
Loading
Loading
+12 −3
Original line number Diff line number Diff line
@@ -31,6 +31,9 @@ import android.os.UserHandle;
import android.provider.Settings;

import com.android.internal.annotations.VisibleForTesting;
import com.android.systemui.Dependency;

import java.util.concurrent.atomic.AtomicBoolean;

/**
 * Controls the screen brightness when dozing.
@@ -63,6 +66,7 @@ public class DozeScreenBrightness extends BroadcastReceiver implements DozeMachi
     * --ei brightness_bucket 1}
     */
    private int mDebugBrightnessBucket = -1;
    private AtomicBoolean mIsDestroyed = new AtomicBoolean();

    @VisibleForTesting
    public DozeScreenBrightness(Context context, DozeMachine.Service service,
@@ -82,9 +86,13 @@ public class DozeScreenBrightness extends BroadcastReceiver implements DozeMachi
        mSensorToScrimOpacity = sensorToScrimOpacity;

        if (mDebuggable) {
            Dependency.get(Dependency.BG_HANDLER).post(()-> {
                IntentFilter filter = new IntentFilter();
                filter.addAction(ACTION_AOD_BRIGHTNESS);
            mContext.registerReceiverAsUser(this, UserHandle.ALL, filter, null, null);
                if (!mIsDestroyed.get()) {
                    mContext.registerReceiverAsUser(this, UserHandle.ALL, filter, null, handler);
                }
            });
        }
    }

@@ -121,6 +129,7 @@ public class DozeScreenBrightness extends BroadcastReceiver implements DozeMachi
    }

    private void onDestroy() {
        mIsDestroyed.set(true);
        setLightSensorEnabled(false);
        if (mDebuggable) {
            mContext.unregisterReceiver(this);