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

Commit b9e44e50 authored by Robin Lee's avatar Robin Lee
Browse files

Make LogicalLight @Nullable: part one (external)

This helps to simplify the internal logic of LightsService to not have
to worry about sending bad values down to the HAL if system services use
lights that don't actually exist.

Bug: 151113302
Test: atest google/perf/boottime/boottime-test
Change-Id: I0512c71e376c64095270b8e70e9754fe0f81210e
parent e51b6e1c
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -1101,6 +1101,9 @@ public final class BatteryService extends SystemService {
         * Synchronize on BatteryService.
         */
        public void updateLightsLocked() {
            if (mBatteryLight == null) {
                return;
            }
            final int level = mHealthInfo.batteryLevel;
            final int status = mHealthInfo.batteryStatus;
            if (level < mLowBatteryWarningLevel) {
+6 −2
Original line number Diff line number Diff line
@@ -646,8 +646,10 @@ final class LocalDisplayAdapter extends DisplayAdapter {
                                    + "id=" + physicalDisplayId
                                    + ", state=" + Display.stateToString(state) + ")");
                        }
                        if (mBacklight != null) {
                            mBacklight.setVrMode(isVrEnabled);
                        }
                    }

                    private void setDisplayState(int state) {
                        if (DEBUG) {
@@ -708,7 +710,9 @@ final class LocalDisplayAdapter extends DisplayAdapter {
                                        BrightnessSynchronizer.brightnessFloatToInt(getContext(),
                                                brightness));
                            }
                            if (mBacklight != null) {
                                mBacklight.setBrightness(brightness);
                            }
                            Trace.traceCounter(Trace.TRACE_TAG_POWER,
                                    "ScreenBrightness",
                                    BrightnessSynchronizer.brightnessFloatToInt(
+3 −1
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.server.lights;

import android.annotation.Nullable;
import android.hardware.light.V2_0.Type;

public abstract class LightsManager {
@@ -30,7 +31,8 @@ public abstract class LightsManager {
    public static final int LIGHT_ID_COUNT = Type.COUNT;

    /**
     * Returns the logical light with the given type.
     * Returns the logical light with the given type, if it exists, or null.
     */
    @Nullable
    public abstract LogicalLight getLight(int id);
}
+9 −3
Original line number Diff line number Diff line
@@ -1548,7 +1548,9 @@ public class NotificationManagerService extends SystemService {
                }
            } else if (action.equals(Intent.ACTION_USER_PRESENT)) {
                // turn off LED when user passes through lock screen
                if (mNotificationLight != null) {
                    mNotificationLight.turnOff();
                }
            } else if (action.equals(Intent.ACTION_USER_SWITCHED)) {
                final int userId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, USER_NULL);
                mUserProfiles.updateCache(context);
@@ -4179,7 +4181,7 @@ public class NotificationManagerService extends SystemService {
        @Override
        public int getInterruptionFilterFromListener(INotificationListener token)
                throws RemoteException {
            synchronized (mNotificationLight) {
            synchronized (mNotificationLock) {
                return mInterruptionFilter;
            }
        }
@@ -6973,7 +6975,7 @@ public class NotificationManagerService extends SystemService {
        if (canShowLightsLocked(record, aboveThreshold)) {
            mLights.add(key);
            updateLightsLocked();
            if (mUseAttentionLight) {
            if (mUseAttentionLight && mAttentionLight != null) {
                mAttentionLight.pulse();
            }
            blink = true;
@@ -8171,6 +8173,10 @@ public class NotificationManagerService extends SystemService {
    @GuardedBy("mNotificationLock")
    void updateLightsLocked()
    {
        if (mNotificationLight == null) {
            return;
        }

        // handle notification lights
        NotificationRecord ledNotification = null;
        while (ledNotification == null && !mLights.isEmpty()) {
+3 −1
Original line number Diff line number Diff line
@@ -3496,8 +3496,10 @@ public final class PowerManagerService extends SystemService
        }

        // Control light outside of lock.
        if (light != null) {
            light.setFlashing(color, LogicalLight.LIGHT_FLASH_HARDWARE, (on ? 3 : 0), 0);
        }
    }

    private void setDozeAfterScreenOffInternal(boolean on) {
        synchronized (mLock) {