marble: fix auto brightness after screen turn on

After the screen has been off for a long time, when the screen is turned on, auto brightness is very slow to restore from 0.
I sensors-hal: handle_sns_std_sensor_event:65, light_event: ts=763376097432, lux: 0.0, extra_info=0
or when the screen is on
I DisplayPowerController[0]: BrightnessEvent: brt=0.0011033387 (8.0%), nits= 3.1000004, lux=0.0, reason=automatic

adb logcat | grep " lux"

added LightNotifier logic from https://github.com/LineageOS/android_device_xiaomi_sm8450-common/blob/lineage-22.2/sensors/sensor-n
otifier/notifiers/LightNotifier.cpp
This commit is contained in:
Alex Yustasov
2025-06-02 09:35:13 +03:00
committed by Joey
parent 92a0a0c526
commit b1e239ad04
2 changed files with 71 additions and 28 deletions

View File

@@ -47,7 +47,8 @@ class RawLightSensorCallback : public IEventQueueCallback {
} // namespace
RawLightNotifier::RawLightNotifier(sp<ISensorManager> manager) : SensorNotifier(manager) {
RawLightNotifier::RawLightNotifier(sp<ISensorManager> manager) : SensorNotifier(manager),
isEnable(false) {
initializeSensorQueue("xiaomi.sensor.ambientlight.factory", false,
new RawLightSensorCallback());
}
@@ -69,20 +70,30 @@ void RawLightNotifier::notify() {
res = mQueue->enableSensor(mSensorHandle, 20000 /* sample period */, 0 /* latency */);
if (res != Result::OK) {
LOG(ERROR) << "failed to enable sensor";
}
} else isEnable = true;
// Register for power events
disp_event_req req;
req.base.flag = 0;
req.base.disp_id = MI_DISP_PRIMARY;
req.type = MI_DISP_EVENT_POWER;
ioctl(disp_fd_.get(), MI_DISP_IOCTL_REGISTER_EVENT, &req);
const std::vector<disp_event_type> notifyEvents = {MI_DISP_EVENT_POWER, MI_DISP_EVENT_FPS,
MI_DISP_EVENT_51_BRIGHTNESS,
MI_DISP_EVENT_HBM, MI_DISP_EVENT_DC};
for (const disp_event_type& event : notifyEvents) {
disp_event_req req;
req.base.flag = 0;
req.base.disp_id = MI_DISP_PRIMARY;
req.type = event;
ioctl(disp_fd_.get(), MI_DISP_IOCTL_REGISTER_EVENT, &req);
}
struct pollfd dispEventPoll = {
.fd = disp_fd_.get(),
.events = POLLIN,
};
_oem_msg* msg = new _oem_msg;
notify_t notifyType;
float value;
while (mActive) {
int rc = poll(&dispEventPoll, 1, -1);
if (rc < 0) {
@@ -95,28 +106,58 @@ void RawLightNotifier::notify() {
continue;
}
if (response->base.type != MI_DISP_EVENT_POWER) {
LOG(ERROR) << "unexpected display event: " << response->base.type;
continue;
if (response->base.type == MI_DISP_EVENT_POWER) {
notifyType = POWER_STATE;
value = response->data[0];
switch (response->data[0]) {
case MI_DISP_POWER_ON:
if (!isEnable) {
res = mQueue->enableSensor(mSensorHandle, 20000 /* sample period */,
0 /* latency */);
if (res != Result::OK) {
LOG(ERROR) << "failed to enable sensor";
} else isEnable = true;
}
break;
default:
if (isEnable) {
res = mQueue->disableSensor(mSensorHandle);
if (res != Result::OK) {
LOG(ERROR) << "failed to disable sensor";
} else isEnable = false;
}
break;
}
} else {
switch (response->base.type) {
case MI_DISP_EVENT_FPS:
notifyType = DISPLAY_FREQUENCY;
value = response->data[0];
break;
case MI_DISP_EVENT_51_BRIGHTNESS:
notifyType = BRIGHTNESS;
value = *(uint16_t*)response->data;
break;
case MI_DISP_EVENT_HBM:
notifyType = BRIGHTNESS;
value = response->data[0] ? -1 : -2;
break;
case MI_DISP_EVENT_DC:
notifyType = DC_STATE;
value = response->data[0];
break;
default:
LOG(ERROR) << "got unknown event: " << response->base.type;
continue;
}
}
msg->sensorType = kSensorTypeAmbientlightRaw;
msg->notifyType = notifyType;
msg->notifyTypeFloat = notifyType;
msg->value = value;
msg->unknown1 = 1;
msg->unknown2 = 5;
int value = response->data[0];
LOG(VERBOSE) << "received data: " << std::bitset<8>(value);
switch (response->data[0]) {
case MI_DISP_POWER_ON:
res = mQueue->enableSensor(mSensorHandle, 20000 /* sample period */,
0 /* latency */);
if (res != Result::OK) {
LOG(ERROR) << "failed to enable sensor";
}
break;
default:
res = mQueue->disableSensor(mSensorHandle);
if (res != Result::OK) {
LOG(ERROR) << "failed to disable sensor";
}
break;
}
SscCalApiWrapper::getInstance().processMsg(msg);
}
}

View File

@@ -15,4 +15,6 @@ class RawLightNotifier : public SensorNotifier {
protected:
void notify();
bool isEnable;
};