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

Commit 9cf96452 authored by android-build-team Robot's avatar android-build-team Robot
Browse files

release-request-1b0d6769-ebfa-4e2d-b128-039ac0dcd5c9-for-git_oc-mr1-release-41...

release-request-1b0d6769-ebfa-4e2d-b128-039ac0dcd5c9-for-git_oc-mr1-release-4140700 snap-temp-L81200000078275553

Change-Id: I850a95616e260d2e79f54ffdb0a9a82fb2c978ab
parents e57d13b0 84091d58
Loading
Loading
Loading
Loading
+71 −42
Original line number Diff line number Diff line
@@ -228,6 +228,7 @@ class BroadcastRadioHidlTest : public ::testing::VtsHalHidlTargetTestBase,
    bool getProperties();
    bool openTuner();
    bool checkAntenna();
    BandConfig& getBand(unsigned idx);

    static const nsecs_t kConnectCallbacktimeoutNs = seconds_to_nanoseconds(1);
    static const nsecs_t kConfigCallbacktimeoutNs = seconds_to_nanoseconds(10);
@@ -237,6 +238,7 @@ class BroadcastRadioHidlTest : public ::testing::VtsHalHidlTargetTestBase,
    bool skipped;
    sp<IBroadcastRadio> mRadio;
    Properties mHalProperties;
    bool mHalPropertiesInitialized = false;
    sp<ITuner> mTuner;
    sp<MyCallback> mTunerCallback;
    Mutex mLock;
