cs40l26: Align Felix Hal with common HAL

Pull ag/22589260 to replace new/delete by using vector from the common
HAL.

Bug: 322648133
Test: idlcli compose commands
Test: adb shell cmd vibrator_manager synced prebaked 1
Test: adb shell idlcli vibrator compose 0 8 1.0; \
      sleep 1; adb shell idlcli vibrator compose 0 7 1.0;
Test: atest PtsVibratorHalTestSuite \
  PtsHapticsTestCases \
  VibratorHalCs40l26TestSuitePrivate \
  VtsHalVibratorManagerTargetTest \
  VtsHalVibratorTargetTest \
  android.os.cts.VibratorTest \
  android.os.cts.VibratorManagerTest \
  android.os.cts.VibrationEffectTest \
  android.os.cts.VibrationAttributesTest \
  android.os.cts.CombinedVibrationTest
Change-Id: Ia6e9111c47f27089521f05a68b538bbefb235d6b
This commit is contained in:
Ravi Jain 2024-03-21 15:16:14 +00:00
parent ad47d16718
commit 75d87040c7
3 changed files with 40 additions and 15 deletions

View file

@ -104,18 +104,25 @@ class HwApi : public Vibrator::HwApi, private HwApiBase {
.code = FF_GAIN,
.value = value,
};
if (value > 100) {
ALOGE("Invalid gain");
return false;
}
if (write(fd, (const void *)&gain, sizeof(gain)) != sizeof(gain)) {
return false;
}
return true;
}
bool setFFEffect(int fd, struct ff_effect *effect, uint16_t timeoutMs) override {
if (effect == nullptr) {
ALOGE("Invalid ff_effect");
return false;
}
if (ioctl(fd, EVIOCSFF, effect) < 0) {
ALOGE("setFFEffect fail");
return false;
} else {
return true;
}
return true;
}
bool setFFPlay(int fd, int8_t index, bool value) override {
struct input_event play = {
@ -186,14 +193,17 @@ class HwApi : public Vibrator::HwApi, private HwApiBase {
}
bool uploadOwtEffect(int fd, const uint8_t *owtData, const uint32_t numBytes, struct ff_effect *effect,
uint32_t *outEffectIndex, int *status) override {
(*effect).u.periodic.custom_len = numBytes / sizeof(uint16_t);
delete[] ((*effect).u.periodic.custom_data);
(*effect).u.periodic.custom_data = new int16_t[(*effect).u.periodic.custom_len]{0x0000};
if ((*effect).u.periodic.custom_data == nullptr) {
ALOGE("Failed to allocate memory for custom data\n");
if (owtData == nullptr || effect == nullptr || outEffectIndex == nullptr) {
ALOGE("Invalid argument owtData, ff_effect or outEffectIndex");
*status = EX_NULL_POINTER;
return false;
}
if (status == nullptr) {
ALOGE("Invalid argument status");
return false;
}
(*effect).u.periodic.custom_len = numBytes / sizeof(uint16_t);
memcpy((*effect).u.periodic.custom_data, owtData, numBytes);
if ((*effect).id != -1) {
@ -204,7 +214,6 @@ class HwApi : public Vibrator::HwApi, private HwApiBase {
(*effect).id = -1;
if (ioctl(fd, EVIOCSFF, effect) < 0) {
ALOGE("Failed to upload effect %d (%d): %s", *outEffectIndex, errno, strerror(errno));
delete[] ((*effect).u.periodic.custom_data);
*status = EX_ILLEGAL_STATE;
return false;
}