Loading services/core/java/com/android/server/BatteryService.java +3 −0 Original line number Diff line number Diff line Loading @@ -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) { Loading services/core/java/com/android/server/display/LocalDisplayAdapter.java +6 −2 Original line number Diff line number Diff line Loading @@ -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) { Loading Loading @@ -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( Loading services/core/java/com/android/server/lights/LightsManager.java +3 −1 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package com.android.server.lights; import android.annotation.Nullable; import android.hardware.light.V2_0.Type; public abstract class LightsManager { Loading @@ -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); } services/core/java/com/android/server/lights/LightsService.java +58 −68 Original line number Diff line number Diff line Loading @@ -52,8 +52,8 @@ public class LightsService extends SystemService { static final String TAG = "LightsService"; static final boolean DEBUG = false; private LightImpl[] mLights = null; private SparseArray<LightImpl> mLightsById = null; private final LightImpl[] mLightsByType = new LightImpl[LightsManager.LIGHT_ID_COUNT]; private final SparseArray<LightImpl> mLightsById = new SparseArray<>(); private ILights mVintfLights = null; Loading Loading @@ -96,8 +96,8 @@ public class LightsService extends SystemService { synchronized (LightsService.this) { final List<Light> lights = new ArrayList<Light>(); for (int i = 0; i < mLightsById.size(); i++) { HwLight hwLight = mLightsById.valueAt(i).getHwLight(); if (!isSystemLight(hwLight)) { if (!mLightsById.valueAt(i).isSystemLight()) { HwLight hwLight = mLightsById.valueAt(i).mHwLight; lights.add(new Light(hwLight.id, hwLight.ordinal, hwLight.type)); } } Loading Loading @@ -138,7 +138,7 @@ public class LightsService extends SystemService { synchronized (LightsService.this) { final LightImpl light = mLightsById.get(lightId); if (light == null || isSystemLight(light.getHwLight())) { if (light == null || light.isSystemLight()) { throw new IllegalArgumentException("Invalid light: " + lightId); } return new LightState(light.getColor()); Loading Loading @@ -184,9 +184,8 @@ public class LightsService extends SystemService { private void checkRequestIsValid(int[] lightIds) { for (int i = 0; i < lightIds.length; i++) { final LightImpl light = mLightsById.get(lightIds[i]); final HwLight hwLight = light.getHwLight(); Preconditions.checkState(light != null && !isSystemLight(hwLight), "invalid lightId " + hwLight.id); Preconditions.checkState(light != null && !light.isSystemLight(), "Invalid lightId " + lightIds[i]); } } Loading @@ -205,9 +204,8 @@ public class LightsService extends SystemService { } for (int i = 0; i < mLightsById.size(); i++) { LightImpl light = mLightsById.valueAt(i); HwLight hwLight = light.getHwLight(); if (!isSystemLight(hwLight)) { LightState state = states.get(hwLight.id); if (!light.isSystemLight()) { LightState state = states.get(light.mHwLight.id); if (state != null) { light.setColor(state.getColor()); } else { Loading Loading @@ -385,6 +383,7 @@ public class LightsService extends SystemService { int brightnessMode) { Trace.traceBegin(Trace.TRACE_TAG_POWER, "setLightState(" + mHwLight.id + ", 0x" + Integer.toHexString(color) + ")"); try { if (mVintfLights != null) { HwLightState lightState = new HwLightState(); lightState.color = color; Loading @@ -392,28 +391,29 @@ public class LightsService extends SystemService { lightState.flashOnMs = onMS; lightState.flashOffMs = offMS; lightState.brightnessMode = (byte) brightnessMode; try { mVintfLights.setLightState(mHwLight.id, lightState); } catch (RemoteException | UnsupportedOperationException ex) { Slog.e(TAG, "Failed issuing setLightState", ex); } finally { Trace.traceEnd(Trace.TRACE_TAG_POWER); } } else { try { setLight_native(mHwLight.id, color, mode, onMS, offMS, brightnessMode); } } catch (RemoteException | UnsupportedOperationException ex) { Slog.e(TAG, "Failed issuing setLightState", ex); } finally { Trace.traceEnd(Trace.TRACE_TAG_POWER); } } } private boolean shouldBeInLowPersistenceMode() { return mVrModeEnabled && mUseLowPersistenceForVR; } private HwLight getHwLight() { return mHwLight; /** * Returns whether a light is system-use-only or should be accessible to * applications using the {@link android.hardware.lights.LightsManager} API. */ private boolean isSystemLight() { // LIGHT_ID_COUNT comes from the 2.0 HIDL HAL and only contains system lights. // Newly-added lights are made available via the public LightsManager API. return (0 <= mHwLight.type && mHwLight.type < LightsManager.LIGHT_ID_COUNT); } private int getColor() { Loading Loading @@ -451,37 +451,38 @@ public class LightsService extends SystemService { } private void populateAvailableLights(Context context) { mLights = new LightImpl[LightsManager.LIGHT_ID_COUNT]; mLightsById = new SparseArray<>(); if (mVintfLights != null) { try { for (HwLight availableLight : mVintfLights.getLights()) { LightImpl light = new LightImpl(context, availableLight); int type = (int) availableLight.type; if (0 <= type && type < mLights.length && mLights[type] == null) { mLights[type] = light; populateAvailableLightsFromAidl(context); } else { populateAvailableLightsFromHidl(context); } mLightsById.put(availableLight.id, light); for (int i = mLightsById.size() - 1; i >= 0; i--) { final int type = mLightsById.keyAt(i); if (0 <= type && type < mLightsByType.length) { mLightsByType[type] = mLightsById.valueAt(i); } } catch (RemoteException ex) { Slog.e(TAG, "Unable to get lights for initialization", ex); } } // In the case where only the old HAL is available, all lights will be initialized here for (int i = 0; i < mLights.length; i++) { if (mLights[i] == null) { // The ordinal can be anything if there is only 1 light of each type. Set it to 1. HwLight light = new HwLight(); light.id = (byte) i; light.ordinal = 1; light.type = (byte) i; mLights[i] = new LightImpl(context, light); mLightsById.put(i, mLights[i]); private void populateAvailableLightsFromAidl(Context context) { try { for (HwLight hwLight : mVintfLights.getLights()) { mLightsById.put(hwLight.id, new LightImpl(context, hwLight)); } } catch (RemoteException ex) { Slog.e(TAG, "Unable to get lights from HAL", ex); } } private void populateAvailableLightsFromHidl(Context context) { for (int i = 0; i < mLightsByType.length; i++) { HwLight hwLight = new HwLight(); hwLight.id = (byte) i; hwLight.ordinal = 1; hwLight.type = (byte) i; mLightsById.put(hwLight.id, new LightImpl(context, hwLight)); } } @Override Loading @@ -505,25 +506,14 @@ public class LightsService extends SystemService { private final LightsManager mService = new LightsManager() { @Override public LogicalLight getLight(int lightType) { if (mLights != null && 0 <= lightType && lightType < mLights.length) { return mLights[lightType]; if (mLightsByType != null && 0 <= lightType && lightType < mLightsByType.length) { return mLightsByType[lightType]; } else { return null; } } }; /** * Returns whether a light is system-use-only or should be accessible to * applications using the {@link android.hardware.lights.LightsManager} API. */ private static boolean isSystemLight(HwLight light) { // LIGHT_ID_COUNT comes from the 2.0 HIDL HAL and only contains system // lights. Newly added lights will be made available via the // LightsManager API. return 0 <= light.type && light.type < LightsManager.LIGHT_ID_COUNT; } static native void setLight_native(int light, int color, int mode, int onMS, int offMS, int brightnessMode); } services/core/java/com/android/server/notification/NotificationManagerService.java +9 −3 Original line number Diff line number Diff line Loading @@ -1579,7 +1579,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); Loading Loading @@ -4193,7 +4195,7 @@ public class NotificationManagerService extends SystemService { @Override public int getInterruptionFilterFromListener(INotificationListener token) throws RemoteException { synchronized (mNotificationLight) { synchronized (mNotificationLock) { return mInterruptionFilter; } } Loading Loading @@ -6773,7 +6775,7 @@ public class NotificationManagerService extends SystemService { if (canShowLightsLocked(record, aboveThreshold)) { mLights.add(key); updateLightsLocked(); if (mUseAttentionLight) { if (mUseAttentionLight && mAttentionLight != null) { mAttentionLight.pulse(); } blink = true; Loading Loading @@ -7974,6 +7976,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()) { Loading Loading
services/core/java/com/android/server/BatteryService.java +3 −0 Original line number Diff line number Diff line Loading @@ -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) { Loading
services/core/java/com/android/server/display/LocalDisplayAdapter.java +6 −2 Original line number Diff line number Diff line Loading @@ -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) { Loading Loading @@ -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( Loading
services/core/java/com/android/server/lights/LightsManager.java +3 −1 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package com.android.server.lights; import android.annotation.Nullable; import android.hardware.light.V2_0.Type; public abstract class LightsManager { Loading @@ -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); }
services/core/java/com/android/server/lights/LightsService.java +58 −68 Original line number Diff line number Diff line Loading @@ -52,8 +52,8 @@ public class LightsService extends SystemService { static final String TAG = "LightsService"; static final boolean DEBUG = false; private LightImpl[] mLights = null; private SparseArray<LightImpl> mLightsById = null; private final LightImpl[] mLightsByType = new LightImpl[LightsManager.LIGHT_ID_COUNT]; private final SparseArray<LightImpl> mLightsById = new SparseArray<>(); private ILights mVintfLights = null; Loading Loading @@ -96,8 +96,8 @@ public class LightsService extends SystemService { synchronized (LightsService.this) { final List<Light> lights = new ArrayList<Light>(); for (int i = 0; i < mLightsById.size(); i++) { HwLight hwLight = mLightsById.valueAt(i).getHwLight(); if (!isSystemLight(hwLight)) { if (!mLightsById.valueAt(i).isSystemLight()) { HwLight hwLight = mLightsById.valueAt(i).mHwLight; lights.add(new Light(hwLight.id, hwLight.ordinal, hwLight.type)); } } Loading Loading @@ -138,7 +138,7 @@ public class LightsService extends SystemService { synchronized (LightsService.this) { final LightImpl light = mLightsById.get(lightId); if (light == null || isSystemLight(light.getHwLight())) { if (light == null || light.isSystemLight()) { throw new IllegalArgumentException("Invalid light: " + lightId); } return new LightState(light.getColor()); Loading Loading @@ -184,9 +184,8 @@ public class LightsService extends SystemService { private void checkRequestIsValid(int[] lightIds) { for (int i = 0; i < lightIds.length; i++) { final LightImpl light = mLightsById.get(lightIds[i]); final HwLight hwLight = light.getHwLight(); Preconditions.checkState(light != null && !isSystemLight(hwLight), "invalid lightId " + hwLight.id); Preconditions.checkState(light != null && !light.isSystemLight(), "Invalid lightId " + lightIds[i]); } } Loading @@ -205,9 +204,8 @@ public class LightsService extends SystemService { } for (int i = 0; i < mLightsById.size(); i++) { LightImpl light = mLightsById.valueAt(i); HwLight hwLight = light.getHwLight(); if (!isSystemLight(hwLight)) { LightState state = states.get(hwLight.id); if (!light.isSystemLight()) { LightState state = states.get(light.mHwLight.id); if (state != null) { light.setColor(state.getColor()); } else { Loading Loading @@ -385,6 +383,7 @@ public class LightsService extends SystemService { int brightnessMode) { Trace.traceBegin(Trace.TRACE_TAG_POWER, "setLightState(" + mHwLight.id + ", 0x" + Integer.toHexString(color) + ")"); try { if (mVintfLights != null) { HwLightState lightState = new HwLightState(); lightState.color = color; Loading @@ -392,28 +391,29 @@ public class LightsService extends SystemService { lightState.flashOnMs = onMS; lightState.flashOffMs = offMS; lightState.brightnessMode = (byte) brightnessMode; try { mVintfLights.setLightState(mHwLight.id, lightState); } catch (RemoteException | UnsupportedOperationException ex) { Slog.e(TAG, "Failed issuing setLightState", ex); } finally { Trace.traceEnd(Trace.TRACE_TAG_POWER); } } else { try { setLight_native(mHwLight.id, color, mode, onMS, offMS, brightnessMode); } } catch (RemoteException | UnsupportedOperationException ex) { Slog.e(TAG, "Failed issuing setLightState", ex); } finally { Trace.traceEnd(Trace.TRACE_TAG_POWER); } } } private boolean shouldBeInLowPersistenceMode() { return mVrModeEnabled && mUseLowPersistenceForVR; } private HwLight getHwLight() { return mHwLight; /** * Returns whether a light is system-use-only or should be accessible to * applications using the {@link android.hardware.lights.LightsManager} API. */ private boolean isSystemLight() { // LIGHT_ID_COUNT comes from the 2.0 HIDL HAL and only contains system lights. // Newly-added lights are made available via the public LightsManager API. return (0 <= mHwLight.type && mHwLight.type < LightsManager.LIGHT_ID_COUNT); } private int getColor() { Loading Loading @@ -451,37 +451,38 @@ public class LightsService extends SystemService { } private void populateAvailableLights(Context context) { mLights = new LightImpl[LightsManager.LIGHT_ID_COUNT]; mLightsById = new SparseArray<>(); if (mVintfLights != null) { try { for (HwLight availableLight : mVintfLights.getLights()) { LightImpl light = new LightImpl(context, availableLight); int type = (int) availableLight.type; if (0 <= type && type < mLights.length && mLights[type] == null) { mLights[type] = light; populateAvailableLightsFromAidl(context); } else { populateAvailableLightsFromHidl(context); } mLightsById.put(availableLight.id, light); for (int i = mLightsById.size() - 1; i >= 0; i--) { final int type = mLightsById.keyAt(i); if (0 <= type && type < mLightsByType.length) { mLightsByType[type] = mLightsById.valueAt(i); } } catch (RemoteException ex) { Slog.e(TAG, "Unable to get lights for initialization", ex); } } // In the case where only the old HAL is available, all lights will be initialized here for (int i = 0; i < mLights.length; i++) { if (mLights[i] == null) { // The ordinal can be anything if there is only 1 light of each type. Set it to 1. HwLight light = new HwLight(); light.id = (byte) i; light.ordinal = 1; light.type = (byte) i; mLights[i] = new LightImpl(context, light); mLightsById.put(i, mLights[i]); private void populateAvailableLightsFromAidl(Context context) { try { for (HwLight hwLight : mVintfLights.getLights()) { mLightsById.put(hwLight.id, new LightImpl(context, hwLight)); } } catch (RemoteException ex) { Slog.e(TAG, "Unable to get lights from HAL", ex); } } private void populateAvailableLightsFromHidl(Context context) { for (int i = 0; i < mLightsByType.length; i++) { HwLight hwLight = new HwLight(); hwLight.id = (byte) i; hwLight.ordinal = 1; hwLight.type = (byte) i; mLightsById.put(hwLight.id, new LightImpl(context, hwLight)); } } @Override Loading @@ -505,25 +506,14 @@ public class LightsService extends SystemService { private final LightsManager mService = new LightsManager() { @Override public LogicalLight getLight(int lightType) { if (mLights != null && 0 <= lightType && lightType < mLights.length) { return mLights[lightType]; if (mLightsByType != null && 0 <= lightType && lightType < mLightsByType.length) { return mLightsByType[lightType]; } else { return null; } } }; /** * Returns whether a light is system-use-only or should be accessible to * applications using the {@link android.hardware.lights.LightsManager} API. */ private static boolean isSystemLight(HwLight light) { // LIGHT_ID_COUNT comes from the 2.0 HIDL HAL and only contains system // lights. Newly added lights will be made available via the // LightsManager API. return 0 <= light.type && light.type < LightsManager.LIGHT_ID_COUNT; } static native void setLight_native(int light, int color, int mode, int onMS, int offMS, int brightnessMode); }
services/core/java/com/android/server/notification/NotificationManagerService.java +9 −3 Original line number Diff line number Diff line Loading @@ -1579,7 +1579,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); Loading Loading @@ -4193,7 +4195,7 @@ public class NotificationManagerService extends SystemService { @Override public int getInterruptionFilterFromListener(INotificationListener token) throws RemoteException { synchronized (mNotificationLight) { synchronized (mNotificationLock) { return mInterruptionFilter; } } Loading Loading @@ -6773,7 +6775,7 @@ public class NotificationManagerService extends SystemService { if (canShowLightsLocked(record, aboveThreshold)) { mLights.add(key); updateLightsLocked(); if (mUseAttentionLight) { if (mUseAttentionLight && mAttentionLight != null) { mAttentionLight.pulse(); } blink = true; Loading Loading @@ -7974,6 +7976,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()) { Loading