diff options
| -rw-r--r-- | packages/SystemUI/src/com/android/systemui/doze/DozeScreenBrightness.java | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/doze/DozeScreenBrightness.java b/packages/SystemUI/src/com/android/systemui/doze/DozeScreenBrightness.java index 5d99c571ee20..ce84b84935c5 100644 --- a/packages/SystemUI/src/com/android/systemui/doze/DozeScreenBrightness.java +++ b/packages/SystemUI/src/com/android/systemui/doze/DozeScreenBrightness.java @@ -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) { - IntentFilter filter = new IntentFilter(); - filter.addAction(ACTION_AOD_BRIGHTNESS); - mContext.registerReceiverAsUser(this, UserHandle.ALL, filter, null, null); + Dependency.get(Dependency.BG_HANDLER).post(()-> { + IntentFilter filter = new IntentFilter(); + filter.addAction(ACTION_AOD_BRIGHTNESS); + 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); |