Adding GNSS Model & Version String

Bug: 38003769
Test: Device code & VTS builds, runs.
Todo in later phase: java connection.
Change-Id: Iddb2f25b18aba800e4f077d72c0452a417f78576
This commit is contained in:
Wyatt Riley 2017-11-07 17:39:29 -08:00
parent bbeae6fe23
commit 4d3c8e2c77
9 changed files with 381 additions and 0 deletions

19
gnss/1.1/Android.bp Normal file
View file

@ -0,0 +1,19 @@
// This file is autogenerated by hidl-gen -Landroidbp.
hidl_interface {
name: "android.hardware.gnss@1.1",
root: "android.hardware",
vndk: {
enabled: true,
},
srcs: [
"IGnss.hal",
"IGnssCallback.hal",
],
interfaces: [
"android.hardware.gnss@1.0",
"android.hidl.base@1.0",
],
gen_java: true,
}

34
gnss/1.1/IGnss.hal Normal file
View file

@ -0,0 +1,34 @@
/*
* 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.
*/
package android.hardware.gnss@1.1;
import @1.0::IGnss;
import IGnssCallback;
/** Represents the standard GNSS (Global Navigation Satellite System) interface. */
interface IGnss extends @1.0::IGnss {
/**
* Opens the interface and provides the callback routines
* to the implementation of this interface.
*
* @param callback Callback interface for IGnss.
*
* @return success Returns true on success.
*/
setCallback_1_1(IGnssCallback callback) generates (bool success);
};

View file

@ -0,0 +1,38 @@
/*
* 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.
*/
package android.hardware.gnss@1.1;
import @1.0::IGnssCallback;
/**
* The interface is required for the HAL to communicate certain information
* like status and location info back to the platform, the platform implements
* the interfaces and passes a handle to the HAL.
*/
interface IGnssCallback extends @1.0::IGnssCallback {
/**
* Callback to inform framework of the GNSS HAL implementation model & version name.
*
* This is a user-visible string that identifies the model and version of the GNSS HAL.
* For example "ABC Co., Baseband Part 1234, RF Part 567, Software version 3.14.159"
*
* This must be called in response to IGnss::setCallback
*
* @param name String providing the name of the GNSS HAL implementation
*/
gnssNameCb(string name);
};

6
gnss/1.1/vts/OWNERS Normal file
View file

@ -0,0 +1,6 @@
wyattriley@google.com
gomo@google.com
smalkos@google.com
# VTS team
yim@google.com

View file

@ -0,0 +1,29 @@
//
// 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.
//
cc_test {
name: "VtsHalGnssV1_1TargetTest",
defaults: ["VtsHalTargetTestDefaults"],
srcs: [
"gnss_hal_test.cpp",
"gnss_hal_test_cases.cpp",
"VtsHalGnssV1_1TargetTest.cpp",
],
static_libs: [
"android.hardware.gnss@1.0",
"android.hardware.gnss@1.1",
],
}

View file

@ -0,0 +1,24 @@
/*
* 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 <VtsHalHidlTargetTestBase.h>
int main(int argc, char** argv) {
::testing::InitGoogleTest(&argc, argv);
int status = RUN_ALL_TESTS();
ALOGI("Test result = %d", status);
return status;
}

View file

@ -0,0 +1,76 @@
/*
* 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.
*/
#define LOG_TAG "VtsHalGnssV1_1TargetTest"
#include <log/log.h>
#include <gnss_hal_test.h>
#include <chrono>
// Implementations for the main test class for GNSS HAL
GnssHalTest::GnssHalTest() : info_called_count_(0), name_called_count_(0), notify_count_(0) {}
void GnssHalTest::SetUp() {
gnss_hal_ = ::testing::VtsHalHidlTargetTestBase::getService<IGnss>();
ASSERT_NE(gnss_hal_, nullptr);
}
void GnssHalTest::TearDown() {
if (gnss_hal_ != nullptr) {
gnss_hal_->cleanup();
}
if (notify_count_ > 0) {
ALOGW("%d unprocessed callbacks discarded", notify_count_);
}
}
void GnssHalTest::notify() {
std::unique_lock<std::mutex> lock(mtx_);
notify_count_++;
cv_.notify_one();
}
std::cv_status GnssHalTest::wait(int timeoutSeconds) {
std::unique_lock<std::mutex> lock(mtx_);
auto status = std::cv_status::no_timeout;
while (notify_count_ == 0) {
status = cv_.wait_for(lock, std::chrono::seconds(timeoutSeconds));
if (status == std::cv_status::timeout) return status;
}
notify_count_--;
return status;
}
// Actual (test) callback handlers
Return<void> GnssHalTest::GnssCallback::gnssSetSystemInfoCb(
const IGnssCallback::GnssSystemInfo& info) {
ALOGI("Info received, year %d", info.yearOfHw);
parent_.info_called_count_++;
parent_.last_info_ = info;
parent_.notify();
return Void();
}
// Actual (test) callback handlers
Return<void> GnssHalTest::GnssCallback::gnssNameCb(const android::hardware::hidl_string& name) {
ALOGI("Name received: %s", name.c_str());
parent_.name_called_count_++;
parent_.last_name_ = name;
parent_.notify();
return Void();
}

