Merge "Use SystemUI config to easily adjust udfps haptics" into sc-v2-dev

This commit is contained in:
Beverly Tai
2021-11-23 21:33:08 +00:00
committed by Android (Google) Code Review
2 changed files with 35 additions and 12 deletions

View File

@@ -595,6 +595,17 @@
280
</integer>
<!-- Haptic feedback intensity for ticks used for the udfps dwell time -->
<item name="config_udfpsTickIntensity" translatable="false" format="float"
type="dimen">.5</item>
<!-- Haptic feedback delay between ticks used for udfps dwell time -->
<integer name="config_udfpsTickDelay" translatable="false">25</integer>
<!-- Haptic feedback tick type - if true, uses VibrationEffect.Composition.PRIMITIVE_LOW_TICK
else uses VibrationEffect.Composition.PRIMITIVE_TICK -->
<bool name="config_udfpsUseLowTick">true</bool>
<!-- package name of a built-in camera app to use to restrict implicit intent resolution
when the double-press power gesture is used. Ignored if empty. -->
<string translatable="false" name="config_cameraGesturePackage"></string>

View File

@@ -163,7 +163,10 @@ public class UdfpsController implements DozeReceiver {
private boolean mOnFingerDown;
private boolean mAttemptedToDismissKeyguard;
private Set<Callback> mCallbacks = new HashSet<>();
private final VibrationEffect mLowTick;
// by default, use low tick
private int mPrimitiveTick = VibrationEffect.Composition.PRIMITIVE_LOW_TICK;
private final VibrationEffect mTick;
@VisibleForTesting
public static final AudioAttributes VIBRATION_SONIFICATION_ATTRIBUTES =
@@ -572,7 +575,7 @@ public class UdfpsController implements DozeReceiver {
mConfigurationController = configurationController;
mSystemClock = systemClock;
mUnlockedScreenOffAnimationController = unlockedScreenOffAnimationController;
mLowTick = lowTick();
mTick = lowTick();
mSensorProps = findFirstUdfps();
// At least one UDFPS sensor exists
@@ -608,22 +611,31 @@ public class UdfpsController implements DozeReceiver {
}
private VibrationEffect lowTick() {
boolean useLowTickDefault = mContext.getResources()
.getBoolean(R.bool.config_udfpsUseLowTick);
if (Settings.Global.getFloat(
mContext.getContentResolver(),
"tick-low", useLowTickDefault ? 1 : 0) == 0) {
mPrimitiveTick = VibrationEffect.Composition.PRIMITIVE_TICK;
}
float tickIntensity = Settings.Global.getFloat(
mContext.getContentResolver(), "low-tick-intensity", .5f);
VibrationEffect.Composition composition = VibrationEffect.startComposition();
composition.addPrimitive(VibrationEffect.Composition.PRIMITIVE_LOW_TICK,
tickIntensity, 0);
mContext.getContentResolver(),
"tick-intensity",
mContext.getResources().getFloat(R.dimen.config_udfpsTickIntensity));
int tickDelay = Settings.Global.getInt(
mContext.getContentResolver(), "low-tick-delay", 25);
mContext.getContentResolver(),
"tick-delay",
mContext.getResources().getInteger(R.integer.config_udfpsTickDelay));
VibrationEffect.Composition composition = VibrationEffect.startComposition();
composition.addPrimitive(mPrimitiveTick, tickIntensity, 0);
int primitives = 1000 / tickDelay;
float[] rampUp = new float[]{.48f, .58f, .69f, .83f};
for (int i = 0; i < rampUp.length; i++) {
composition.addPrimitive(VibrationEffect.Composition.PRIMITIVE_LOW_TICK,
tickIntensity * rampUp[i], tickDelay);
composition.addPrimitive(mPrimitiveTick, tickIntensity * rampUp[i], tickDelay);
}
for (int i = rampUp.length; i < primitives; i++) {
composition.addPrimitive(VibrationEffect.Composition.PRIMITIVE_LOW_TICK,
tickIntensity, tickDelay);
composition.addPrimitive(mPrimitiveTick, tickIntensity, tickDelay);
}
return composition.compose();
}
@@ -637,7 +649,7 @@ public class UdfpsController implements DozeReceiver {
mVibrator.vibrate(
Process.myUid(),
mContext.getOpPackageName(),
mLowTick,
mTick,
"udfps-onStart-tick",
VIBRATION_SONIFICATION_ATTRIBUTES);
}