Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save adithya2306/ff2462ff56dd46406c7b3c24a8a93ac2 to your computer and use it in GitHub Desktop.
Save adithya2306/ff2462ff56dd46406c7b3c24a8a93ac2 to your computer and use it in GitHub Desktop.
AutomaticBrightnessControllerImpl from MIUI 13 (lisa)
package com.android.server.display;
import android.content.Context;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.hardware.camera2.CameraManager;
import android.os.Handler;
import android.os.PowerManager;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.SystemClock;
import android.os.SystemProperties;
import android.util.MathUtils;
import android.util.Slog;
import android.util.Spline;
import android.view.IRotationWatcher;
import android.view.IWindowManager;
import com.android.internal.display.BrightnessSynchronizer;
import com.android.server.magicwin.MiuiMagicWinAnimation;
import java.io.PrintWriter;
import miui.os.Build;
import miui.os.DeviceFeature;
import miui.util.FeatureParser;
/* loaded from: classes.dex */
public class AutomaticBrightnessControllerImpl extends AutomaticBrightnessControllerStub {
private static final int ALS_FOV;
private static final float ASSISTSENSOR_BRIGHTENINGRATIO = 2.0f;
private static final float ASSISTSENSOR_BRIGHTENING_MINTHRES = 5.0f;
private static final float ASSISTSENSOR_DARKENINGRATIO = 0.2f;
private static final float ASSISTSENSOR_DATA_THRESHOLD;
private static final long ASSISTSENSOR_DEBOUNCETIME = 10000;
private static final float ASSISTSENSOR_MAXTHRES;
private static final int ASSIST_SENSOR_TYPE = 33171055;
private static final int AUTOBRIGHTNESS_RATE_SLOW;
private static final String AUTO_BRIGHTNESS_DEBUG = "sys.sensor.autobacklight.dbg";
private static final int BRIGHTNESS_12BIT = 4095;
private static final float BRIGHTNESS_DARK;
private static final float BRIGHTNESS_DARK_RAMPRATE;
private static final int BRIGHTNESS_IN_BRIGHTENING = 2;
private static final int BRIGHTNESS_IN_DARKENING = 1;
private static final int BRIGHTNESS_IN_STABLE = 0;
private static final boolean BRIGHTNESS_RATE_ADJUSTIBLE;
private static final float DARKENING_HYSTERESIS_FOVTOSEVENTY;
private static final float DARKENING_HYSTERESIS_SEVENTYTONINETY;
private static final float DARKENING_HYSTERESIS_ZEROTOFOV;
private static boolean DEBUG = false;
private static final int DYNAMIC_DARKENING_DEBOUNCE1;
private static final int DYNAMIC_DARKENING_DEBOUNCE2;
private static final int DYNAMIC_DARKENING_DEFAULTDEBOUNCE;
private static final float DYNAMIC_DARKENING_LUXTHRESHOLD;
private static final float HBM_BRIGHTENING_DEBOUNCE;
private static final float HBM_BRIGHTENING_LUX;
private static final float HBM_BRIGHTENING_THRES;
private static final int HBM_BRIGHTNESS_ON;
private static final float HBM_BRIGHTNESS_ON_FLOAT;
private static final float HBM_DARKENING_DEBOUNCE;
private static final float HBM_DARKENING_LUX;
private static final float HBM_DARKENING_THRES;
private static final float HBM_MAX_NIT;
private static final float HBM_START_LUX;
private static final boolean HBM_SUPPORT_DIMMING;
private static final float HIGHANGLE_THRESHOLD;
private static final int HIGHEST_LUX = 8000;
private static final boolean IS_UMI_0B_DISPLAY_PANEL;
private static final float MOTIONSENSOR_STATIC_LUXTHRESHOLD;
private static final int MOTIONSENSOR_TYPE = 33171039;
private static final int MOTION_MOVE = 1;
private static final int MOTION_STATIC = 2;
private static final int MOTION_STATIC_ROTATE = 3;
private static final int MSG_ROTATION_CHANGE = 1001;
private static final int MSG_ROTATION_CHANGE_DURATION_MILLIS = 30;
private static final float NIT_LEVEL = 40.0f;
private static final float NIT_LEVEL1 = 35.0f;
private static final float NIT_LEVEL2 = 87.450005f;
private static final float NIT_LEVEL3 = 265.0f;
private static final int NORMAL_BRIGHTNESS_ON;
private static final String OLED_PANEL_ID;
private static final int PROXIMITY_NEGATIVE = 0;
private static final int PROXIMITY_POSITIVE = 1;
private static final int PROXIMITY_UNKNOWN = -1;
private static final int RATE_LEVEL = 40;
private static final int SENSOR_TYPE_LIGHT_SECONDARY = 33171081;
private static final int SKIP_DEBOUNCE;
private static final boolean SKIP_DEBOUNCE_ENABLED;
private static final float SKIP_LUX_DEBOUNCE1;
private static final float SKIP_LUX_DEBOUNCE2;
private static final int SLOW_RATIO;
private static final boolean SMD_EFFECT_STATUS;
private static final boolean SUPPORT_HBM;
private static final String TAG = "AutomaticBrightnessControllerImpl";
private static final float TIME_1 = 0.0f;
private static final float TIME_2 = 0.8f;
private static final float TIME_3 = 1.8f;
private static final float TIME_4 = 4.0f;
private static final float TIME_5 = 24.0f;
private static final int TORCHCLOSEDELAY = 1000;
private static final float TYPICAL_PROXIMITY_THRESHOLD = 5.0f;
private static final boolean USE_ACCELEROMETER_ENABLED;
private static final boolean USE_ASSISTSENSOR_ENABLED;
private static final boolean USE_DAEMON_SENSOR_POLICY;
private static final boolean USE_DYNAMIC_DEBOUNCE;
private static final boolean USE_FOLD_ENABLED;
private static final boolean USE_MOTIONSENSOR_ENABLED;
private static final boolean USE_PROXIMITY_ENABLED;
private static final boolean WAIT_FOR_AUTOBRIGHTNESS;
private static final int WAIT_TIME;
private static final float[] mALevels;
private static final float[] mBLevels;
private static final float[] mNitsLevels;
private static final float[] sHbmLuxLevels;
private Spline HBM_AUTO_BRIGHTNESS_SPLINE;
private Spline HBM_NITTOBACKLIGHT_SPLINE;
private Sensor mAccelerometer;
private Sensor mAssistSensor;
private CameraManager mCameraManager;
private Context mContext;
public DaemonSensorPolicy mDaemonSensorPolicy;
private boolean mHDRState;
private Handler mHandler;
public boolean mIsAutoBrightnessByApplicationAnimationEnable;
private boolean mIsAutoBrightnessByApplicationRateEnable;
private boolean mLastHdrState;
private float mMaxNitsProperty;
private Sensor mMotionSensor;
private boolean mNeedBrightening;
private Sensor mProximitySensor;
private float mProximityThreshold;
private float mRealLux;
private RotationWatcher mRotationWatcher;
private boolean mRotationWatcherOn;
private SensorManager mSensorManager;
private float mStableLux;
private IWindowManager mWindowManager;
private int mProximity = -1;
private boolean mProximitySensorEnabled = false;
private float mAngleXYToHorizon = MiuiMagicWinAnimation.INVALID_THRESHOLD;
private boolean mAccSensorEnabled = false;
private boolean mAmbientLuxFirstEvent = false;
private boolean mSlowChange = false;
private float mStartBrightness = -1.0f;
private boolean mAutomaticBrightnessEnable = false;
private float mFirstLux = -1.0f;
private float mLastLux = -1.0f;
private int mBrightnessStatus = 0;
private boolean mMotionSensorEnabled = false;
private int mMotionStatus = 1;
private boolean mAssistSensorEnabled = false;
private float mAssistSensorData = -1.0f;
private float mAssistDarkeningThres = -1.0f;
private float mAssistBrighteningThres = -1.0f;
private long mAssistSensorTime = -1;
private float mCurrentLux = -1.0f;
private long mDynamicEnvStartTime = 0;
private boolean mIsTorchOpen = false;
private long mTorchCloseTime = 0;
private long mHbmEnterStartTs = 0;
private long mHbmExitStartTs = 0;
private boolean mHbmStatus = false;
private float mSpeedingRatio = MiuiMagicWinAnimation.INVALID_THRESHOLD;
private float mLastSettingBrightness = Float.NaN;
private float mBrighteningRatio = Resources.getSystem().getFloat(285671463);
private boolean mSupportHdr = Resources.getSystem().getBoolean(285540416);
private int mRotation = 0;
private Sensor mSecLightSensor = null;
private final boolean IS_SUPPORT_AUTOBRIGHTNESS_BY_APPLICATION_CATEGORY = FeatureParser.getBoolean("support_autobrightness_by_application_category", false);
private final boolean IS_INTERNAL_BUILD = Build.IS_INTERNATIONAL_BUILD;
private final float SLOW_RATE_TIME = 10.0f;
private final float FAST_RATE_TIME = 5.0f;
private final float AUTOBRIGHTNESS_BY_APPLICATION_MIN_RATE = 0.01f;
private float mAutoBrightnessByApplicationRate = MiuiMagicWinAnimation.INVALID_THRESHOLD;
private final CameraManager.TorchCallback mTorchCallback = new CameraManager.TorchCallback() { // from class: com.android.server.display.AutomaticBrightnessControllerImpl.1
@Override // android.hardware.camera2.CameraManager.TorchCallback
public void onTorchModeUnavailable(String cameraId) {
AutomaticBrightnessControllerImpl.this.mIsTorchOpen = true;
}
@Override // android.hardware.camera2.CameraManager.TorchCallback
public void onTorchModeChanged(String cameraId, boolean enabled) {
if (enabled) {
AutomaticBrightnessControllerImpl.this.mIsTorchOpen = true;
return;
}
if (AutomaticBrightnessControllerImpl.this.mIsTorchOpen) {
AutomaticBrightnessControllerImpl.this.mTorchCloseTime = System.currentTimeMillis();
}
AutomaticBrightnessControllerImpl.this.mIsTorchOpen = false;
}
};
private SensorEventListener mSensorListener = new SensorEventListener() { // from class: com.android.server.display.AutomaticBrightnessControllerImpl.2
@Override // android.hardware.SensorEventListener
public void onSensorChanged(SensorEvent event) {
switch (event.sensor.getType()) {
case 1:
AutomaticBrightnessControllerImpl.this.onAccelerometerSensorChanged(event);
return;
case 8:
AutomaticBrightnessControllerImpl.this.onProximitySensorChanged(event);
return;
case AutomaticBrightnessControllerImpl.MOTIONSENSOR_TYPE /* 33171039 */:
AutomaticBrightnessControllerImpl.this.onMotionSensorChanged(event);
return;
case AutomaticBrightnessControllerImpl.ASSIST_SENSOR_TYPE /* 33171055 */:
AutomaticBrightnessControllerImpl.this.onAssistSensorChanged(event);
return;
default:
return;
}
}
@Override // android.hardware.SensorEventListener
public void onAccuracyChanged(Sensor sensor, int accuracy) {
}
};
static {
USE_PROXIMITY_ENABLED = Resources.getSystem().getBoolean(285540374) && !DeviceFeature.hasSupportAudioPromity();
USE_ACCELEROMETER_ENABLED = Resources.getSystem().getBoolean(285540369);
SKIP_DEBOUNCE_ENABLED = Resources.getSystem().getBoolean(285540375);
SKIP_DEBOUNCE = Resources.getSystem().getInteger(285933596);
SKIP_LUX_DEBOUNCE1 = Resources.getSystem().getInteger(285933627);
SKIP_LUX_DEBOUNCE2 = Resources.getSystem().getInteger(285933628);
DARKENING_HYSTERESIS_ZEROTOFOV = Resources.getSystem().getInteger(285933637) / 10.0f;
DARKENING_HYSTERESIS_FOVTOSEVENTY = Resources.getSystem().getInteger(285933604) / 10.0f;
DARKENING_HYSTERESIS_SEVENTYTONINETY = Resources.getSystem().getInteger(285933625) / 10.0f;
ALS_FOV = Resources.getSystem().getInteger(285933594);
HIGHANGLE_THRESHOLD = Resources.getSystem().getInteger(285933595);
SLOW_RATIO = Resources.getSystem().getInteger(285933631);
WAIT_FOR_AUTOBRIGHTNESS = Resources.getSystem().getBoolean(285540420);
WAIT_TIME = Resources.getSystem().getInteger(285933636);
String str = SystemProperties.get("ro.boot.oled_panel_id", "");
OLED_PANEL_ID = str;
IS_UMI_0B_DISPLAY_PANEL = "0B".equals(str) && ("umi".equals(android.os.Build.DEVICE) || "umiin".equals(android.os.Build.DEVICE));
ASSISTSENSOR_MAXTHRES = Resources.getSystem().getInteger(285933576);
USE_DYNAMIC_DEBOUNCE = Resources.getSystem().getBoolean(285540371);
USE_MOTIONSENSOR_ENABLED = Resources.getSystem().getBoolean(285540373);
USE_ASSISTSENSOR_ENABLED = Resources.getSystem().getBoolean(285540370);
DYNAMIC_DARKENING_DEBOUNCE1 = Resources.getSystem().getInteger(285933602);
DYNAMIC_DARKENING_DEBOUNCE2 = Resources.getSystem().getInteger(285933603);
SMD_EFFECT_STATUS = Resources.getSystem().getBoolean(285540413);
DYNAMIC_DARKENING_DEFAULTDEBOUNCE = Resources.getSystem().getInteger(285933600);
ASSISTSENSOR_DATA_THRESHOLD = Resources.getSystem().getInteger(285933577);
MOTIONSENSOR_STATIC_LUXTHRESHOLD = Resources.getSystem().getInteger(285933615);
DYNAMIC_DARKENING_LUXTHRESHOLD = Resources.getSystem().getInteger(285933601);
AUTOBRIGHTNESS_RATE_SLOW = Resources.getSystem().getInteger(285933578);
BRIGHTNESS_RATE_ADJUSTIBLE = Resources.getSystem().getBoolean(285540366);
BRIGHTNESS_DARK = Resources.getSystem().getInteger(285933580) / 1000.0f;
BRIGHTNESS_DARK_RAMPRATE = Resources.getSystem().getInteger(285933581) / 1000.0f;
mNitsLevels = new float[]{800.0f, 251.0f, 150.0f, 100.0f, 70.0f, 50.0f, NIT_LEVEL, 30.0f, 28.5f};
mALevels = new float[]{800.0f, 569.48f, 344.89f, 237.75f, 179.71f, 135.19f, 113.59f, 62.84f, 676.87f};
mBLevels = new float[]{0.9887f, 0.992f, 0.995f, 0.9965f, 0.9973f, 0.9979f, 0.9982f, 0.999f, 0.996f};
SUPPORT_HBM = Resources.getSystem().getBoolean(285540415);
HBM_SUPPORT_DIMMING = Resources.getSystem().getBoolean(285540386);
float[] floatArray = getFloatArray(Resources.getSystem().obtainTypedArray(285409305));
sHbmLuxLevels = floatArray;
HBM_START_LUX = floatArray[0];
HBM_BRIGHTENING_THRES = Resources.getSystem().getInteger(285933609) / 1000.0f;
HBM_DARKENING_THRES = Resources.getSystem().getInteger(285933612) / 1000.0f;
HBM_BRIGHTENING_DEBOUNCE = Resources.getSystem().getInteger(285933607);
HBM_DARKENING_DEBOUNCE = Resources.getSystem().getInteger(285933610);
HBM_MAX_NIT = Resources.getSystem().getInteger(285933613);
HBM_BRIGHTENING_LUX = Resources.getSystem().getInteger(285933608);
HBM_DARKENING_LUX = Resources.getSystem().getInteger(285933611);
int i = (1 << DeviceFeature.BACKLIGHT_BIT) - 1;
NORMAL_BRIGHTNESS_ON = i;
int i2 = 1 << DeviceFeature.HBMBACKLIGHT_BIT;
HBM_BRIGHTNESS_ON = i2;
HBM_BRIGHTNESS_ON_FLOAT = i2 / i;
USE_FOLD_ENABLED = Resources.getSystem().getBoolean(285540372);
USE_DAEMON_SENSOR_POLICY = FeatureParser.getBoolean("use_daemon_sensor_policy", true);
}
/* JADX WARN: Removed duplicated region for block: B:29:0x0076 */
/*
Code decompiled incorrectly, please refer to instructions dump.
*/
private boolean needToUpdateAssistSensorData() {
boolean ret;
if (DEBUG) {
Slog.i(TAG, "USE_ASSISTSENSOR_ENABLED=" + USE_ASSISTSENSOR_ENABLED + ", mAssistSensorTime=" + this.mAssistSensorTime);
}
boolean z = USE_ASSISTSENSOR_ENABLED;
if (!z || this.mAssistSensorTime == -1) {
return false;
}
long currTime = SystemClock.uptimeMillis();
long deltaTime = currTime - this.mAssistSensorTime;
float f = this.mAssistBrighteningThres;
if (f != -1.0f) {
float f2 = this.mAssistDarkeningThres;
if (f2 != -1.0f) {
float f3 = this.mAssistSensorData;
if ((f3 > f || f3 < f2) && checkAssistSensorValid() && this.mAssistSensorData < ASSISTSENSOR_MAXTHRES && deltaTime > 10000 && !isMotionStaticRotate()) {
ret = true;
if (DEBUG) {
Slog.i(TAG, "USE_ASSISTSENSOR_ENABLED=" + z + ", mAssistSensorTime=" + this.mAssistSensorTime + ", currTime=" + currTime + ", deltaTime=" + deltaTime + ", mAssistSensorData=" + this.mAssistSensorData + ", mAssistBrighteningThres=" + this.mAssistBrighteningThres + ", mAssistDarkeningThres=" + this.mAssistDarkeningThres + ", ret=" + ret);
}
return ret;
}
}
}
ret = false;
if (DEBUG) {
}
return ret;
}
public Sensor getSecLightSensor() {
return this.mSecLightSensor;
}
public void initialize(SensorManager sensorManager, Context context, Handler handler) {
this.mHandler = handler;
this.mSensorManager = sensorManager;
this.mRotationWatcher = new RotationWatcher();
this.mWindowManager = IWindowManager.Stub.asInterface(ServiceManager.getService("window"));
if (USE_FOLD_ENABLED) {
this.mSecLightSensor = this.mSensorManager.getDefaultSensor(SENSOR_TYPE_LIGHT_SECONDARY);
}
if (USE_PROXIMITY_ENABLED) {
Sensor defaultSensor = this.mSensorManager.getDefaultSensor(8);
this.mProximitySensor = defaultSensor;
if (defaultSensor != null) {
this.mProximityThreshold = Math.min(defaultSensor.getMaximumRange(), 5.0f);
}
}
if (USE_ACCELEROMETER_ENABLED) {
this.mAccelerometer = this.mSensorManager.getDefaultSensor(1);
}
if (USE_MOTIONSENSOR_ENABLED) {
this.mMotionSensor = this.mSensorManager.getDefaultSensor(MOTIONSENSOR_TYPE);
}
if (USE_ASSISTSENSOR_ENABLED) {
this.mAssistSensor = this.mSensorManager.getDefaultSensor(ASSIST_SENSOR_TYPE);
}
AutomaticBrightnessTouchHelper.initialize();
getMaxNit();
getSpeedingRatio();
this.mContext = context;
CameraManager cameraManager = (CameraManager) context.getSystemService("camera");
this.mCameraManager = cameraManager;
Handler handler2 = this.mHandler;
if (handler2 != null) {
cameraManager.registerTorchCallback(this.mTorchCallback, handler2);
}
this.mDaemonSensorPolicy = new DaemonSensorPolicy(this.mContext, sensorManager, handler.getLooper(), this);
try {
this.HBM_AUTO_BRIGHTNESS_SPLINE = Spline.createSpline(getFloatArray(Resources.getSystem().obtainTypedArray(285409305)), getFloatArray(Resources.getSystem().obtainTypedArray(285409306)));
Slog.i(TAG, "HBM_AUTO_BRIGHTNESS_SPLINE: " + this.HBM_AUTO_BRIGHTNESS_SPLINE);
this.HBM_NITTOBACKLIGHT_SPLINE = Spline.createSpline(getFloatArray(Resources.getSystem().obtainTypedArray(285409306)), getFloatArray(Resources.getSystem().obtainTypedArray(285409304)));
Slog.i(TAG, "HBM_NITTOBACKLIGHT_SPLINE: " + this.HBM_NITTOBACKLIGHT_SPLINE);
} catch (IllegalArgumentException e) {
Slog.w(TAG, "HBM_NITTOBACKLIGHT_SPLINE not support");
}
}
public float configure(boolean enable, float screenAutoBrightness) {
setSensorEnabled(enable);
if (USE_DAEMON_SENSOR_POLICY) {
this.mDaemonSensorPolicy.notifyAutoBrightnessState(enable);
}
AutomaticBrightnessTouchHelper.configure(enable, this.mContext);
if (!enable && this.mAutomaticBrightnessEnable) {
this.mAutomaticBrightnessEnable = false;
this.mFirstLux = -1.0f;
this.mLastLux = -1.0f;
this.mCurrentLux = -1.0f;
this.mBrightnessStatus = 0;
this.mDynamicEnvStartTime = 0L;
this.mHbmEnterStartTs = 0L;
this.mHbmExitStartTs = 0L;
this.mHbmStatus = false;
this.mLastSettingBrightness = Float.NaN;
} else if (enable && !this.mAutomaticBrightnessEnable) {
this.mAutomaticBrightnessEnable = true;
}
return screenAutoBrightness;
}
private void setSensorEnabled(boolean enable) {
if (USE_PROXIMITY_ENABLED) {
setProximitySensorEnabled(enable);
}
if (USE_ACCELEROMETER_ENABLED) {
setAccSensorEnabled(enable);
}
if (USE_MOTIONSENSOR_ENABLED) {
setMotionSensorEnabled(enable);
}
if (USE_ASSISTSENSOR_ENABLED) {
setAssistSensorEnabled(enable);
}
}
private void setProximitySensorEnabled(boolean enable) {
if (enable && !this.mProximitySensorEnabled) {
Slog.i(TAG, "setProximitySensorEnabled enable");
this.mProximitySensorEnabled = true;
this.mSensorManager.registerListener(this.mSensorListener, this.mProximitySensor, 3);
} else if (!enable && this.mProximitySensorEnabled) {
Slog.i(TAG, "setProximitySensorEnabled disable");
this.mProximitySensorEnabled = false;
this.mProximity = -1;
this.mSensorManager.unregisterListener(this.mSensorListener, this.mProximitySensor);
}
}
private void setAccSensorEnabled(boolean enable) {
if (enable && !this.mAccSensorEnabled) {
Slog.i(TAG, "setAccSensorEnabled enable");
this.mAccSensorEnabled = true;
this.mSensorManager.registerListener(this.mSensorListener, this.mAccelerometer, 3);
} else if (!enable && this.mAccSensorEnabled) {
Slog.i(TAG, "setAccSensorEnabled disable");
this.mAccSensorEnabled = false;
this.mSensorManager.unregisterListener(this.mSensorListener, this.mAccelerometer);
}
}
private void setMotionSensorEnabled(boolean enable) {
if (enable && !this.mMotionSensorEnabled) {
Slog.i(TAG, "setMotionSensorEnabled enable");
this.mMotionSensorEnabled = true;
this.mSensorManager.registerListener(this.mSensorListener, this.mMotionSensor, 3);
} else if (!enable && this.mMotionSensorEnabled) {
Slog.i(TAG, "setMotionSensorEnabled disable");
this.mMotionSensorEnabled = false;
this.mMotionStatus = 1;
this.mSensorManager.unregisterListener(this.mSensorListener, this.mMotionSensor);
}
}
private void setAssistSensorEnabled(boolean enable) {
if (enable && !this.mAssistSensorEnabled) {
Slog.i(TAG, "setAssistSensorEnabled enable");
this.mAssistSensorEnabled = true;
this.mSensorManager.registerListener(this.mSensorListener, this.mAssistSensor, 3);
} else if (!enable && this.mAssistSensorEnabled) {
Slog.i(TAG, "setAssistSensorEnabled disable");
this.mAssistSensorEnabled = false;
this.mAssistSensorData = -1.0f;
this.mAssistSensorTime = -1L;
this.mSensorManager.unregisterListener(this.mSensorListener, this.mAssistSensor);
}
}
public void onProximitySensorChanged(SensorEvent event) {
if (this.mProximitySensorEnabled) {
SystemClock.uptimeMillis();
float distance = event.values[0];
boolean positive = distance >= MiuiMagicWinAnimation.INVALID_THRESHOLD && distance < this.mProximityThreshold;
if (positive) {
this.mProximity = 1;
} else {
this.mProximity = 0;
}
}
}
public void onAccelerometerSensorChanged(SensorEvent event) {
if (this.mAccSensorEnabled) {
float[] values = event.values;
float ax = values[0];
float ay = values[1];
float az = values[2];
double g = Math.sqrt((ax * ax) + (ay * ay) + (az * az));
double cos = az / g;
if (cos > 1.0d) {
cos = 1.0d;
} else if (cos < -1.0d) {
cos = -1.0d;
}
double angle = (Math.acos(cos) * 180.0d) / 3.141592653589793d;
this.mAngleXYToHorizon = (float) angle;
if (DEBUG) {
Slog.d(TAG, "Auto-brightness acc: x=" + ax + ", y=" + ay + ", z=" + az + ", xyz=" + g + ", angle=" + angle + ", angle_xyTohorizon" + this.mAngleXYToHorizon);
}
}
}
public void onMotionSensorChanged(SensorEvent event) {
if (this.mMotionSensorEnabled) {
this.mMotionStatus = (int) event.values[0];
if (DEBUG) {
Slog.i(TAG, "Auto-brightness motion status: " + this.mMotionStatus);
}
}
}
public void onAssistSensorChanged(SensorEvent event) {
if (this.mAssistSensorEnabled) {
this.mAssistSensorData = event.values[0];
if (DEBUG) {
Slog.i(TAG, "Auto-brightness assistsensor lux: " + this.mAssistSensorData);
}
}
}
/* loaded from: classes.dex */
public class RotationWatcher extends IRotationWatcher.Stub {
RotationWatcher() {
AutomaticBrightnessControllerImpl.this = this$0;
}
public void onRotationChanged(int rotation) throws RemoteException {
AutomaticBrightnessControllerImpl.this.mRotation = rotation;
if (AutomaticBrightnessControllerImpl.DEBUG) {
Slog.d(AutomaticBrightnessControllerImpl.TAG, "onRotationChanged:rotation=" + rotation);
}
AutomaticBrightnessControllerImpl.this.mHandler.sendMessageDelayed(AutomaticBrightnessControllerImpl.this.mHandler.obtainMessage(AutomaticBrightnessControllerImpl.MSG_ROTATION_CHANGE, Integer.valueOf(rotation)), 30L);
}
}
private void registerRotationListener() {
try {
this.mWindowManager.watchRotation(this.mRotationWatcher, 0);
this.mRotationWatcherOn = true;
} catch (RemoteException e) {
e.printStackTrace();
}
}
private void unregisterRotationListener() {
try {
this.mWindowManager.removeRotationWatcher(this.mRotationWatcher);
this.mRotationWatcherOn = false;
} catch (RemoteException e) {
e.printStackTrace();
}
}
public boolean checkProximityStatus(float lux, boolean luxValid) {
if (AutomaticBrightnessTouchHelper.checkTouchStatus(lux, luxValid)) {
return true;
}
if (DEBUG || !luxValid) {
Slog.i(TAG, "mProximity=" + this.mProximity + ", lux=" + lux);
}
if (this.mFirstLux == -1.0f) {
this.mFirstLux = lux;
}
if (USE_PROXIMITY_ENABLED && this.mProximity == 1 && luxValid) {
Slog.i(TAG, "drop the lightsensor event! lux=" + lux);
return true;
}
this.mRealLux = lux;
return false;
}
float getCurrentRealLux() {
return this.mRealLux;
}
float getCurrentLux(float ambientlux) {
if (DEBUG) {
Slog.i(TAG, "mRealLux = " + this.mRealLux + ", ambientlux = " + ambientlux);
}
float f = this.mRealLux;
if (f >= TIME_2 * ambientlux && f <= 1.2f * ambientlux) {
return f;
}
return ambientlux;
}
boolean checkAssistSensorValid() {
if (USE_ASSISTSENSOR_ENABLED) {
float f = this.mAssistSensorData;
if (f != -1.0f && f < ASSISTSENSOR_DATA_THRESHOLD && !this.mIsTorchOpen && System.currentTimeMillis() - this.mTorchCloseTime > 1000) {
return true;
}
return false;
}
return false;
}
/* JADX WARN: Code restructure failed: missing block: B:5:0x000b, code lost:
if (r1 > r6) goto L7;
*/
/*
Code decompiled incorrectly, please refer to instructions dump.
*/
public float getCurrentLux(float lux, float maxLux, float minLux) {
float f;
if (checkAssistSensorValid()) {
f = this.mAssistSensorData;
}
f = lux;
float currLux = f;
float f2 = this.mAssistSensorData;
if (currLux == f2) {
this.mAssistDarkeningThres = 0.2f * f2;
float f3 = ASSISTSENSOR_BRIGHTENINGRATIO * f2;
this.mAssistBrighteningThres = f3;
if (f3 < f2 + 5.0f) {
this.mAssistBrighteningThres = f2 + 5.0f;
}
this.mAssistSensorTime = SystemClock.uptimeMillis();
} else {
this.mAssistSensorTime = -1L;
}
this.mCurrentLux = currLux;
if (lux != currLux || DEBUG) {
Slog.i(TAG, "maxLux=" + maxLux + ", minLux=" + minLux + ", lux=" + lux + ", mAssistSensorData=" + this.mAssistSensorData + ", mAssistDarkeningThres=" + this.mAssistDarkeningThres + ", mAssistBrighteningThres=" + this.mAssistBrighteningThres + ", mAssistSensorTime=" + this.mAssistSensorTime + ", currLux=" + currLux + ", mBrightnessStatus=" + this.mBrightnessStatus);
}
return currLux;
}
public void checkBrightening(float lux, float brightenThreshold, float darkThreshold) {
if (lux > brightenThreshold) {
this.mBrightnessStatus = 2;
this.mDynamicEnvStartTime = SystemClock.uptimeMillis();
} else if (lux < darkThreshold) {
this.mBrightnessStatus = 1;
this.mDynamicEnvStartTime = SystemClock.uptimeMillis();
} else {
this.mBrightnessStatus = 0;
}
}
boolean checkDynamicDebounce() {
long currTime = SystemClock.uptimeMillis();
long deltaTime = currTime - this.mDynamicEnvStartTime;
if (DEBUG) {
Slog.i(TAG, "mDynamicEnvStartTime=" + this.mDynamicEnvStartTime + ", deltaTime=" + deltaTime + ", currTime=" + currTime);
}
if (this.mDynamicEnvStartTime == 0 || deltaTime > 2000) {
return true;
}
return false;
}
int checkMotionStatus() {
if (USE_MOTIONSENSOR_ENABLED) {
int i = this.mMotionStatus;
if (i == 2 || i == 3) {
return i;
}
return 0;
}
return 0;
}
public boolean isMotionStaticRotate() {
if (SMD_EFFECT_STATUS && checkMotionStatus() == 3) {
return true;
}
return false;
}
/* JADX WARN: Removed duplicated region for block: B:32:0x005d */
/*
Code decompiled incorrectly, please refer to instructions dump.
*/
public long updateDarkeningDebounce(float lux, float maxLux, float minLux) {
long darkeningDebounce;
if (checkMotionStatus() == 3) {
float f = this.mCurrentLux;
if (f < MOTIONSENSOR_STATIC_LUXTHRESHOLD && f != -1.0f && checkDynamicDebounce()) {
darkeningDebounce = DYNAMIC_DARKENING_DEBOUNCE1;
if (DEBUG) {
Slog.i(TAG, "DarkeningLightDebounce=" + darkeningDebounce + ", mMotionStatus = " + this.mMotionStatus + ", mCurrentLux = " + this.mCurrentLux);
}
return darkeningDebounce;
}
}
if (checkMotionStatus() == 2) {
float f2 = this.mCurrentLux;
if (f2 < MOTIONSENSOR_STATIC_LUXTHRESHOLD && f2 != -1.0f && checkDynamicDebounce()) {
darkeningDebounce = DYNAMIC_DARKENING_DEBOUNCE2;
if (DEBUG) {
}
return darkeningDebounce;
}
}
if (USE_DYNAMIC_DEBOUNCE) {
float f3 = this.mCurrentLux;
if (f3 < DYNAMIC_DARKENING_LUXTHRESHOLD && f3 != -1.0f && checkDynamicDebounce()) {
darkeningDebounce = DYNAMIC_DARKENING_DEBOUNCE2;
if (DEBUG) {
}
return darkeningDebounce;
}
}
darkeningDebounce = DYNAMIC_DARKENING_DEFAULTDEBOUNCE;
if (DEBUG) {
}
return darkeningDebounce;
}
public float getDarkenThreshold(float darkThreshold, float brightenThreshold, float lux) {
float mAmbientDarkeningThreshold = darkThreshold;
float f = this.mAngleXYToHorizon;
if (f > HIGHANGLE_THRESHOLD) {
mAmbientDarkeningThreshold *= 1.0f - DARKENING_HYSTERESIS_SEVENTYTONINETY;
} else if (f > ALS_FOV) {
mAmbientDarkeningThreshold *= 1.0f - DARKENING_HYSTERESIS_FOVTOSEVENTY;
}
Slog.i(TAG, "AmbientLux=" + lux + ", mAmbientDarkeningThreshold=" + mAmbientDarkeningThreshold + ", mAmbientBrighteningThreshold=" + brightenThreshold + ", angle_xytohorizon=" + this.mAngleXYToHorizon);
return mAmbientDarkeningThreshold;
}
public boolean checkSkipDebounceStatus(long enableTime, long time, float lux) {
if (DEBUG) {
Slog.d(TAG, "checkSkipDebounceStatus, enableTime=" + enableTime + ", time=" + time + ", SKIP_DEBOUNCE_ENABLED=" + SKIP_DEBOUNCE_ENABLED + ", SKIP_DEBOUNCE=" + SKIP_DEBOUNCE + ", enableTime=" + enableTime + ", mLastLux=" + this.mLastLux + ", mFirstLux=" + this.mFirstLux + ", lux=" + lux);
}
if (SKIP_DEBOUNCE_ENABLED && SKIP_DEBOUNCE + enableTime >= time) {
float f = this.mLastLux;
if (f == -1.0f || (f != -1.0f && lux > f + SKIP_LUX_DEBOUNCE2 && lux > this.mFirstLux + SKIP_LUX_DEBOUNCE1)) {
this.mAmbientLuxFirstEvent = true;
Slog.i(TAG, "skip debounce!");
this.mLastLux = lux;
return true;
}
}
if (SKIP_DEBOUNCE + enableTime >= time && this.mAmbientLuxFirstEvent && lux == this.mLastLux) {
return needToUpdateAssistSensorData();
}
this.mAmbientLuxFirstEvent = false;
this.mLastLux = lux;
if (this.mRealLux == lux && lux != MiuiMagicWinAnimation.INVALID_THRESHOLD) {
this.mStableLux = lux;
}
return needToUpdateAssistSensorData();
}
public boolean isAmbientLuxFirstEvent() {
return this.mAmbientLuxFirstEvent;
}
public int changeBrightness(float lux, int brightness) {
int temp_brightness = brightness;
int maxBrightness = NORMAL_BRIGHTNESS_ON;
boolean z = SUPPORT_HBM;
if (z && HBM_SUPPORT_DIMMING && lux > HBM_START_LUX) {
if (DEBUG) {
Slog.d(TAG, "lux: " + lux + " brightness: " + brightness);
}
temp_brightness = Math.min(Math.round(this.HBM_NITTOBACKLIGHT_SPLINE.interpolate(this.HBM_AUTO_BRIGHTNESS_SPLINE.interpolate(lux))) + brightness, NORMAL_BRIGHTNESS_ON + HBM_BRIGHTNESS_ON);
if (DEBUG) {
Slog.d(TAG, "after modify: lux: " + lux + " brightness: " + temp_brightness);
}
} else if (z && !HBM_SUPPORT_DIMMING) {
long currTime = SystemClock.uptimeMillis();
long deltaTime = 0;
if (brightness == maxBrightness && lux > HBM_BRIGHTENING_LUX) {
this.mHbmExitStartTs = 0L;
long j = this.mHbmEnterStartTs;
deltaTime = currTime - j;
if (j == 0) {
this.mHbmEnterStartTs = currTime;
} else if (((float) deltaTime) > HBM_BRIGHTENING_DEBOUNCE) {
this.mHbmStatus = true;
temp_brightness = HBM_BRIGHTNESS_ON + brightness;
}
} else if (this.mHbmStatus && lux < HBM_DARKENING_LUX) {
this.mHbmEnterStartTs = 0L;
long j2 = this.mHbmExitStartTs;
deltaTime = currTime - j2;
if (j2 == 0) {
this.mHbmExitStartTs = currTime;
} else if (((float) deltaTime) > HBM_DARKENING_DEBOUNCE) {
this.mHbmStatus = false;
} else {
temp_brightness = HBM_BRIGHTNESS_ON + brightness;
}
} else {
this.mHbmEnterStartTs = 0L;
}
if (DEBUG) {
Slog.i(TAG, "changeBrightness: brightness: " + brightness + ", lux: " + lux + ", mHbmEnterStartTs=" + this.mHbmEnterStartTs + ", mHbmExitStartTs=" + this.mHbmExitStartTs + ", mHbmStatus=" + this.mHbmStatus + ", deltaTime=" + deltaTime + ", temp_brightness=" + temp_brightness);
}
} else if (lux >= 8000.0f) {
return maxBrightness;
}
return temp_brightness;
}
public void updateSlowChangeStatus(boolean slowChange, float startBrightness) {
this.mSlowChange = slowChange;
this.mStartBrightness = startBrightness;
if (DEBUG) {
Slog.d(TAG, "updateSlowChangeStatus: " + this.mSlowChange + ", startBrightness: " + this.mStartBrightness);
}
}
void getMaxNit() {
this.mMaxNitsProperty = Float.parseFloat(SystemProperties.get("persist.vendor.max.brightness", "0"));
if (DEBUG) {
Slog.d(TAG, "maxNit: " + this.mMaxNitsProperty);
}
}
void getSpeedingRatio() {
this.mSpeedingRatio = Float.parseFloat(SystemProperties.get("sys.sensor.speedingratio", "0"));
if (DEBUG) {
Slog.d(TAG, "mSpeedingRatio: " + this.mSpeedingRatio);
}
}
public float getCeilingLimitValue(float maxvalue) {
if (SUPPORT_HBM && this.mAutomaticBrightnessEnable) {
return brightnessIntToFloat(this.mContext, NORMAL_BRIGHTNESS_ON + HBM_BRIGHTNESS_ON);
}
return maxvalue;
}
float convertToNit(float brightness) {
if (SUPPORT_HBM && brightness > 1.0f && DeviceFeature.HBMBACKLIGHT_BIT > 0) {
float nit = this.mMaxNitsProperty + (((brightness - 1.0f) * HBM_MAX_NIT) / HBM_BRIGHTNESS_ON_FLOAT);
return nit;
}
float nit2 = brightness * this.mMaxNitsProperty;
return nit2;
}
/* JADX WARN: Removed duplicated region for block: B:16:0x002f */
/*
Code decompiled incorrectly, please refer to instructions dump.
*/
float convertToBrightness(float nit) {
float brightness = MiuiMagicWinAnimation.INVALID_THRESHOLD;
if (SUPPORT_HBM && nit > this.mMaxNitsProperty && DeviceFeature.HBMBACKLIGHT_BIT > 0) {
float f = HBM_MAX_NIT;
if (f > MiuiMagicWinAnimation.INVALID_THRESHOLD) {
brightness = (((nit - this.mMaxNitsProperty) * HBM_BRIGHTNESS_ON_FLOAT) / f) + 1.0f;
if (DEBUG) {
Slog.d(TAG, "nit: " + nit + ", mMaxNitsProperty: " + this.mMaxNitsProperty + ", HBM_MAX_NIT: " + HBM_MAX_NIT);
}
return brightness;
}
}
float f2 = this.mMaxNitsProperty;
if (f2 > MiuiMagicWinAnimation.INVALID_THRESHOLD) {
brightness = nit / f2;
}
if (DEBUG) {
}
return brightness;
}
int getIndex(float nit) {
int index = 1;
while (true) {
float[] fArr = mNitsLevels;
if (fArr.length <= index || nit >= fArr[index]) {
break;
}
index++;
}
if (DEBUG) {
Slog.d(TAG, "nit: " + nit + ", index: " + index);
}
return index - 1;
}
float getTime(float nit, int index) {
float a = mALevels[index];
float b = mBLevels[index];
float time = (MathUtils.log(nit / a) / MathUtils.log(b)) / TIME_5;
if (DEBUG) {
Slog.d(TAG, "time: " + time + ", a: " + a + ", b: " + b);
}
return MathUtils.abs(time);
}
float getDarkeningRate(float brightness) {
float rate;
float nit = convertToNit(brightness);
int index = getIndex(nit);
float f = mALevels[index] * TIME_5;
float[] fArr = mBLevels;
float rate2 = MathUtils.abs(f * MathUtils.pow(fArr[index], getTime(nit, index) * TIME_5) * MathUtils.log(fArr[index]));
if (SUPPORT_HBM && nit > this.mMaxNitsProperty) {
rate = (((this.mSpeedingRatio + 1.0f) * rate2) * HBM_BRIGHTNESS_ON_FLOAT) / HBM_MAX_NIT;
} else {
rate = rate2 / this.mMaxNitsProperty;
}
int i = NORMAL_BRIGHTNESS_ON;
if (i < 4095 && nit <= NIT_LEVEL) {
rate = NIT_LEVEL / i;
} else if (IS_UMI_0B_DISPLAY_PANEL && nit <= NIT_LEVEL) {
rate = 80.0f / i;
}
if (DEBUG) {
Slog.d(TAG, "rate: " + rate + ", mSpeedingRatio: " + this.mSpeedingRatio);
}
return rate;
}
float getExpRate(float begin, float end, float nit, float time1, float time2) {
float a = MathUtils.log(end / begin) / (time2 - time1);
float b = MathUtils.log(end) - (a * time2);
float t = (MathUtils.log(nit) - b) / a;
float ret = MathUtils.exp((a * t) + b) * a;
if (SUPPORT_HBM && nit > this.mMaxNitsProperty) {
return (HBM_BRIGHTNESS_ON_FLOAT * ret) / HBM_MAX_NIT;
}
return ret / this.mMaxNitsProperty;
}
float getBrighteningRate(float brightness, float startBrightness, float tgtBrightness) {
float nit = convertToNit(brightness);
float startnit = convertToNit(startBrightness);
float tgtnit = convertToNit(tgtBrightness);
if (startnit < NIT_LEVEL1) {
if (tgtnit < NIT_LEVEL1) {
float ret = (tgtBrightness - startBrightness) / TIME_4;
return ret;
} else if (tgtnit < NIT_LEVEL3) {
if (nit < NIT_LEVEL1) {
float ret2 = (convertToBrightness(NIT_LEVEL1) - startBrightness) / TIME_3;
return ret2;
}
float ret3 = getExpRate(NIT_LEVEL1, tgtnit, nit, TIME_3, TIME_4);
return ret3;
} else if (nit < NIT_LEVEL1) {
float ret4 = (convertToBrightness(NIT_LEVEL1) - startBrightness) / TIME_2;
return ret4;
} else if (nit < NIT_LEVEL2) {
float ret5 = getExpRate(NIT_LEVEL1, NIT_LEVEL2, nit, TIME_2, TIME_3);
return ret5;
} else {
float ret6 = getExpRate(NIT_LEVEL2, tgtnit, nit, TIME_3, TIME_4);
return ret6;
}
} else if (startnit < NIT_LEVEL3) {
if (tgtnit < NIT_LEVEL3) {
float ret7 = getExpRate(startnit, tgtnit, nit, MiuiMagicWinAnimation.INVALID_THRESHOLD, TIME_4);
return ret7;
} else if (nit < NIT_LEVEL2) {
float ret8 = getExpRate(startnit, NIT_LEVEL2, nit, MiuiMagicWinAnimation.INVALID_THRESHOLD, TIME_3);
return ret8;
} else {
float ret9 = getExpRate(NIT_LEVEL2, tgtnit, nit, TIME_3, TIME_4);
return ret9;
}
} else {
float ret10 = getExpRate(startnit, tgtnit, nit, MiuiMagicWinAnimation.INVALID_THRESHOLD, TIME_4);
return ret10;
}
}
public float computeFloatRate(float rate, float currBrightness, float tgtBrightness) {
float ret = rate;
if (BRIGHTNESS_RATE_ADJUSTIBLE && this.mAutomaticBrightnessEnable && this.mSlowChange) {
if (rate == MiuiMagicWinAnimation.INVALID_THRESHOLD) {
ret = MiuiMagicWinAnimation.INVALID_THRESHOLD;
} else if (this.mAmbientLuxFirstEvent) {
ret = rate;
} else if (isAutoBrightnessByApplicationRateEnable()) {
ret = getAutobrightnessByApplicationRate(currBrightness, tgtBrightness, ret);
} else {
float f = this.mStartBrightness;
ret = f < tgtBrightness ? getBrighteningRate(currBrightness, f, tgtBrightness) : getDarkeningRate(currBrightness);
}
}
if (DEBUG) {
Slog.i(TAG, "computeFloatRate: in rate=" + rate + ", out rate=" + ret);
}
return ret;
}
public float brightnessIntToFloat(Context context, int brightnessInt) {
PowerManager pm = (PowerManager) context.getSystemService(PowerManager.class);
float pmMinBrightness = pm.getBrightnessConstraint(0);
float pmMaxBrightness = pm.getBrightnessConstraint(1);
int minBrightnessInt = Math.round(BrightnessSynchronizer.brightnessFloatToIntRange(pmMinBrightness));
Math.round(BrightnessSynchronizer.brightnessFloatToIntRange(pmMaxBrightness));
if (!SUPPORT_HBM || !this.mAutomaticBrightnessEnable) {
return BrightnessSynchronizer.brightnessIntToFloat(brightnessInt);
}
if (brightnessInt == 0) {
return -1.0f;
}
if (brightnessInt == -1) {
return Float.NaN;
}
float brightnessFlt = MathUtils.lerp(pmMinBrightness, pmMaxBrightness, MathUtils.lerpInv(minBrightnessInt, NORMAL_BRIGHTNESS_ON, brightnessInt));
if (DEBUG) {
Slog.d(TAG, "brightnessIntToFloat: int: " + brightnessInt + ", float: " + brightnessFlt);
}
return brightnessFlt;
}
public int brightnessFloatToInt(Context context, float brightnessFloat) {
PowerManager pm = (PowerManager) context.getSystemService(PowerManager.class);
float pmMinBrightness = pm.getBrightnessConstraint(0);
float pmMaxBrightness = pm.getBrightnessConstraint(1);
int minBrightnessInt = Math.round(BrightnessSynchronizer.brightnessFloatToIntRange(pmMinBrightness));
Math.round(BrightnessSynchronizer.brightnessFloatToIntRange(pmMaxBrightness));
if (!SUPPORT_HBM || !this.mAutomaticBrightnessEnable) {
return BrightnessSynchronizer.brightnessFloatToInt(brightnessFloat);
}
if (BrightnessSynchronizer.floatEquals(brightnessFloat, -1.0f)) {
return 0;
}
if (Float.isNaN(brightnessFloat)) {
return -1;
}
int brightnessInt = Math.round(MathUtils.lerp(minBrightnessInt, NORMAL_BRIGHTNESS_ON, MathUtils.lerpInv(pmMinBrightness, pmMaxBrightness, brightnessFloat)));
if (DEBUG) {
Slog.d(TAG, "brightnessFloatToInt: float: " + brightnessFloat + ", int: " + brightnessInt);
}
return brightnessInt;
}
public boolean needToUpdateSetting(float brightnessState) {
if (!SUPPORT_HBM || brightnessState <= 1.0f || Float.isNaN(this.mLastSettingBrightness) || (this.mLastSettingBrightness < 1.0f && brightnessState >= 1.0f)) {
this.mLastSettingBrightness = brightnessState;
if (DEBUG) {
Slog.d(TAG, "need to update setting: " + brightnessState + ", mLastSettingBrightness: " + this.mLastSettingBrightness);
return true;
}
return true;
} else if (DEBUG) {
Slog.d(TAG, "do not need to update setting: " + brightnessState + ", mLastSettingBrightness: " + this.mLastSettingBrightness);
return false;
} else {
return false;
}
}
public boolean isSlowChangeForHdr(boolean isAutoMode, boolean slowChange) {
int i;
boolean z = true;
if (!this.mHDRState || ((i = this.mRotation) != 1 && i != 3)) {
z = false;
}
boolean hdrState = z;
this.mNeedBrightening = false;
if (!this.mSupportHdr) {
return slowChange;
}
if (this.mLastHdrState != hdrState) {
this.mNeedBrightening = hdrState;
slowChange = false;
this.mLastHdrState = hdrState;
} else if (hdrState) {
this.mNeedBrightening = hdrState;
slowChange = isAutoMode;
this.mLastHdrState = hdrState;
}
if (DEBUG) {
Slog.d(TAG, "getSlowChangeForHdr: mRotation=" + this.mRotation + ", isAutoMode=" + isAutoMode + ", hdr=" + this.mHDRState + ", hdrState=" + hdrState + ", slowChange=" + slowChange);
}
return slowChange;
}
public void setHDRState(boolean hdrState) {
this.mHDRState = hdrState;
}
public float getBrighteningRatio() {
return this.mBrighteningRatio;
}
public boolean isSupportHDR() {
return this.mSupportHdr;
}
public void setRotationWatcherEnabledIfNeeded() {
boolean z = this.mSupportHdr;
if (z && !this.mRotationWatcherOn) {
registerRotationListener();
} else if (this.mRotationWatcherOn && !z) {
unregisterRotationListener();
}
}
public boolean shouldApplyHDR() {
return this.mNeedBrightening && checkRatioValid(this.mBrighteningRatio);
}
private boolean checkRatioValid(float ratio) {
if (ratio < MiuiMagicWinAnimation.INVALID_THRESHOLD) {
return false;
}
return true;
}
public void dump(PrintWriter pw) {
DEBUG = isDebuggable();
pw.println(" USE_PROXIMITY_ENABLED=" + USE_PROXIMITY_ENABLED);
pw.println(" DARKENING_HYSTERESIS_ZEROTOFOV=" + DARKENING_HYSTERESIS_ZEROTOFOV);
pw.println(" DARKENING_HYSTERESIS_FOVTOSEVENTY=" + DARKENING_HYSTERESIS_FOVTOSEVENTY);
pw.println(" DARKENING_HYSTERESIS_SEVENTYTONINETY=" + DARKENING_HYSTERESIS_SEVENTYTONINETY);
pw.println(" ALS_FOV=" + ALS_FOV);
pw.println(" HIGHANGLE_THRESHOLD=" + HIGHANGLE_THRESHOLD);
pw.println(" SKIP_DEBOUNCE_ENABLED=" + SKIP_DEBOUNCE_ENABLED);
pw.println(" SKIP_DEBOUNCE=" + SKIP_DEBOUNCE);
pw.println(" SKIP_LUX_DEBOUNCE1=" + SKIP_LUX_DEBOUNCE1);
pw.println(" SKIP_LUX_DEBOUNCE2=" + SKIP_LUX_DEBOUNCE2);
pw.println(" USE_ACCELEROMETER_ENABLED=" + USE_ACCELEROMETER_ENABLED);
pw.println(" BACKLIGHT_BIT=" + DeviceFeature.BACKLIGHT_BIT);
pw.println(" AUTOBRIGHTNESS_RATE_SLOW=" + AUTOBRIGHTNESS_RATE_SLOW);
pw.println(" BRIGHTNESS_RATE_ADJUSTIBLE=" + BRIGHTNESS_RATE_ADJUSTIBLE);
pw.println(" BRIGHTNESS_DARK=" + BRIGHTNESS_DARK);
pw.println(" BRIGHTNESS_DARK_RAMPRATE=" + BRIGHTNESS_DARK_RAMPRATE);
pw.println(" SLOW_RATIO=" + SLOW_RATIO);
pw.println(" WAIT_FOR_AUTOBRIGHTNESS=" + WAIT_FOR_AUTOBRIGHTNESS);
pw.println(" WAIT_TIME=" + WAIT_TIME);
pw.println(" MAX_NIT=" + this.mMaxNitsProperty);
pw.println(" HBM_AUTO_BRIGHTNESS_SPLINE=" + this.HBM_AUTO_BRIGHTNESS_SPLINE);
pw.println(" HBM_NITTOBACKLIGHT_SPLINE=" + this.HBM_NITTOBACKLIGHT_SPLINE);
pw.println(" SUPPORT_HBM=" + SUPPORT_HBM);
pw.println(" HBM_SUPPORT_DIMMING=" + HBM_SUPPORT_DIMMING);
pw.println(" HBM_BITS=" + DeviceFeature.HBMBACKLIGHT_BIT);
pw.println(" HBM_MAX_NIT=" + HBM_MAX_NIT);
pw.println(" HBM_BRIGHTNESS_ON=" + HBM_BRIGHTNESS_ON);
pw.println(" HBM_BRIGHTNESS_ON_FLOAT=" + HBM_BRIGHTNESS_ON_FLOAT);
pw.println(" mBrighteningRatio=" + this.mBrighteningRatio);
pw.println(" mSupportHdr=" + this.mSupportHdr);
AutomaticBrightnessTouchHelper.dump(pw, DEBUG);
this.mDaemonSensorPolicy.dump(pw);
DEBUG = DisplayDebugConfig.DEBUG_ABC;
}
boolean isDebuggable() {
return SystemProperties.getBoolean(AUTO_BRIGHTNESS_DEBUG, false);
}
private static float[] getFloatArray(TypedArray array) {
int length = array.length();
float[] floatArray = new float[length];
for (int i = 0; i < length; i++) {
floatArray[i] = array.getFloat(i, Float.NaN);
}
array.recycle();
return floatArray;
}
public boolean isSupportAutobrightnessByApplicationCategory() {
return this.IS_SUPPORT_AUTOBRIGHTNESS_BY_APPLICATION_CATEGORY && !this.IS_INTERNAL_BUILD;
}
public void setAutoBrightnessByApplicationRateEnable(boolean enable) {
this.mIsAutoBrightnessByApplicationRateEnable = isSupportAutobrightnessByApplicationCategory() && enable;
}
public void setAutoBrightnessByApplicationAnimationEnable(boolean enable) {
this.mIsAutoBrightnessByApplicationAnimationEnable = enable;
}
public boolean isAutoBrightnessByApplicationAnimationEnable() {
return this.mIsAutoBrightnessByApplicationAnimationEnable;
}
public boolean isAutoBrightnessByApplicationRateEnable() {
return this.mIsAutoBrightnessByApplicationRateEnable;
}
public void addUserDataPointByApplication(float lux, float brightness, String packageName, BrightnessMappingStrategy mapper) {
if (mapper instanceof MiuiPhysicalBrightnessMappingStrategy) {
MiuiPhysicalBrightnessMappingStrategy brightnessMapper = (MiuiPhysicalBrightnessMappingStrategy) mapper;
brightnessMapper.addUserDataPoint(lux, brightness, packageName);
return;
}
mapper.addUserDataPoint(lux, brightness);
}
public float getBrightnessByApplication(float lux, String packageName, int category, BrightnessMappingStrategy mapper, float value) {
if (mapper instanceof MiuiPhysicalBrightnessMappingStrategy) {
MiuiPhysicalBrightnessMappingStrategy brightnessMapper = (MiuiPhysicalBrightnessMappingStrategy) mapper;
return brightnessMapper.getBrightness(lux, packageName);
}
return mapper.getBrightness(lux, packageName, category);
}
public float getAutobrightnessByApplicationRate(float currentBrightness, float targetBrightness, float rate) {
if (isAutoBrightnessByApplicationAnimationEnable()) {
if (targetBrightness > currentBrightness) {
float diffBrightness = targetBrightness - currentBrightness;
if (diffBrightness > currentBrightness) {
this.mAutoBrightnessByApplicationRate = diffBrightness / 10.0f;
} else {
this.mAutoBrightnessByApplicationRate = diffBrightness / 5.0f;
}
} else {
float diffBrightness2 = currentBrightness - targetBrightness;
if (diffBrightness2 > targetBrightness) {
this.mAutoBrightnessByApplicationRate = diffBrightness2 / 10.0f;
} else {
this.mAutoBrightnessByApplicationRate = diffBrightness2 / 5.0f;
}
}
setAutoBrightnessByApplicationAnimationEnable(false);
}
return MathUtils.max(this.mAutoBrightnessByApplicationRate, 0.01f);
}
public float fillInLuxFromDaemonSensor() {
if (!USE_DAEMON_SENSOR_POLICY) {
return Float.NaN;
}
float lux = this.mDaemonSensorPolicy.getMainLightSensorLux();
if (USE_ASSISTSENSOR_ENABLED) {
this.mAssistSensorData = this.mDaemonSensorPolicy.getDaemonSensorValue(ASSIST_SENSOR_TYPE);
}
return lux;
}
public void stop() {
setSensorEnabled(false);
this.mDaemonSensorPolicy.stop();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment