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

Commit f23bacec authored by Lucas Dupin's avatar Lucas Dupin Committed by Android (Google) Code Review
Browse files

Merge "Do not block main thread to register debug hook"

parents 8ed0d053 5968855a
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);