Add Lights AIDL HAL support to LightsService am: 4c5ac6b353

Change-Id: I7ca19b8364677533c2e38ed92b2284731530b2c2
This commit is contained in:
Automerger Merge Worker
2020-02-08 01:37:10 +00:00
2 changed files with 78 additions and 17 deletions

View File

@@ -43,6 +43,7 @@ java_library_static {
"android.hardware.broadcastradio-V2.0-java", "android.hardware.broadcastradio-V2.0-java",
"android.hardware.health-V1.0-java", "android.hardware.health-V1.0-java",
"android.hardware.health-V2.0-java", "android.hardware.health-V2.0-java",
"android.hardware.light-java",
"android.hardware.weaver-V1.0-java", "android.hardware.weaver-V1.0-java",
"android.hardware.biometrics.face-V1.0-java", "android.hardware.biometrics.face-V1.0-java",
"android.hardware.biometrics.fingerprint-V2.1-java", "android.hardware.biometrics.fingerprint-V2.1-java",

View File

@@ -17,10 +17,15 @@ package com.android.server.lights;
import android.app.ActivityManager; import android.app.ActivityManager;
import android.content.Context; import android.content.Context;
import android.hardware.light.HwLight;
import android.hardware.light.HwLightState;
import android.hardware.light.ILights;
import android.os.Handler; import android.os.Handler;
import android.os.IBinder; import android.os.IBinder;
import android.os.Message; import android.os.Message;
import android.os.PowerManager; import android.os.PowerManager;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.Trace; import android.os.Trace;
import android.provider.Settings; import android.provider.Settings;
import android.util.Slog; import android.util.Slog;
@@ -32,15 +37,16 @@ public class LightsService extends SystemService {
static final String TAG = "LightsService"; static final String TAG = "LightsService";
static final boolean DEBUG = false; static final boolean DEBUG = false;
final LightImpl mLights[] = new LightImpl[LightsManager.LIGHT_ID_COUNT]; private LightImpl[] mLights = null;
private ILights mVintfLights = null;
private final class LightImpl extends LogicalLight { private final class LightImpl extends LogicalLight {
private final IBinder mDisplayToken; private final IBinder mDisplayToken;
private final int mSurfaceControlMaximumBrightness; private final int mSurfaceControlMaximumBrightness;
private LightImpl(Context context, int id) { private LightImpl(Context context, HwLight hwLight) {
mId = id; mHwLight = hwLight;
mDisplayToken = SurfaceControl.getInternalDisplayToken(); mDisplayToken = SurfaceControl.getInternalDisplayToken();
final boolean brightnessSupport = SurfaceControl.getDisplayBrightnessSupport( final boolean brightnessSupport = SurfaceControl.getDisplayBrightnessSupport(
mDisplayToken); mDisplayToken);
@@ -67,8 +73,8 @@ public class LightsService extends SystemService {
synchronized (this) { synchronized (this) {
// LOW_PERSISTENCE cannot be manually set // LOW_PERSISTENCE cannot be manually set
if (brightnessMode == BRIGHTNESS_MODE_LOW_PERSISTENCE) { if (brightnessMode == BRIGHTNESS_MODE_LOW_PERSISTENCE) {
Slog.w(TAG, "setBrightness with LOW_PERSISTENCE unexpected #" + mId + Slog.w(TAG, "setBrightness with LOW_PERSISTENCE unexpected #" + mHwLight.id
": brightness=0x" + Integer.toHexString(brightness)); + ": brightness=0x" + Integer.toHexString(brightness));
return; return;
} }
// Ideally, we'd like to set the brightness mode through the SF/HWC as well, but // Ideally, we'd like to set the brightness mode through the SF/HWC as well, but
@@ -167,8 +173,10 @@ public class LightsService extends SystemService {
if (!mInitialized || color != mColor || mode != mMode || onMS != mOnMS || if (!mInitialized || color != mColor || mode != mMode || onMS != mOnMS ||
offMS != mOffMS || mBrightnessMode != brightnessMode) { offMS != mOffMS || mBrightnessMode != brightnessMode) {
if (DEBUG) Slog.v(TAG, "setLight #" + mId + ": color=#" if (DEBUG) {
+ Integer.toHexString(color) + ": brightnessMode=" + brightnessMode); Slog.v(TAG, "setLight #" + mHwLight.id + ": color=#"
+ Integer.toHexString(color) + ": brightnessMode=" + brightnessMode);
}
mInitialized = true; mInitialized = true;
mLastColor = mColor; mLastColor = mColor;
mColor = color; mColor = color;
@@ -176,10 +184,31 @@ public class LightsService extends SystemService {
mOnMS = onMS; mOnMS = onMS;
mOffMS = offMS; mOffMS = offMS;
mBrightnessMode = brightnessMode; mBrightnessMode = brightnessMode;
Trace.traceBegin(Trace.TRACE_TAG_POWER, "setLight(" + mId + ", 0x" setLightUnchecked(color, mode, onMS, offMS, brightnessMode);
+ Integer.toHexString(color) + ")"); }
}
private void setLightUnchecked(int color, int mode, int onMS, int offMS,
int brightnessMode) {
Trace.traceBegin(Trace.TRACE_TAG_POWER, "setLightState(" + mHwLight.id + ", 0x"
+ Integer.toHexString(color) + ")");
if (mVintfLights != null) {
HwLightState lightState = new HwLightState();
lightState.color = color;
lightState.flashMode = (byte) mode;
lightState.flashOnMs = onMS;
lightState.flashOffMs = offMS;
lightState.brightnessMode = (byte) brightnessMode;
try { try {
setLight_native(mId, color, mode, onMS, offMS, brightnessMode); 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);
} finally { } finally {
Trace.traceEnd(Trace.TRACE_TAG_POWER); Trace.traceEnd(Trace.TRACE_TAG_POWER);
} }
@@ -190,7 +219,7 @@ public class LightsService extends SystemService {
return mVrModeEnabled && mUseLowPersistenceForVR; return mVrModeEnabled && mUseLowPersistenceForVR;
} }
private int mId; private HwLight mHwLight;
private int mColor; private int mColor;
private int mMode; private int mMode;
private int mOnMS; private int mOnMS;
@@ -207,8 +236,39 @@ public class LightsService extends SystemService {
public LightsService(Context context) { public LightsService(Context context) {
super(context); super(context);
for (int i = 0; i < LightsManager.LIGHT_ID_COUNT; i++) { IBinder service = ServiceManager.getService("android.hardware.light.ILights/default");
mLights[i] = new LightImpl(context, i); mVintfLights = ILights.Stub.asInterface(service);
populateAvailableLights(context);
}
private void populateAvailableLights(Context context) {
mLights = new LightImpl[LightsManager.LIGHT_ID_COUNT];
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;
}
}
} 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);
}
} }
} }
@@ -231,9 +291,9 @@ public class LightsService extends SystemService {
private final LightsManager mService = new LightsManager() { private final LightsManager mService = new LightsManager() {
@Override @Override
public LogicalLight getLight(int id) { public LogicalLight getLight(int lightType) {
if (0 <= id && id < LIGHT_ID_COUNT) { if (mLights != null && 0 <= lightType && lightType < LIGHT_ID_COUNT) {
return mLights[id]; return mLights[lightType];
} else { } else {
return null; return null;
} }