View file

@ -0,0 +1,100 @@
/*
* 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.
*/
#ifndef GNSS_HAL_TEST_H_
#define GNSS_HAL_TEST_H_
#include <android/hardware/gnss/1.1/IGnss.h>
#include <VtsHalHidlTargetTestBase.h>
#include <condition_variable>
#include <mutex>
using android::hardware::Return;
using android::hardware::Void;
using android::hardware::gnss::V1_0::GnssLocation;
using android::hardware::gnss::V1_1::IGnss;
using android::hardware::gnss::V1_1::IGnssCallback;
using android::sp;
// The main test class for GNSS HAL.
class GnssHalTest : public ::testing::VtsHalHidlTargetTestBase {
public:
GnssHalTest();
virtual void SetUp() override;
virtual void TearDown() override;
/* Used as a mechanism to inform the test that a callback has occurred */
void notify();
/* Test code calls this function to wait for a callback */
std::cv_status wait(int timeoutSeconds);
/* Callback class for data & Event. */
class GnssCallback : public IGnssCallback {
public:
GnssHalTest& parent_;
GnssCallback(GnssHalTest& parent) : parent_(parent){};
virtual ~GnssCallback() = default;
// Dummy callback handlers
Return<void> gnssStatusCb(const IGnssCallback::GnssStatusValue /* status */) override {
return Void();
}
Return<void> gnssSvStatusCb(const IGnssCallback::GnssSvStatus& /* svStatus */) override {
return Void();
}
Return<void> gnssNmeaCb(int64_t /* timestamp */,
const android::hardware::hidl_string& /* nmea */) override {
return Void();
}
Return<void> gnssAcquireWakelockCb() override { return Void(); }
Return<void> gnssReleaseWakelockCb() override { return Void(); }
Return<void> gnssRequestTimeCb() override { return Void(); }
Return<void> gnssLocationCb(const GnssLocation& /* location */) override { return Void(); }
Return<void> gnssSetCapabilitesCb(uint32_t /* capabilities */) override { return Void(); }
// Actual (test) callback handlers
Return<void> gnssSetSystemInfoCb(const IGnssCallback::GnssSystemInfo& info) override;
Return<void> gnssNameCb(const android::hardware::hidl_string& name) override;
};
sp<IGnss> gnss_hal_; // GNSS HAL to call into
sp<IGnssCallback> gnss_cb_; // Primary callback interface
/* Count of calls to set the following items, and the latest item (used by
* test.)
*/
int info_called_count_;
IGnssCallback::GnssSystemInfo last_info_;
int name_called_count_;
android::hardware::hidl_string last_name_;
private:
std::mutex mtx_;
std::condition_variable cv_;
int notify_count_;
};
#endif // GNSS_HAL_TEST_H_

View file

@ -0,0 +1,55 @@
/*
* 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 <gnss_hal_test.h>
#include <VtsHalHidlTargetTestBase.h>
#define TIMEOUT_SEC 2 // for basic commands/responses
/*
* SetupTeardownCreateCleanup:
* Requests the gnss HAL then calls cleanup
*
* Empty test fixture to verify basic Setup & Teardown
*/
TEST_F(GnssHalTest, SetupTeardownCreateCleanup) {}
/*
* SetCallbackResponses:
* Sets up the callback, awaits the info & name
*/
TEST_F(GnssHalTest, SetCallbackResponses) {
gnss_cb_ = new GnssCallback(*this);
ASSERT_NE(gnss_cb_, nullptr);
auto result = gnss_hal_->setCallback_1_1(gnss_cb_);
if (!result.isOk()) {
ALOGE("result of failed setCallback %s", result.description().c_str());
}
ASSERT_TRUE(result.isOk());
ASSERT_TRUE(result);
/*
* Both name and systemInfo callbacks should trigger
*/
EXPECT_EQ(std::cv_status::no_timeout, wait(TIMEOUT_SEC));
EXPECT_EQ(std::cv_status::no_timeout, wait(TIMEOUT_SEC));
EXPECT_EQ(info_called_count_, 1);
EXPECT_EQ(name_called_count_, 1);
}