diff options
author | android-build-team Robot | 2018-05-06 02:25:59 -0500 |
---|---|---|
committer | android-build-team Robot | 2018-05-06 02:25:59 -0500 |
commit | 32ca66c03527f950edd09c29b89009da42ff26e5 (patch) | |
tree | 44612d89789f121c3cee5e3e697a795d41ed8ae4 | |
parent | 16ba7ece2bf05b942d733b5319479bd58ba15298 (diff) | |
parent | 8f3b492c83fb2a01e95e3edc8a4bda1471c7aa3d (diff) | |
download | platform-hardware-interfaces-32ca66c03527f950edd09c29b89009da42ff26e5.tar.gz platform-hardware-interfaces-32ca66c03527f950edd09c29b89009da42ff26e5.tar.xz platform-hardware-interfaces-32ca66c03527f950edd09c29b89009da42ff26e5.zip |
Snap for 4765094 from 8f3b492c83fb2a01e95e3edc8a4bda1471c7aa3d to pi-release
Change-Id: I82690c3829d09ac79465e6b977b08c4f853d749b
8 files changed, 207 insertions, 112 deletions
diff --git a/audio/common/all-versions/test/utility/include/utility/PrettyPrintAudioTypes.h b/audio/common/all-versions/test/utility/include/utility/PrettyPrintAudioTypes.h index 05239acc..abc2ff5f 100644 --- a/audio/common/all-versions/test/utility/include/utility/PrettyPrintAudioTypes.h +++ b/audio/common/all-versions/test/utility/include/utility/PrettyPrintAudioTypes.h | |||
@@ -41,6 +41,7 @@ namespace audio { | |||
41 | inline void PrintTo(const T& val, ::std::ostream* os) { *os << toString(val); } | 41 | inline void PrintTo(const T& val, ::std::ostream* os) { *os << toString(val); } |
42 | 42 | ||
43 | namespace AUDIO_HAL_VERSION { | 43 | namespace AUDIO_HAL_VERSION { |
44 | DEFINE_GTEST_PRINT_TO(IPrimaryDevice::TtyMode) | ||
44 | DEFINE_GTEST_PRINT_TO(Result) | 45 | DEFINE_GTEST_PRINT_TO(Result) |
45 | } // namespace AUDIO_HAL_VERSION | 46 | } // namespace AUDIO_HAL_VERSION |
46 | 47 | ||
diff --git a/audio/core/4.0/vts/functional/AudioPrimaryHidlHalTest.cpp b/audio/core/4.0/vts/functional/AudioPrimaryHidlHalTest.cpp index 0bf32b57..c764ea62 100644 --- a/audio/core/4.0/vts/functional/AudioPrimaryHidlHalTest.cpp +++ b/audio/core/4.0/vts/functional/AudioPrimaryHidlHalTest.cpp | |||
@@ -22,6 +22,7 @@ | |||
22 | #include <cstdio> | 22 | #include <cstdio> |
23 | #include <initializer_list> | 23 | #include <initializer_list> |
24 | #include <limits> | 24 | #include <limits> |
25 | #include <list> | ||
25 | #include <string> | 26 | #include <string> |
26 | #include <vector> | 27 | #include <vector> |
27 | 28 | ||
@@ -51,6 +52,7 @@ using std::initializer_list; | |||
51 | using std::string; | 52 | using std::string; |
52 | using std::to_string; | 53 | using std::to_string; |
53 | using std::vector; | 54 | using std::vector; |
55 | using std::list; | ||
54 | 56 | ||
55 | using ::android::sp; | 57 | using ::android::sp; |
56 | using ::android::hardware::Return; | 58 | using ::android::hardware::Return; |
@@ -104,6 +106,7 @@ using namespace ::android::hardware::audio::common::test::utility; | |||
104 | static auto okOrNotSupported = {Result::OK, Result::NOT_SUPPORTED}; | 106 | static auto okOrNotSupported = {Result::OK, Result::NOT_SUPPORTED}; |
105 | static auto okOrNotSupportedOrInvalidArgs = {Result::OK, Result::NOT_SUPPORTED, | 107 | static auto okOrNotSupportedOrInvalidArgs = {Result::OK, Result::NOT_SUPPORTED, |
106 | Result::INVALID_ARGUMENTS}; | 108 | Result::INVALID_ARGUMENTS}; |
109 | static auto invalidArgsOrNotSupported = {Result::INVALID_ARGUMENTS, Result::NOT_SUPPORTED}; | ||
107 | 110 | ||
108 | class AudioHidlTestEnvironment : public ::Environment { | 111 | class AudioHidlTestEnvironment : public ::Environment { |
109 | public: | 112 | public: |
@@ -212,53 +215,59 @@ TEST_F(AudioPrimaryHidlTest, Init) { | |||
212 | template <class Property> | 215 | template <class Property> |
213 | class AccessorPrimaryHidlTest : public AudioPrimaryHidlTest { | 216 | class AccessorPrimaryHidlTest : public AudioPrimaryHidlTest { |
214 | protected: | 217 | protected: |
215 | /** Test a property getter and setter. */ | 218 | enum Optionality { REQUIRED, OPTIONAL }; |
216 | template <class Getter, class Setter> | 219 | struct Initial { // Initial property value |
217 | void testAccessors(const string& propertyName, const vector<Property>& valuesToTest, | 220 | Initial(Property value, Optionality check = REQUIRED) : value(value), check(check) {} |
218 | Setter setter, Getter getter, const vector<Property>& invalidValues = {}) { | 221 | Property value; |
219 | Property initialValue; // Save initial value to restore it at the end | 222 | Optionality check; // If this initial value should be checked |
220 | // of the test | 223 | }; |
224 | /** Test a property getter and setter. | ||
225 | * The getter and/or the setter may return NOT_SUPPORTED if optionality == OPTIONAL. | ||
226 | */ | ||
227 | template <Optionality optionality = REQUIRED, class Getter, class Setter> | ||
228 | void testAccessors(const string& propertyName, const Initial expectedInitial, | ||
229 | list<Property> valuesToTest, Setter setter, Getter getter, | ||
230 | const vector<Property>& invalidValues = {}) { | ||
231 | const auto expectedResults = {Result::OK, | ||
232 | optionality == OPTIONAL ? Result::NOT_SUPPORTED : Result::OK}; | ||
233 | |||
234 | Property initialValue = expectedInitial.value; | ||
221 | ASSERT_OK((device.get()->*getter)(returnIn(res, initialValue))); | 235 | ASSERT_OK((device.get()->*getter)(returnIn(res, initialValue))); |
222 | ASSERT_OK(res); | 236 | ASSERT_RESULT(expectedResults, res); |
237 | if (res == Result::OK && expectedInitial.check == REQUIRED) { | ||
238 | EXPECT_EQ(expectedInitial.value, initialValue); | ||
239 | } | ||
223 | 240 | ||
241 | valuesToTest.push_front(expectedInitial.value); | ||
242 | valuesToTest.push_back(initialValue); | ||
224 | for (Property setValue : valuesToTest) { | 243 | for (Property setValue : valuesToTest) { |
225 | SCOPED_TRACE("Test " + propertyName + " getter and setter for " + | 244 | SCOPED_TRACE("Test " + propertyName + " getter and setter for " + |
226 | testing::PrintToString(setValue)); | 245 | testing::PrintToString(setValue)); |
227 | ASSERT_OK((device.get()->*setter)(setValue)); | 246 | auto ret = (device.get()->*setter)(setValue); |
247 | ASSERT_RESULT(expectedResults, ret); | ||
248 | if (ret == Result::NOT_SUPPORTED) { | ||
249 | doc::partialTest(propertyName + " setter is not supported"); | ||
250 | break; | ||
251 | } | ||
228 | Property getValue; | 252 | Property getValue; |
229 | // Make sure the getter returns the same value just set | 253 | // Make sure the getter returns the same value just set |
230 | ASSERT_OK((device.get()->*getter)(returnIn(res, getValue))); | 254 | ASSERT_OK((device.get()->*getter)(returnIn(res, getValue))); |
231 | ASSERT_OK(res); | 255 | ASSERT_RESULT(expectedResults, res); |
256 | if (res == Result::NOT_SUPPORTED) { | ||
257 | doc::partialTest(propertyName + " getter is not supported"); | ||
258 | continue; | ||
259 | } | ||
232 | EXPECT_EQ(setValue, getValue); | 260 | EXPECT_EQ(setValue, getValue); |
233 | } | 261 | } |
234 | 262 | ||
235 | for (Property invalidValue : invalidValues) { | 263 | for (Property invalidValue : invalidValues) { |
236 | SCOPED_TRACE("Try to set " + propertyName + " with the invalid value " + | 264 | SCOPED_TRACE("Try to set " + propertyName + " with the invalid value " + |
237 | testing::PrintToString(invalidValue)); | 265 | testing::PrintToString(invalidValue)); |
238 | EXPECT_RESULT(Result::INVALID_ARGUMENTS, (device.get()->*setter)(invalidValue)); | 266 | EXPECT_RESULT(invalidArgsOrNotSupported, (device.get()->*setter)(invalidValue)); |
239 | } | 267 | } |
240 | 268 | ||
241 | ASSERT_OK((device.get()->*setter)(initialValue)); // restore initial value | 269 | // Restore initial value |
242 | } | 270 | EXPECT_RESULT(expectedResults, (device.get()->*setter)(initialValue)); |
243 | |||
244 | /** Test the getter and setter of an optional feature. */ | ||
245 | template <class Getter, class Setter> | ||
246 | void testOptionalAccessors(const string& propertyName, const vector<Property>& valuesToTest, | ||
247 | Setter setter, Getter getter, | ||
248 | const vector<Property>& invalidValues = {}) { | ||
249 | doc::test("Test the optional " + propertyName + " getters and setter"); | ||
250 | { | ||
251 | SCOPED_TRACE("Test feature support by calling the getter"); | ||
252 | Property initialValue; | ||
253 | ASSERT_OK((device.get()->*getter)(returnIn(res, initialValue))); | ||
254 | if (res == Result::NOT_SUPPORTED) { | ||
255 | doc::partialTest(propertyName + " getter is not supported"); | ||
256 | return; | ||
257 | } | ||
258 | ASSERT_OK(res); // If it is supported it must succeed | ||
259 | } | ||
260 | // The feature is supported, test it | ||
261 | testAccessors(propertyName, valuesToTest, setter, getter, invalidValues); | ||
262 | } | 271 | } |
263 | }; | 272 | }; |
264 | 273 | ||
@@ -266,24 +275,22 @@ using BoolAccessorPrimaryHidlTest = AccessorPrimaryHidlTest<bool>; | |||
266 | 275 | ||
267 | TEST_F(BoolAccessorPrimaryHidlTest, MicMuteTest) { | 276 | TEST_F(BoolAccessorPrimaryHidlTest, MicMuteTest) { |
268 | doc::test("Check that the mic can be muted and unmuted"); | 277 | doc::test("Check that the mic can be muted and unmuted"); |
269 | testAccessors("mic mute", {true, false, true}, &IDevice::setMicMute, &IDevice::getMicMute); | 278 | testAccessors("mic mute", Initial{false}, {true}, &IDevice::setMicMute, &IDevice::getMicMute); |
270 | // TODO: check that the mic is really muted (all sample are 0) | 279 | // TODO: check that the mic is really muted (all sample are 0) |
271 | } | 280 | } |
272 | 281 | ||
273 | TEST_F(BoolAccessorPrimaryHidlTest, MasterMuteTest) { | 282 | TEST_F(BoolAccessorPrimaryHidlTest, MasterMuteTest) { |
274 | doc::test( | 283 | doc::test("If master mute is supported, try to mute and unmute the master output"); |
275 | "If master mute is supported, try to mute and unmute the master " | 284 | testAccessors<OPTIONAL>("master mute", Initial{false}, {true}, &IDevice::setMasterMute, |
276 | "output"); | 285 | &IDevice::getMasterMute); |
277 | testOptionalAccessors("master mute", {true, false, true}, &IDevice::setMasterMute, | ||
278 | &IDevice::getMasterMute); | ||
279 | // TODO: check that the master volume is really muted | 286 | // TODO: check that the master volume is really muted |
280 | } | 287 | } |
281 | 288 | ||
282 | using FloatAccessorPrimaryHidlTest = AccessorPrimaryHidlTest<float>; | 289 | using FloatAccessorPrimaryHidlTest = AccessorPrimaryHidlTest<float>; |
283 | TEST_F(FloatAccessorPrimaryHidlTest, MasterVolumeTest) { | 290 | TEST_F(FloatAccessorPrimaryHidlTest, MasterVolumeTest) { |
284 | doc::test("Test the master volume if supported"); | 291 | doc::test("Test the master volume if supported"); |
285 | testOptionalAccessors( | 292 | testAccessors<OPTIONAL>( |
286 | "master volume", {0, 0.5, 1}, &IDevice::setMasterVolume, &IDevice::getMasterVolume, | 293 | "master volume", Initial{1}, {0, 0.5}, &IDevice::setMasterVolume, &IDevice::getMasterVolume, |
287 | {-0.1, 1.1, NAN, INFINITY, -INFINITY, 1 + std::numeric_limits<float>::epsilon()}); | 294 | {-0.1, 1.1, NAN, INFINITY, -INFINITY, 1 + std::numeric_limits<float>::epsilon()}); |
288 | // TODO: check that the master volume is really changed | 295 | // TODO: check that the master volume is really changed |
289 | } | 296 | } |
@@ -957,7 +964,6 @@ TEST_IO_STREAM(close, "Make sure a stream can be closed", ASSERT_OK(closeStream( | |||
957 | TEST_IO_STREAM(closeTwice, "Make sure a stream can not be closed twice", ASSERT_OK(closeStream()); | 964 | TEST_IO_STREAM(closeTwice, "Make sure a stream can not be closed twice", ASSERT_OK(closeStream()); |
958 | ASSERT_RESULT(Result::INVALID_STATE, closeStream())) | 965 | ASSERT_RESULT(Result::INVALID_STATE, closeStream())) |
959 | 966 | ||
960 | static auto invalidArgsOrNotSupported = {Result::INVALID_ARGUMENTS, Result::NOT_SUPPORTED}; | ||
961 | static void testCreateTooBigMmapBuffer(IStream* stream) { | 967 | static void testCreateTooBigMmapBuffer(IStream* stream) { |
962 | MmapBufferInfo info; | 968 | MmapBufferInfo info; |
963 | Result res; | 969 | Result res; |
@@ -1415,35 +1421,36 @@ TEST_F(AudioPrimaryHidlTest, updateRotation) { | |||
1415 | 1421 | ||
1416 | TEST_F(BoolAccessorPrimaryHidlTest, BtScoNrecEnabled) { | 1422 | TEST_F(BoolAccessorPrimaryHidlTest, BtScoNrecEnabled) { |
1417 | doc::test("Query and set the BT SCO NR&EC state"); | 1423 | doc::test("Query and set the BT SCO NR&EC state"); |
1418 | testOptionalAccessors("BtScoNrecEnabled", {true, false, true}, | 1424 | testAccessors<OPTIONAL>("BtScoNrecEnabled", Initial{false, OPTIONAL}, {true}, |
1419 | &IPrimaryDevice::setBtScoNrecEnabled, | 1425 | &IPrimaryDevice::setBtScoNrecEnabled, |
1420 | &IPrimaryDevice::getBtScoNrecEnabled); | 1426 | &IPrimaryDevice::getBtScoNrecEnabled); |
1421 | } | 1427 | } |
1422 | 1428 | ||
1423 | TEST_F(BoolAccessorPrimaryHidlTest, setGetBtScoWidebandEnabled) { | 1429 | TEST_F(BoolAccessorPrimaryHidlTest, setGetBtScoWidebandEnabled) { |
1424 | doc::test("Query and set the SCO whideband state"); | 1430 | doc::test("Query and set the SCO whideband state"); |
1425 | testOptionalAccessors("BtScoWideband", {true, false, true}, | 1431 | testAccessors<OPTIONAL>("BtScoWideband", Initial{false, OPTIONAL}, {true}, |
1426 | &IPrimaryDevice::setBtScoWidebandEnabled, | 1432 | &IPrimaryDevice::setBtScoWidebandEnabled, |
1427 | &IPrimaryDevice::getBtScoWidebandEnabled); | 1433 | &IPrimaryDevice::getBtScoWidebandEnabled); |
1428 | } | 1434 | } |
1429 | 1435 | ||
1430 | TEST_F(BoolAccessorPrimaryHidlTest, setGetBtHfpEnabled) { | 1436 | TEST_F(BoolAccessorPrimaryHidlTest, setGetBtHfpEnabled) { |
1431 | doc::test("Query and set the BT HFP state"); | 1437 | doc::test("Query and set the BT HFP state"); |
1432 | testOptionalAccessors("BtHfpEnabled", {true, false, true}, &IPrimaryDevice::setBtHfpEnabled, | 1438 | testAccessors<OPTIONAL>("BtHfpEnabled", Initial{false, OPTIONAL}, {true}, |
1433 | &IPrimaryDevice::getBtHfpEnabled); | 1439 | &IPrimaryDevice::setBtHfpEnabled, &IPrimaryDevice::getBtHfpEnabled); |
1434 | } | 1440 | } |
1435 | 1441 | ||
1436 | using TtyModeAccessorPrimaryHidlTest = AccessorPrimaryHidlTest<TtyMode>; | 1442 | using TtyModeAccessorPrimaryHidlTest = AccessorPrimaryHidlTest<TtyMode>; |
1437 | TEST_F(TtyModeAccessorPrimaryHidlTest, setGetTtyMode) { | 1443 | TEST_F(TtyModeAccessorPrimaryHidlTest, setGetTtyMode) { |
1438 | doc::test("Query and set the TTY mode state"); | 1444 | doc::test("Query and set the TTY mode state"); |
1439 | testOptionalAccessors("TTY mode", {TtyMode::OFF, TtyMode::HCO, TtyMode::VCO, TtyMode::FULL}, | 1445 | testAccessors<OPTIONAL>("TTY mode", Initial{TtyMode::OFF}, |
1440 | &IPrimaryDevice::setTtyMode, &IPrimaryDevice::getTtyMode); | 1446 | {TtyMode::HCO, TtyMode::VCO, TtyMode::FULL}, |
1447 | &IPrimaryDevice::setTtyMode, &IPrimaryDevice::getTtyMode); | ||
1441 | } | 1448 | } |
1442 | 1449 | ||
1443 | TEST_F(BoolAccessorPrimaryHidlTest, setGetHac) { | 1450 | TEST_F(BoolAccessorPrimaryHidlTest, setGetHac) { |
1444 | doc::test("Query and set the HAC state"); | 1451 | doc::test("Query and set the HAC state"); |
1445 | testOptionalAccessors("HAC", {true, false, true}, &IPrimaryDevice::setHacEnabled, | 1452 | testAccessors<OPTIONAL>("HAC", Initial{false}, {true}, &IPrimaryDevice::setHacEnabled, |
1446 | &IPrimaryDevice::getHacEnabled); | 1453 | &IPrimaryDevice::getHacEnabled); |
1447 | } | 1454 | } |
1448 | 1455 | ||
1449 | ////////////////////////////////////////////////////////////////////////////// | 1456 | ////////////////////////////////////////////////////////////////////////////// |
diff --git a/audio/core/all-versions/default/include/core/all-versions/default/ParametersUtil.h b/audio/core/all-versions/default/include/core/all-versions/default/ParametersUtil.h index a27ac25d..35ff1105 100644 --- a/audio/core/all-versions/default/include/core/all-versions/default/ParametersUtil.h +++ b/audio/core/all-versions/default/include/core/all-versions/default/ParametersUtil.h | |||
@@ -36,6 +36,7 @@ using ::android::hardware::hidl_vec; | |||
36 | 36 | ||
37 | class ParametersUtil { | 37 | class ParametersUtil { |
38 | public: | 38 | public: |
39 | Result setParam(const char* name, const char* value); | ||
39 | Result getParam(const char* name, bool* value); | 40 | Result getParam(const char* name, bool* value); |
40 | Result getParam(const char* name, int* value); | 41 | Result getParam(const char* name, int* value); |
41 | Result getParam(const char* name, String8* value, AudioParameter context = {}); | 42 | Result getParam(const char* name, String8* value, AudioParameter context = {}); |
diff --git a/audio/core/all-versions/default/include/core/all-versions/default/ParametersUtil.impl.h b/audio/core/all-versions/default/include/core/all-versions/default/ParametersUtil.impl.h index afff2b6d..34bc53c7 100644 --- a/audio/core/all-versions/default/include/core/all-versions/default/ParametersUtil.impl.h +++ b/audio/core/all-versions/default/include/core/all-versions/default/ParametersUtil.impl.h | |||
@@ -112,6 +112,12 @@ std::unique_ptr<AudioParameter> ParametersUtil::getParams(const AudioParameter& | |||
112 | return std::unique_ptr<AudioParameter>(new AudioParameter(paramsAndValues)); | 112 | return std::unique_ptr<AudioParameter>(new AudioParameter(paramsAndValues)); |
113 | } | 113 | } |
114 | 114 | ||
115 | Result ParametersUtil::setParam(const char* name, const char* value) { | ||
116 | AudioParameter param; | ||
117 | param.add(String8(name), String8(value)); | ||
118 | return setParams(param); | ||
119 | } | ||
120 | |||
115 | Result ParametersUtil::setParam(const char* name, bool value) { | 121 | Result ParametersUtil::setParam(const char* name, bool value) { |
116 | AudioParameter param; | 122 | AudioParameter param; |
117 | param.add(String8(name), String8(value ? AudioParameter::valueOn : AudioParameter::valueOff)); | 123 | param.add(String8(name), String8(value ? AudioParameter::valueOn : AudioParameter::valueOff)); |
diff --git a/audio/core/all-versions/default/include/core/all-versions/default/PrimaryDevice.impl.h b/audio/core/all-versions/default/include/core/all-versions/default/PrimaryDevice.impl.h index 61ffbe00..f269dd4f 100644 --- a/audio/core/all-versions/default/include/core/all-versions/default/PrimaryDevice.impl.h +++ b/audio/core/all-versions/default/include/core/all-versions/default/PrimaryDevice.impl.h | |||
@@ -208,16 +208,56 @@ Return<Result> PrimaryDevice::setBtScoWidebandEnabled(bool enabled) { | |||
208 | return mDevice->setParam(AUDIO_PARAMETER_KEY_BT_SCO_WB, enabled); | 208 | return mDevice->setParam(AUDIO_PARAMETER_KEY_BT_SCO_WB, enabled); |
209 | } | 209 | } |
210 | 210 | ||
211 | static const char* convertTtyModeFromHIDL(IPrimaryDevice::TtyMode mode) { | ||
212 | switch (mode) { | ||
213 | case IPrimaryDevice::TtyMode::OFF: | ||
214 | return AUDIO_PARAMETER_VALUE_TTY_OFF; | ||
215 | case IPrimaryDevice::TtyMode::VCO: | ||
216 | return AUDIO_PARAMETER_VALUE_TTY_VCO; | ||
217 | case IPrimaryDevice::TtyMode::HCO: | ||
218 | return AUDIO_PARAMETER_VALUE_TTY_HCO; | ||
219 | case IPrimaryDevice::TtyMode::FULL: | ||
220 | return AUDIO_PARAMETER_VALUE_TTY_FULL; | ||
221 | default: | ||
222 | return nullptr; | ||
223 | } | ||
224 | } | ||
225 | static IPrimaryDevice::TtyMode convertTtyModeToHIDL(const char* halMode) { | ||
226 | if (strcmp(halMode, AUDIO_PARAMETER_VALUE_TTY_OFF) == 0) | ||
227 | return IPrimaryDevice::TtyMode::OFF; | ||
228 | else if (strcmp(halMode, AUDIO_PARAMETER_VALUE_TTY_VCO) == 0) | ||
229 | return IPrimaryDevice::TtyMode::VCO; | ||
230 | else if (strcmp(halMode, AUDIO_PARAMETER_VALUE_TTY_HCO) == 0) | ||
231 | return IPrimaryDevice::TtyMode::HCO; | ||
232 | else if (strcmp(halMode, AUDIO_PARAMETER_VALUE_TTY_FULL) == 0) | ||
233 | return IPrimaryDevice::TtyMode::FULL; | ||
234 | return IPrimaryDevice::TtyMode(-1); | ||
235 | } | ||
236 | |||
211 | Return<void> PrimaryDevice::getTtyMode(getTtyMode_cb _hidl_cb) { | 237 | Return<void> PrimaryDevice::getTtyMode(getTtyMode_cb _hidl_cb) { |
212 | int halMode; | 238 | String8 halMode; |
213 | Result retval = mDevice->getParam(AUDIO_PARAMETER_KEY_TTY_MODE, &halMode); | 239 | Result retval = mDevice->getParam(AUDIO_PARAMETER_KEY_TTY_MODE, &halMode); |
214 | TtyMode mode = retval == Result::OK ? TtyMode(halMode) : TtyMode::OFF; | 240 | if (retval != Result::OK) { |
215 | _hidl_cb(retval, mode); | 241 | _hidl_cb(retval, TtyMode::OFF); |
242 | return Void(); | ||
243 | } | ||
244 | TtyMode mode = convertTtyModeToHIDL(halMode); | ||
245 | if (mode == TtyMode(-1)) { | ||
246 | ALOGE("HAL returned invalid TTY value: %s", halMode.c_str()); | ||
247 | _hidl_cb(Result::INVALID_STATE, TtyMode::OFF); | ||
248 | return Void(); | ||
249 | } | ||
250 | _hidl_cb(Result::OK, mode); | ||
216 | return Void(); | 251 | return Void(); |
217 | } | 252 | } |
218 | 253 | ||
219 | Return<Result> PrimaryDevice::setTtyMode(IPrimaryDevice::TtyMode mode) { | 254 | Return<Result> PrimaryDevice::setTtyMode(IPrimaryDevice::TtyMode mode) { |
220 | return mDevice->setParam(AUDIO_PARAMETER_KEY_TTY_MODE, static_cast<int>(mode)); | 255 | const char* modeStr = convertTtyModeFromHIDL(mode); |
256 | if (modeStr == nullptr) { | ||
257 | ALOGW("Can not set an invalid TTY value: %d", mode); | ||
258 | return Result::INVALID_ARGUMENTS; | ||
259 | } | ||
260 | return mDevice->setParam(AUDIO_PARAMETER_KEY_TTY_MODE, modeStr); | ||
221 | } | 261 | } |
222 | 262 | ||
223 | Return<void> PrimaryDevice::getHacEnabled(getHacEnabled_cb _hidl_cb) { | 263 | Return<void> PrimaryDevice::getHacEnabled(getHacEnabled_cb _hidl_cb) { |
diff --git a/camera/device/3.4/default/CameraDeviceSession.cpp b/camera/device/3.4/default/CameraDeviceSession.cpp index 550d65a8..9722c75d 100644 --- a/camera/device/3.4/default/CameraDeviceSession.cpp +++ b/camera/device/3.4/default/CameraDeviceSession.cpp | |||
@@ -52,6 +52,8 @@ CameraDeviceSession::CameraDeviceSession( | |||
52 | } | 52 | } |
53 | } | 53 | } |
54 | 54 | ||
55 | mResultBatcher_3_4.setNumPartialResults(mNumPartialResults); | ||
56 | |||
55 | camera_metadata_entry_t capabilities = | 57 | camera_metadata_entry_t capabilities = |
56 | mDeviceInfo.find(ANDROID_REQUEST_AVAILABLE_CAPABILITIES); | 58 | mDeviceInfo.find(ANDROID_REQUEST_AVAILABLE_CAPABILITIES); |
57 | bool isLogicalMultiCamera = false; | 59 | bool isLogicalMultiCamera = false; |
diff --git a/graphics/allocator/2.0/utils/gralloc1-adapter/Gralloc1On0Adapter.cpp b/graphics/allocator/2.0/utils/gralloc1-adapter/Gralloc1On0Adapter.cpp index b7ed58ce..b2aab7b1 100644 --- a/graphics/allocator/2.0/utils/gralloc1-adapter/Gralloc1On0Adapter.cpp +++ b/graphics/allocator/2.0/utils/gralloc1-adapter/Gralloc1On0Adapter.cpp | |||
@@ -161,6 +161,11 @@ gralloc1_function_pointer_t Gralloc1On0Adapter::doGetFunction( | |||
161 | case GRALLOC1_FUNCTION_INVALID: | 161 | case GRALLOC1_FUNCTION_INVALID: |
162 | ALOGE("Invalid function descriptor"); | 162 | ALOGE("Invalid function descriptor"); |
163 | return nullptr; | 163 | return nullptr; |
164 | case GRALLOC1_FUNCTION_VALIDATE_BUFFER_SIZE: | ||
165 | case GRALLOC1_FUNCTION_GET_TRANSPORT_SIZE: | ||
166 | case GRALLOC1_FUNCTION_IMPORT_BUFFER: | ||
167 | ALOGW("Not supported by gralloc 0"); | ||
168 | return nullptr; | ||
164 | } | 169 | } |
165 | 170 | ||
166 | ALOGE("Unknown function descriptor: %d", intDescriptor); | 171 | ALOGE("Unknown function descriptor: %d", intDescriptor); |
diff --git a/graphics/mapper/2.1/utils/passthrough/include/mapper-passthrough/2.1/Gralloc1Hal.h b/graphics/mapper/2.1/utils/passthrough/include/mapper-passthrough/2.1/Gralloc1Hal.h index 8b695e4d..08d604e9 100644 --- a/graphics/mapper/2.1/utils/passthrough/include/mapper-passthrough/2.1/Gralloc1Hal.h +++ b/graphics/mapper/2.1/utils/passthrough/include/mapper-passthrough/2.1/Gralloc1Hal.h | |||
@@ -28,6 +28,7 @@ namespace passthrough { | |||
28 | 28 | ||
29 | using V2_0::BufferDescriptor; | 29 | using V2_0::BufferDescriptor; |
30 | using V2_0::Error; | 30 | using V2_0::Error; |
31 | using android::hardware::graphics::common::V1_0::BufferUsage; | ||
31 | 32 | ||
32 | namespace detail { | 33 | namespace detail { |
33 | 34 | ||
@@ -38,48 +39,19 @@ class Gralloc1HalImpl : public V2_0::passthrough::detail::Gralloc1HalImpl<Hal> { | |||
38 | Error validateBufferSize(const native_handle_t* bufferHandle, | 39 | Error validateBufferSize(const native_handle_t* bufferHandle, |
39 | const IMapper::BufferDescriptorInfo& descriptorInfo, | 40 | const IMapper::BufferDescriptorInfo& descriptorInfo, |
40 | uint32_t stride) override { | 41 | uint32_t stride) override { |
41 | uint32_t bufferWidth; | 42 | gralloc1_buffer_descriptor_info_t bufferDescriptorInfo; |
42 | uint32_t bufferHeight; | ||
43 | uint32_t bufferLayerCount; | ||
44 | int32_t bufferFormat; | ||
45 | uint64_t bufferProducerUsage; | ||
46 | uint64_t bufferConsumerUsage; | ||
47 | uint32_t bufferStride; | ||
48 | |||
49 | int32_t error = mDispatch.getDimensions(mDevice, bufferHandle, &bufferWidth, &bufferHeight); | ||
50 | if (error != GRALLOC1_ERROR_NONE) { | ||
51 | return toError(error); | ||
52 | } | ||
53 | error = mDispatch.getLayerCount(mDevice, bufferHandle, &bufferLayerCount); | ||
54 | if (error != GRALLOC1_ERROR_NONE) { | ||
55 | return toError(error); | ||
56 | } | ||
57 | error = mDispatch.getFormat(mDevice, bufferHandle, &bufferFormat); | ||
58 | if (error != GRALLOC1_ERROR_NONE) { | ||
59 | return toError(error); | ||
60 | } | ||
61 | error = mDispatch.getProducerUsage(mDevice, bufferHandle, &bufferProducerUsage); | ||
62 | if (error != GRALLOC1_ERROR_NONE) { | ||
63 | return toError(error); | ||
64 | } | ||
65 | error = mDispatch.getConsumerUsage(mDevice, bufferHandle, &bufferConsumerUsage); | ||
66 | if (error != GRALLOC1_ERROR_NONE) { | ||
67 | return toError(error); | ||
68 | } | ||
69 | error = mDispatch.getStride(mDevice, bufferHandle, &bufferStride); | ||
70 | if (error != GRALLOC1_ERROR_NONE) { | ||
71 | return toError(error); | ||
72 | } | ||
73 | 43 | ||
74 | // TODO format? usage? width > stride? | 44 | bufferDescriptorInfo.width = descriptorInfo.width; |
75 | // need a gralloc1 extension to really validate | 45 | bufferDescriptorInfo.height = descriptorInfo.height; |
76 | (void)bufferFormat; | 46 | bufferDescriptorInfo.layerCount = descriptorInfo.layerCount; |
77 | (void)bufferProducerUsage; | 47 | bufferDescriptorInfo.format = static_cast<android_pixel_format_t>(descriptorInfo.format); |
78 | (void)bufferConsumerUsage; | 48 | bufferDescriptorInfo.consumerUsage = toConsumerUsage(descriptorInfo.usage); |
49 | bufferDescriptorInfo.producerUsage = toProducerUsage(descriptorInfo.usage); | ||
79 | 50 | ||
80 | if (descriptorInfo.width > bufferWidth || descriptorInfo.height > bufferHeight || | 51 | int32_t error = |
81 | descriptorInfo.layerCount > bufferLayerCount || stride > bufferStride) { | 52 | mDispatch.validateBufferSize(mDevice, bufferHandle, &bufferDescriptorInfo, stride); |
82 | return Error::BAD_VALUE; | 53 | if (error != GRALLOC1_ERROR_NONE) { |
54 | return toError(error); | ||
83 | } | 55 | } |
84 | 56 | ||
85 | return Error::NONE; | 57 | return Error::NONE; |
@@ -87,10 +59,15 @@ class Gralloc1HalImpl : public V2_0::passthrough::detail::Gralloc1HalImpl<Hal> { | |||
87 | 59 | ||
88 | Error getTransportSize(const native_handle_t* bufferHandle, uint32_t* outNumFds, | 60 | Error getTransportSize(const native_handle_t* bufferHandle, uint32_t* outNumFds, |
89 | uint32_t* outNumInts) override { | 61 | uint32_t* outNumInts) override { |
90 | // need a gralloc1 extension to get the transport size | 62 | int32_t error = mDispatch.getTransportSize(mDevice, bufferHandle, outNumFds, outNumInts); |
91 | *outNumFds = bufferHandle->numFds; | 63 | return toError(error); |
92 | *outNumInts = bufferHandle->numInts; | 64 | } |
93 | return Error::NONE; | 65 | |
66 | Error importBuffer(const native_handle_t* rawHandle, | ||
67 | native_handle_t** outBufferHandle) override { | ||
68 | int32_t error = mDispatch.importBuffer( | ||
69 | mDevice, rawHandle, const_cast<const native_handle_t**>(outBufferHandle)); | ||
70 | return toError(error); | ||
94 | } | 71 | } |
95 | 72 | ||
96 | Error createDescriptor_2_1(const IMapper::BufferDescriptorInfo& descriptorInfo, | 73 | Error createDescriptor_2_1(const IMapper::BufferDescriptorInfo& descriptorInfo, |
@@ -109,12 +86,9 @@ class Gralloc1HalImpl : public V2_0::passthrough::detail::Gralloc1HalImpl<Hal> { | |||
109 | return false; | 86 | return false; |
110 | } | 87 | } |
111 | 88 | ||
112 | if (!initDispatch(GRALLOC1_FUNCTION_GET_DIMENSIONS, &mDispatch.getDimensions) || | 89 | if (!initDispatch(GRALLOC1_FUNCTION_VALIDATE_BUFFER_SIZE, &mDispatch.validateBufferSize) || |
113 | !initDispatch(GRALLOC1_FUNCTION_GET_LAYER_COUNT, &mDispatch.getLayerCount) || | 90 | !initDispatch(GRALLOC1_FUNCTION_GET_TRANSPORT_SIZE, &mDispatch.getTransportSize) || |
114 | !initDispatch(GRALLOC1_FUNCTION_GET_FORMAT, &mDispatch.getFormat) || | 91 | !initDispatch(GRALLOC1_FUNCTION_IMPORT_BUFFER, &mDispatch.importBuffer)) { |
115 | !initDispatch(GRALLOC1_FUNCTION_GET_PRODUCER_USAGE, &mDispatch.getProducerUsage) || | ||
116 | !initDispatch(GRALLOC1_FUNCTION_GET_CONSUMER_USAGE, &mDispatch.getConsumerUsage) || | ||
117 | !initDispatch(GRALLOC1_FUNCTION_GET_STRIDE, &mDispatch.getStride)) { | ||
118 | return false; | 92 | return false; |
119 | } | 93 | } |
120 | 94 | ||
@@ -122,14 +96,73 @@ class Gralloc1HalImpl : public V2_0::passthrough::detail::Gralloc1HalImpl<Hal> { | |||
122 | } | 96 | } |
123 | 97 | ||
124 | struct { | 98 | struct { |
125 | GRALLOC1_PFN_GET_DIMENSIONS getDimensions; | 99 | GRALLOC1_PFN_VALIDATE_BUFFER_SIZE validateBufferSize; |
126 | GRALLOC1_PFN_GET_LAYER_COUNT getLayerCount; | 100 | GRALLOC1_PFN_GET_TRANSPORT_SIZE getTransportSize; |
127 | GRALLOC1_PFN_GET_FORMAT getFormat; | 101 | GRALLOC1_PFN_IMPORT_BUFFER importBuffer; |
128 | GRALLOC1_PFN_GET_PRODUCER_USAGE getProducerUsage; | ||
129 | GRALLOC1_PFN_GET_CONSUMER_USAGE getConsumerUsage; | ||
130 | GRALLOC1_PFN_GET_STRIDE getStride; | ||
131 | } mDispatch = {}; | 102 | } mDispatch = {}; |
132 | 103 | ||
104 | static uint64_t toProducerUsage(uint64_t usage) { | ||
105 | // this is potentially broken as we have no idea which private flags | ||
106 | // should be filtered out | ||
107 | uint64_t producerUsage = usage & ~static_cast<uint64_t>(BufferUsage::CPU_READ_MASK | | ||
108 | BufferUsage::CPU_WRITE_MASK | | ||
109 | BufferUsage::GPU_DATA_BUFFER); | ||
110 | |||
111 | switch (usage & BufferUsage::CPU_WRITE_MASK) { | ||
112 | case static_cast<uint64_t>(BufferUsage::CPU_WRITE_RARELY): | ||
113 | producerUsage |= GRALLOC1_PRODUCER_USAGE_CPU_WRITE; | ||
114 | break; | ||
115 | case static_cast<uint64_t>(BufferUsage::CPU_WRITE_OFTEN): | ||
116 | producerUsage |= GRALLOC1_PRODUCER_USAGE_CPU_WRITE_OFTEN; | ||
117 | break; | ||
118 | default: | ||
119 | break; | ||
120 | } | ||
121 | |||
122 | switch (usage & BufferUsage::CPU_READ_MASK) { | ||
123 | case static_cast<uint64_t>(BufferUsage::CPU_READ_RARELY): | ||
124 | producerUsage |= GRALLOC1_PRODUCER_USAGE_CPU_READ; | ||
125 | break; | ||
126 | case static_cast<uint64_t>(BufferUsage::CPU_READ_OFTEN): | ||
127 | producerUsage |= GRALLOC1_PRODUCER_USAGE_CPU_READ_OFTEN; | ||
128 | break; | ||
129 | default: | ||
130 | break; | ||
131 | } | ||
132 | |||
133 | // BufferUsage::GPU_DATA_BUFFER is always filtered out | ||
134 | |||
135 | return producerUsage; | ||
136 | } | ||
137 | |||
138 | static uint64_t toConsumerUsage(uint64_t usage) { | ||
139 | // this is potentially broken as we have no idea which private flags | ||
140 | // should be filtered out | ||
141 | uint64_t consumerUsage = | ||
142 | usage & | ||
143 | ~static_cast<uint64_t>(BufferUsage::CPU_READ_MASK | BufferUsage::CPU_WRITE_MASK | | ||
144 | BufferUsage::SENSOR_DIRECT_DATA | BufferUsage::GPU_DATA_BUFFER); | ||
145 | |||
146 | switch (usage & BufferUsage::CPU_READ_MASK) { | ||
147 | case static_cast<uint64_t>(BufferUsage::CPU_READ_RARELY): | ||
148 | consumerUsage |= GRALLOC1_CONSUMER_USAGE_CPU_READ; | ||
149 | break; | ||
150 | case static_cast<uint64_t>(BufferUsage::CPU_READ_OFTEN): | ||
151 | consumerUsage |= GRALLOC1_CONSUMER_USAGE_CPU_READ_OFTEN; | ||
152 | break; | ||
153 | default: | ||
154 | break; | ||
155 | } | ||
156 | |||
157 | // BufferUsage::SENSOR_DIRECT_DATA is always filtered out | ||
158 | |||
159 | if (usage & BufferUsage::GPU_DATA_BUFFER) { | ||
160 | consumerUsage |= GRALLOC1_CONSUMER_USAGE_GPU_DATA_BUFFER; | ||
161 | } | ||
162 | |||
163 | return consumerUsage; | ||
164 | } | ||
165 | |||
133 | private: | 166 | private: |
134 | using BaseType2_0 = V2_0::passthrough::detail::Gralloc1HalImpl<Hal>; | 167 | using BaseType2_0 = V2_0::passthrough::detail::Gralloc1HalImpl<Hal>; |
135 | using BaseType2_0::createDescriptor; | 168 | using BaseType2_0::createDescriptor; |