Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b3aa121d authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Add new vibrator effects."

parents 7a3b5644 ed5d92cc
Loading
Loading
Loading
Loading
+23 −0
Original line number Diff line number Diff line
// This file is autogenerated by hidl-gen -Landroidbp.

hidl_interface {
    name: "android.hardware.vibrator@1.2",
    root: "android.hardware",
    vndk: {
        enabled: true,
    },
    srcs: [
        "types.hal",
        "IVibrator.hal",
    ],
    interfaces: [
        "android.hardware.vibrator@1.0",
        "android.hardware.vibrator@1.1",
        "android.hidl.base@1.0",
    ],
    types: [
        "Effect",
    ],
    gen_java: true,
}
+37 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2018 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.hardware.vibrator@1.2;

import @1.0::EffectStrength;
import @1.0::Status;
import @1.1::IVibrator;

interface IVibrator extends @1.1::IVibrator {
  /**
   * Fire off a predefined haptic event.
   *
   * @param event The type of haptic event to trigger.
   * @return status Whether the effect was successfully performed or not. Must
   *     return Status::UNSUPPORTED_OPERATION is the effect is not supported.
   * @return lengthMs The length of time the event is expected to take in
   *     milliseconds. This doesn't need to be perfectly accurate, but should be a reasonable
   *     approximation. Should be a positive, non-zero value if the returned status is Status::OK,
   *     and set to 0 otherwise.
   */
  perform_1_2(Effect effect, EffectStrength strength)
          generates (Status status, uint32_t lengthMs);
};

vibrator/1.2/types.hal

0 → 100644
+64 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2018 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.hardware.vibrator@1.2;

import @1.1::Effect_1_1;

// Note that while the previous type had a version suffix, this type does not. This is because the
// versions are already present in the namespace and thus don't need to also be embedded in the
// name of the type.
enum Effect : @1.1::Effect_1_1 {
     /**
      * A thud effect.
      *
      * This effect should solid feeling bump, like the depression of a heavy mechanical button.
      */
     THUD,
     /**
      * A pop effect.
      *
      * A short, quick burst effect.
      */
     POP,

     /**
      * A heavy click effect.
      *
      * This should produce a sharp striking sensation, like a click but stronger.
      */
     HEAVY_CLICK,

     /**
      * Ringtone patterns. They may correspond with the device's ringtone audio, or may just be a
      * pattern that can be played as a ringtone with any audio, depending on the device.
      */
     RINGTONE_1,
     RINGTONE_2,
     RINGTONE_3,
     RINGTONE_4,
     RINGTONE_5,
     RINGTONE_6,
     RINGTONE_7,
     RINGTONE_8,
     RINGTONE_9,
     RINGTONE_10,
     RINGTONE_11,
     RINGTONE_12,
     RINGTONE_13,
     RINGTONE_14,
     RINGTONE_15,
};
+27 −0
Original line number Diff line number Diff line
//
// Copyright (C) 2018 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

cc_test {
    name: "VtsHalVibratorV1_2TargetTest",
    defaults: ["VtsHalTargetTestDefaults"],
    srcs: ["VtsHalVibratorV1_2TargetTest.cpp"],
    static_libs: [
        "android.hardware.vibrator@1.0",
        "android.hardware.vibrator@1.1",
        "android.hardware.vibrator@1.2",
    ],
}
+72 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2018 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#define LOG_TAG "vibrator_hidl_hal_test"

#include <VtsHalHidlTargetTestBase.h>
#include <android-base/logging.h>
#include <android/hardware/vibrator/1.0/types.h>
#include <android/hardware/vibrator/1.2/IVibrator.h>
#include <android/hardware/vibrator/1.2/types.h>
#include <unistd.h>

using ::android::hardware::vibrator::V1_0::Status;
using ::android::hardware::vibrator::V1_0::EffectStrength;
using ::android::hardware::vibrator::V1_2::Effect;
using ::android::hardware::vibrator::V1_2::IVibrator;
using ::android::hardware::hidl_enum_iterator;
using ::android::hardware::Return;
using ::android::hardware::Void;
using ::android::sp;

// The main test class for VIBRATOR HIDL HAL 1.2.
class VibratorHidlTest_1_2 : public ::testing::VtsHalHidlTargetTestBase {
   public:
    virtual void SetUp() override {
        vibrator = ::testing::VtsHalHidlTargetTestBase::getService<IVibrator>();
        ASSERT_NE(vibrator, nullptr);
    }

    virtual void TearDown() override {}

    sp<IVibrator> vibrator;
};

static void validatePerformEffect(Status status, uint32_t lengthMs) {
    ASSERT_TRUE(status == Status::OK || status == Status::UNSUPPORTED_OPERATION);
    if (status == Status::OK) {
        ASSERT_GT(lengthMs, static_cast<uint32_t>(0))
            << "Effects that return OK must return a non-zero duration";
    } else {
        ASSERT_EQ(lengthMs, static_cast<uint32_t>(0))
            << "Effects that return UNSUPPORTED_OPERATION must have a duration of zero";
    }
}

TEST_F(VibratorHidlTest_1_2, PerformEffect_1_2) {
    for (const auto& effect : hidl_enum_iterator<Effect>()) {
        for (const auto& strength : hidl_enum_iterator<EffectStrength>()) {
            vibrator->perform_1_2(effect, strength, validatePerformEffect);
        }
    }
}

int main(int argc, char** argv) {
    ::testing::InitGoogleTest(&argc, argv);
    int status = RUN_ALL_TESTS();
    LOG(INFO) << "Test result = " << status;
    return status;
}