@@ -280,10 +282,10 @@ static bool operator==(const BandConfig& l, const BandConfig& r) {

bool BroadcastRadioHidlTest::getProperties()
{
    if (mHalProperties.bands.size() == 0) {
    if (mHalPropertiesInitialized) return true;

    Result halResult = Result::NOT_INITIALIZED;
        Return<void> hidlReturn =
                mRadio->getProperties([&](Result result, const Properties& properties) {
    auto hidlReturn = mRadio->getProperties([&](Result result, const Properties& properties) {
        halResult = result;
        if (result == Result::OK) {
            mHalProperties = properties;
@@ -292,11 +294,17 @@ bool BroadcastRadioHidlTest::getProperties()

    EXPECT_TRUE(hidlReturn.isOk());
    EXPECT_EQ(Result::OK, halResult);
        EXPECT_EQ(Class::AM_FM, mHalProperties.classId);
    EXPECT_EQ(radioClass, mHalProperties.classId);
    EXPECT_GT(mHalProperties.numTuners, 0u);
    if (radioClass == Class::AM_FM) {
        EXPECT_GT(mHalProperties.bands.size(), 0u);
    }
    return mHalProperties.bands.size() > 0;

    if (hidlReturn.isOk() && halResult == Result::OK) {
        mHalPropertiesInitialized = true;
        return true;
    }
    return false;
}

bool BroadcastRadioHidlTest::openTuner()
@@ -306,24 +314,27 @@ bool BroadcastRadioHidlTest::openTuner()
    }
    if (mTuner.get() == nullptr) {
        Result halResult = Result::NOT_INITIALIZED;
        Return<void> hidlReturn =
                mRadio->openTuner(mHalProperties.bands[0], true, mTunerCallback,
                                  [&](Result result, const sp<ITuner>& tuner) {
        auto openCb = [&](Result result, const sp<ITuner>& tuner) {
            halResult = result;
            if (result == Result::OK) {
                mTuner = tuner;
            }
                    });
        };
        auto hidlReturn = mRadio->openTuner(getBand(0), true, mTunerCallback, openCb);
        EXPECT_TRUE(hidlReturn.isOk());
        EXPECT_EQ(Result::OK, halResult);
        if (radioClass == Class::AM_FM) {
            EXPECT_EQ(true, waitForCallback(kConfigCallbacktimeoutNs));
        }
    }
    EXPECT_NE(nullptr, mTuner.get());
    return nullptr != mTuner.get();
}

bool BroadcastRadioHidlTest::checkAntenna()
{
    if (radioClass != Class::AM_FM) return true;

    BandConfig halConfig;
    Result halResult = Result::NOT_INITIALIZED;
    Return<void> hidlReturn =
@@ -337,6 +348,19 @@ bool BroadcastRadioHidlTest::checkAntenna()
    return ((halResult == Result::OK) && (halConfig.antennaConnected == true));
}

BandConfig& BroadcastRadioHidlTest::getBand(unsigned idx) {
    static BandConfig dummyBandConfig = {};
    if (radioClass == Class::AM_FM) {
        EXPECT_GT(mHalProperties.bands.size(), idx);
        if (mHalProperties.bands.size() > idx) {
            return mHalProperties.bands[idx];
        } else {
            return dummyBandConfig;
        }
    } else {
        return dummyBandConfig;
    }
}

/**
 * Test IBroadcastRadio::getProperties() method
@@ -344,7 +368,7 @@ bool BroadcastRadioHidlTest::checkAntenna()
 * Verifies that:
 *  - the HAL implements the method
 *  - the method returns 0 (no error)
 *  - the implementation class is AM_FM
 *  - the implementation class is radioClass
 *  - the implementation supports at least one tuner
 *  - the implementation supports at one band
 */
@@ -383,23 +407,21 @@ TEST_P(BroadcastRadioHidlTest, ReopenTuner) {
 * Test IBroadcastRadio::openTuner() method called twice.
 *
 * Verifies that:
 *  - the openTuner method fails when called for the second time without deleting previous
 *    ITuner instance
 *  - the openTuner method fails with INVALID_STATE or succeeds when called for the second time
 *    without deleting previous ITuner instance
 */
TEST_P(BroadcastRadioHidlTest, OpenTunerTwice) {
    RETURN_IF_SKIPPED;
    EXPECT_TRUE(openTuner());

    Result halResult = Result::NOT_INITIALIZED;
    Return<void> hidlReturn =
            mRadio->openTuner(mHalProperties.bands[0], true, mTunerCallback,
                              [&](Result result, const sp<ITuner>&) {
                    halResult = result;
                });
    auto openCb = [&](Result result, const sp<ITuner>&) { halResult = result; };
    auto hidlReturn = mRadio->openTuner(getBand(0), true, mTunerCallback, openCb);
    EXPECT_TRUE(hidlReturn.isOk());
    EXPECT_EQ(Result::INVALID_STATE, halResult);
    if (halResult == Result::INVALID_STATE) {
        EXPECT_TRUE(waitForCallback(kConfigCallbacktimeoutNs));
    }
}

/**
 * Test ITuner::setConfiguration() and getConfiguration methods
@@ -411,16 +433,17 @@ TEST_P(BroadcastRadioHidlTest, OpenTunerTwice) {
 *  - the configuration read back from HAl has the same class Id
 */
TEST_P(BroadcastRadioHidlTest, SetAndGetConfiguration) {
    if (radioClass != Class::AM_FM) skipped = true;
    RETURN_IF_SKIPPED;
    ASSERT_EQ(true, openTuner());
    // test setConfiguration
    mCallbackCalled = false;
    Return<Result> hidlResult = mTuner->setConfiguration(mHalProperties.bands[1]);
    Return<Result> hidlResult = mTuner->setConfiguration(getBand(1));
    EXPECT_TRUE(hidlResult.isOk());
    EXPECT_EQ(Result::OK, hidlResult);
    EXPECT_EQ(true, waitForCallback(kConfigCallbacktimeoutNs));
    EXPECT_EQ(Result::OK, mResultCallbackData);
    EXPECT_EQ(mHalProperties.bands[1], mBandConfigCallbackData);
    EXPECT_EQ(getBand(1), mBandConfigCallbackData);

    // test getConfiguration
    BandConfig halConfig;
@@ -434,7 +457,7 @@ TEST_P(BroadcastRadioHidlTest, SetAndGetConfiguration) {
            });
    EXPECT_TRUE(hidlReturn.isOk());
    EXPECT_EQ(Result::OK, halResult);
    EXPECT_EQ(mHalProperties.bands[1], halConfig);
    EXPECT_EQ(getBand(1), halConfig);
}

/**
@@ -445,6 +468,7 @@ TEST_P(BroadcastRadioHidlTest, SetAndGetConfiguration) {
 *  - the method recovers and succeeds after passing correct arguments
 */
TEST_P(BroadcastRadioHidlTest, SetConfigurationFails) {
    if (radioClass != Class::AM_FM) skipped = true;
    RETURN_IF_SKIPPED;
    ASSERT_EQ(true, openTuner());

@@ -463,7 +487,7 @@ TEST_P(BroadcastRadioHidlTest, SetConfigurationFails) {

    // Test setConfiguration recovering after passing good data.
    mCallbackCalled = false;
    setResult = mTuner->setConfiguration(mHalProperties.bands[0]);
    setResult = mTuner->setConfiguration(getBand(0));
    EXPECT_TRUE(setResult.isOk());
    EXPECT_EQ(Result::OK, setResult);
    EXPECT_EQ(true, waitForCallback(kConfigCallbacktimeoutNs));
@@ -508,6 +532,7 @@ TEST_P(BroadcastRadioHidlTest, Scan) {
 *  - skipping sub-channel or not does not fail the call
 */
TEST_P(BroadcastRadioHidlTest, Step) {
    if (radioClass != Class::AM_FM) skipped = true;
    RETURN_IF_SKIPPED;
    ASSERT_EQ(true, openTuner());
    ASSERT_TRUE(checkAntenna());
@@ -535,18 +560,21 @@ TEST_P(BroadcastRadioHidlTest, Step) {
 *  - the tuned callback is received within kTuneCallbacktimeoutNs ns after tune()
 */
TEST_P(BroadcastRadioHidlTest, TuneAndGetProgramInformationAndCancel) {
    if (radioClass != Class::AM_FM) skipped = true;
    RETURN_IF_SKIPPED;
    ASSERT_EQ(true, openTuner());
    ASSERT_TRUE(checkAntenna());

    auto& band = getBand(0);

    // test tune
    ASSERT_GT(mHalProperties.bands[0].spacings.size(), 0u);
    ASSERT_GT(mHalProperties.bands[0].upperLimit, mHalProperties.bands[0].lowerLimit);
    ASSERT_GT(band.spacings.size(), 0u);
    ASSERT_GT(band.upperLimit, band.lowerLimit);

    // test scan UP
    uint32_t lowerLimit = mHalProperties.bands[0].lowerLimit;
    uint32_t upperLimit = mHalProperties.bands[0].upperLimit;
    uint32_t spacing = mHalProperties.bands[0].spacings[0];
    uint32_t lowerLimit = band.lowerLimit;
    uint32_t upperLimit = band.upperLimit;
    uint32_t spacing = band.spacings[0];

    uint32_t channel =
            lowerLimit + (((upperLimit - lowerLimit) / 2 + spacing - 1) / spacing) * spacing;
@@ -593,6 +621,7 @@ TEST_P(BroadcastRadioHidlTest, TuneAndGetProgramInformationAndCancel) {
 *  - the method recovers and succeeds after passing correct arguments
 */
TEST_P(BroadcastRadioHidlTest, TuneFailsOutOfBounds) {
    if (radioClass != Class::AM_FM) skipped = true;
    RETURN_IF_SKIPPED;
    ASSERT_TRUE(openTuner());
    ASSERT_TRUE(checkAntenna());
+1 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@

#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include "CameraParameters.h"
#include <system/graphics.h>

+36 −0
Original line number Diff line number Diff line
//
// Copyright (C) 2016 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: "VtsHalOemLockV1_0TargetTest",
    defaults: ["hidl_defaults"],
    srcs: ["VtsHalOemLockV1_0TargetTest.cpp"],
    shared_libs: [
        "libbase",
        "liblog",
        "libcutils",
        "libhidlbase",
        "libhidltransport",
        "libnativehelper",
        "libutils",
        "android.hardware.oemlock@1.0",
    ],
    static_libs: ["VtsHalHidlTargetTestBase"],
    cflags: [
        "-O0",
        "-g",
    ],
}
+189 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2017 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.
 */

#include <android/hardware/oemlock/1.0/IOemLock.h>

#include <VtsHalHidlTargetTestBase.h>

using ::android::hardware::oemlock::V1_0::IOemLock;
using ::android::hardware::oemlock::V1_0::OemLockStatus;
using ::android::hardware::oemlock::V1_0::OemLockSecureStatus;
using ::android::hardware::hidl_string;
using ::android::hardware::hidl_vec;
using ::android::sp;

struct OemLockHidlTest : public ::testing::VtsHalHidlTargetTestBase {
    virtual void SetUp() override {
        oemlock = ::testing::VtsHalHidlTargetTestBase::getService<IOemLock>();
        ASSERT_NE(oemlock, nullptr);
    }

    virtual void TearDown() override {}

    sp<IOemLock> oemlock;
};

/*
 * Check the name can be retrieved
 */
TEST_F(OemLockHidlTest, GetName) {
    std::string name;
    OemLockStatus status;

    bool callbackCalled = false;
    const auto ret = oemlock->getName([&](OemLockStatus s, hidl_string n) {
        callbackCalled = true;
        status = s;
        name = n.c_str();
    });

    ASSERT_TRUE(ret.isOk());
    ASSERT_TRUE(callbackCalled);
    EXPECT_EQ(status, OemLockStatus::OK);
    // Any value acceptable
};

/*
 * Check the unlock allowed by device state can be queried
 */
TEST_F(OemLockHidlTest, QueryUnlockAllowedByDevice) {
    bool allowed;
    OemLockStatus status;

    bool callbackCalled = false;
    const auto ret = oemlock->isOemUnlockAllowedByDevice([&](OemLockStatus s, bool a) {
        callbackCalled = true;
        status = s;
        allowed = a;
    });

    ASSERT_TRUE(ret.isOk());
    ASSERT_TRUE(callbackCalled);
    EXPECT_EQ(status, OemLockStatus::OK);
    // Any value acceptable
}

/*
 * Check unlock allowed by device state can be toggled
 */
TEST_F(OemLockHidlTest, AllowedByDeviceCanBeToggled) {
    bool allowed;
    OemLockStatus status;

    auto getAllowedCallback = [&](OemLockStatus s, bool a) {
        status = s;
        allowed = a;
    };

    // Get the original state so it can be restored
    const auto get_ret = oemlock->isOemUnlockAllowedByDevice(getAllowedCallback);
    ASSERT_TRUE(get_ret.isOk());
    ASSERT_EQ(status, OemLockStatus::OK);
    const bool originallyAllowed = allowed;

    // Toggle the state
    const auto set_ret = oemlock->setOemUnlockAllowedByDevice(!originallyAllowed);
    ASSERT_TRUE(set_ret.isOk());
    ASSERT_EQ(set_ret, OemLockStatus::OK);
    const auto check_set_ret = oemlock->isOemUnlockAllowedByDevice(getAllowedCallback);
    ASSERT_TRUE(check_set_ret.isOk());
    ASSERT_EQ(status, OemLockStatus::OK);
    ASSERT_EQ(allowed, !originallyAllowed);

    // Restore the state
    const auto restore_ret = oemlock->setOemUnlockAllowedByDevice(originallyAllowed);
    ASSERT_TRUE(restore_ret.isOk());
    ASSERT_EQ(restore_ret, OemLockStatus::OK);
    const auto check_restore_ret = oemlock->isOemUnlockAllowedByDevice(getAllowedCallback);
    ASSERT_TRUE(check_restore_ret.isOk());
    ASSERT_EQ(status, OemLockStatus::OK);
    ASSERT_EQ(allowed, originallyAllowed);
};

/*
 * Check the unlock allowed by device state can be queried
 */
TEST_F(OemLockHidlTest, QueryUnlockAllowedByCarrier) {
    bool allowed;
    OemLockStatus status;

    bool callbackCalled = false;
    const auto ret = oemlock->isOemUnlockAllowedByCarrier([&](OemLockStatus s, bool a) {
        callbackCalled = true;
        status = s;
        allowed = a;
    });

    ASSERT_TRUE(ret.isOk());
    ASSERT_TRUE(callbackCalled);
    EXPECT_EQ(status, OemLockStatus::OK);
    // Any value acceptable
}

/*
 * Attempt to check unlock allowed by carrier can be toggled
 *
 * The implementation may involve a signature which cannot be tested here. That
 * is a valid implementation so the test will pass. If there is no signature
 * required, the test will toggle the value.
 */
TEST_F(OemLockHidlTest, CarrierUnlock) {
    const hidl_vec<uint8_t> noSignature = {};
    bool allowed;
    OemLockStatus status;

    auto getAllowedCallback = [&](OemLockStatus s, bool a) {
        status = s;
        allowed = a;
    };

    // Get the original state so it can be restored
    const auto get_ret = oemlock->isOemUnlockAllowedByCarrier(getAllowedCallback);
    ASSERT_TRUE(get_ret.isOk());
    ASSERT_EQ(status, OemLockStatus::OK);
    const bool originallyAllowed = allowed;

    if (originallyAllowed) {
        // Only applied to locked devices
        return;
    }

    // Toggle the state
    const auto set_ret = oemlock->setOemUnlockAllowedByCarrier(!originallyAllowed, noSignature);
    ASSERT_TRUE(set_ret.isOk());
    ASSERT_NE(set_ret, OemLockSecureStatus::FAILED);
    const auto check_set_ret = oemlock->isOemUnlockAllowedByCarrier(getAllowedCallback);
    ASSERT_TRUE(check_set_ret.isOk());
    ASSERT_EQ(status, OemLockStatus::OK);

    if (set_ret == OemLockSecureStatus::INVALID_SIGNATURE) {
        // Signature is required so we cannot toggle the value in the test, but this is allowed
        ASSERT_EQ(allowed, originallyAllowed);
        return;
    }

    ASSERT_EQ(set_ret, OemLockSecureStatus::OK);
    ASSERT_EQ(allowed, !originallyAllowed);

    // Restore the state
    const auto restore_ret = oemlock->setOemUnlockAllowedByCarrier(originallyAllowed, noSignature);
    ASSERT_TRUE(restore_ret.isOk());
    ASSERT_EQ(restore_ret, OemLockSecureStatus::OK);
    const auto check_restore_ret = oemlock->isOemUnlockAllowedByCarrier(getAllowedCallback);
    ASSERT_TRUE(check_restore_ret.isOk());
    ASSERT_EQ(status, OemLockStatus::OK);
    ASSERT_EQ(allowed, originallyAllowed);
};
+1 −0
Original line number Diff line number Diff line
// This is an autogenerated file, do not edit.
subdirs = [
    "1.0",
    "1.0/vts/functional",
]