summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorandroid-build-team Robot2017-11-14 02:23:01 -0600
committerandroid-build-team Robot2017-11-14 02:23:01 -0600
commit1a261d48094b98ca9970ce9ac59bfda54f7e48c6 (patch)
tree11487fb8033228ac7d0923cd3be0b1b4c4761e05
parentcf58892acb938c2b55b28739194d0602909cda9f (diff)
parent1396a5734f7c7e1972fec5ccdfcc42bd946b0110 (diff)
downloadplatform-system-libvintf-1a261d48094b98ca9970ce9ac59bfda54f7e48c6.tar.gz
platform-system-libvintf-1a261d48094b98ca9970ce9ac59bfda54f7e48c6.tar.xz
platform-system-libvintf-1a261d48094b98ca9970ce9ac59bfda54f7e48c6.zip
Snap for 4450504 from 1396a5734f7c7e1972fec5ccdfcc42bd946b0110 to pi-release
Change-Id: I665a8dd03f5674174873ce577d04cac7cdbb35df
-rw-r--r--VintfObject.cpp19
-rw-r--r--test/Android.bp5
-rw-r--r--test/vintf_object_tests.cpp46
3 files changed, 64 insertions, 6 deletions
diff --git a/VintfObject.cpp b/VintfObject.cpp
index 9dea4d9..efe6242 100644
--- a/VintfObject.cpp
+++ b/VintfObject.cpp
@@ -24,6 +24,10 @@
24#include <memory> 24#include <memory>
25#include <mutex> 25#include <mutex>
26 26
27#ifdef LIBVINTF_TARGET
28#include <android-base/properties.h>
29#endif
30
27namespace android { 31namespace android {
28namespace vintf { 32namespace vintf {
29 33
@@ -58,10 +62,25 @@ static std::shared_ptr<const T> Get(
58std::shared_ptr<const HalManifest> VintfObject::GetDeviceHalManifest(bool skipCache) { 62std::shared_ptr<const HalManifest> VintfObject::GetDeviceHalManifest(bool skipCache) {
59 static LockedSharedPtr<HalManifest> gVendorManifest; 63 static LockedSharedPtr<HalManifest> gVendorManifest;
60 static LockedSharedPtr<HalManifest> gOdmManifest; 64 static LockedSharedPtr<HalManifest> gOdmManifest;
65#ifdef LIBVINTF_TARGET
66 static LockedSharedPtr<HalManifest> gProductManifest;
67#endif
61 static std::mutex gDeviceManifestMutex; 68 static std::mutex gDeviceManifestMutex;
62 69
63 std::unique_lock<std::mutex> _lock(gDeviceManifestMutex); 70 std::unique_lock<std::mutex> _lock(gDeviceManifestMutex);
64 71
72#ifdef LIBVINTF_TARGET
73 std::string productModel = android::base::GetProperty("ro.product.model", "");
74 if (!productModel.empty()) {
75 auto product = Get(&gProductManifest, skipCache,
76 std::bind(&HalManifest::fetchAllInformation, std::placeholders::_1,
77 "/odm/manifest_" + productModel + ".xml"));
78 if (product != nullptr) {
79 return product;
80 }
81 }
82#endif
83
65 auto odm = Get( 84 auto odm = Get(
66 &gOdmManifest, skipCache, 85 &gOdmManifest, skipCache,
67 std::bind(&HalManifest::fetchAllInformation, std::placeholders::_1, "/odm/manifest.xml")); 86 std::bind(&HalManifest::fetchAllInformation, std::placeholders::_1, "/odm/manifest.xml"));
diff --git a/test/Android.bp b/test/Android.bp
index 4849a63..ee1cf4f 100644
--- a/test/Android.bp
+++ b/test/Android.bp
@@ -60,4 +60,9 @@ cc_test {
60 "-O0", 60 "-O0",
61 "-g", 61 "-g",
62 ], 62 ],
63 target: {
64 android: {
65 cflags: ["-DLIBVINTF_TARGET"],
66 },
67 }
63} 68}
diff --git a/test/vintf_object_tests.cpp b/test/vintf_object_tests.cpp
index b206158..3033dfe 100644
--- a/test/vintf_object_tests.cpp
+++ b/test/vintf_object_tests.cpp
@@ -21,6 +21,10 @@
21#include <stdio.h> 21#include <stdio.h>
22#include <unistd.h> 22#include <unistd.h>
23 23
24#ifdef LIBVINTF_TARGET
25#include <android-base/properties.h>
26#endif
27
24#include "utils-fake.h" 28#include "utils-fake.h"
25#include "vintf/VintfObject.h" 29#include "vintf/VintfObject.h"
26 30
@@ -166,9 +170,14 @@ const std::string vendorManifestXml2 =
166// Setup the MockFileFetcher used by the fetchAllInformation template 170// Setup the MockFileFetcher used by the fetchAllInformation template
167// so it returns the given metadata info instead of fetching from device. 171// so it returns the given metadata info instead of fetching from device.
168void setupMockFetcher(const std::string& vendorManifestXml, const std::string& systemMatrixXml, 172void setupMockFetcher(const std::string& vendorManifestXml, const std::string& systemMatrixXml,
169 const std::string& systemManifestXml, const std::string& vendorMatrixXml) { 173 const std::string& systemManifestXml, const std::string& vendorMatrixXml,
174 const std::string& productModel) {
170 MockFileFetcher* fetcher = static_cast<MockFileFetcher*>(gFetcher); 175 MockFileFetcher* fetcher = static_cast<MockFileFetcher*>(gFetcher);
171 176
177 if (!productModel.empty()) {
178 ON_CALL(*fetcher, fetch(StrEq("/odm/manifest_" + productModel + ".xml"), _))
179 .WillByDefault(Return(::android::NAME_NOT_FOUND));
180 }
172 ON_CALL(*fetcher, fetch(StrEq("/odm/manifest.xml"), _)) 181 ON_CALL(*fetcher, fetch(StrEq("/odm/manifest.xml"), _))
173 .WillByDefault(Return(::android::NAME_NOT_FOUND)); 182 .WillByDefault(Return(::android::NAME_NOT_FOUND));
174 ON_CALL(*fetcher, fetch(StrEq("/vendor/manifest.xml"), _)) 183 ON_CALL(*fetcher, fetch(StrEq("/vendor/manifest.xml"), _))
@@ -208,14 +217,17 @@ class VintfObjectCompatibleTest : public testing::Test {
208 protected: 217 protected:
209 virtual void SetUp() { 218 virtual void SetUp() {
210 mounter().reset(); 219 mounter().reset();
211 setupMockFetcher(vendorManifestXml1, systemMatrixXml1, systemManifestXml1, 220#ifdef LIBVINTF_TARGET
212 vendorMatrixXml1); 221 productModel = android::base::GetProperty("ro.product.model", "");
222#endif
223 setupMockFetcher(vendorManifestXml1, systemMatrixXml1, systemManifestXml1, vendorMatrixXml1,
224 productModel);
213 } 225 }
214 virtual void TearDown() { 226 virtual void TearDown() {
215 Mock::VerifyAndClear(&mounter()); 227 Mock::VerifyAndClear(&mounter());
216 Mock::VerifyAndClear(&fetcher()); 228 Mock::VerifyAndClear(&fetcher());
217 } 229 }
218 230 std::string productModel;
219}; 231};
220 232
221// Tests that local info is checked. 233// Tests that local info is checked.
@@ -223,6 +235,9 @@ TEST_F(VintfObjectCompatibleTest, TestDeviceCompatibility) {
223 std::string error; 235 std::string error;
224 std::vector<std::string> packageInfo; 236 std::vector<std::string> packageInfo;
225 237
238 if (!productModel.empty()) {
239 EXPECT_CALL(fetcher(), fetch(StrEq("/odm/manifest_" + productModel + ".xml"), _));
240 }
226 EXPECT_CALL(fetcher(), fetch(StrEq("/odm/manifest.xml"), _)); 241 EXPECT_CALL(fetcher(), fetch(StrEq("/odm/manifest.xml"), _));
227 EXPECT_CALL(fetcher(), fetch(StrEq("/vendor/manifest.xml"), _)); 242 EXPECT_CALL(fetcher(), fetch(StrEq("/vendor/manifest.xml"), _));
228 EXPECT_CALL(fetcher(), fetch(StrEq("/system/manifest.xml"), _)); 243 EXPECT_CALL(fetcher(), fetch(StrEq("/system/manifest.xml"), _));
@@ -263,6 +278,9 @@ TEST_F(VintfObjectCompatibleTest, TestInputVsDeviceSuccess) {
263 std::string error; 278 std::string error;
264 std::vector<std::string> packageInfo = {systemMatrixXml1}; 279 std::vector<std::string> packageInfo = {systemMatrixXml1};
265 280
281 if (!productModel.empty()) {
282 EXPECT_CALL(fetcher(), fetch(StrEq("/odm/manifest_" + productModel + ".xml"), _));
283 }
266 EXPECT_CALL(fetcher(), fetch(StrEq("/odm/manifest.xml"), _)); 284 EXPECT_CALL(fetcher(), fetch(StrEq("/odm/manifest.xml"), _));
267 EXPECT_CALL(fetcher(), fetch(StrEq("/vendor/manifest.xml"), _)); 285 EXPECT_CALL(fetcher(), fetch(StrEq("/vendor/manifest.xml"), _));
268 EXPECT_CALL(fetcher(), fetch(StrEq("/system/manifest.xml"), _)); 286 EXPECT_CALL(fetcher(), fetch(StrEq("/system/manifest.xml"), _));
@@ -325,6 +343,9 @@ TEST_F(VintfObjectCompatibleTest, TestFrameworkOnlyOta) {
325 std::string error; 343 std::string error;
326 std::vector<std::string> packageInfo = {systemMatrixXml1, systemManifestXml1}; 344 std::vector<std::string> packageInfo = {systemMatrixXml1, systemManifestXml1};
327 345
346 if (!productModel.empty()) {
347 EXPECT_CALL(fetcher(), fetch(StrEq("/odm/manifest_" + productModel + ".xml"), _));
348 }
328 EXPECT_CALL(fetcher(), fetch(StrEq("/odm/manifest.xml"), _)); 349 EXPECT_CALL(fetcher(), fetch(StrEq("/odm/manifest.xml"), _));
329 EXPECT_CALL(fetcher(), fetch(StrEq("/vendor/manifest.xml"), _)); 350 EXPECT_CALL(fetcher(), fetch(StrEq("/vendor/manifest.xml"), _));
330 EXPECT_CALL(fetcher(), fetch(StrEq("/system/manifest.xml"), _)).Times(0); 351 EXPECT_CALL(fetcher(), fetch(StrEq("/system/manifest.xml"), _)).Times(0);
@@ -364,6 +385,9 @@ TEST_F(VintfObjectCompatibleTest, TestFullOta) {
364 std::vector<std::string> packageInfo = {systemMatrixXml1, systemManifestXml1, 385 std::vector<std::string> packageInfo = {systemMatrixXml1, systemManifestXml1,
365 vendorMatrixXml1, vendorManifestXml1}; 386 vendorMatrixXml1, vendorManifestXml1};
366 387
388 if (!productModel.empty()) {
389 EXPECT_CALL(fetcher(), fetch(StrEq("/odm/manifest_" + productModel + ".xml"), _)).Times(0);
390 }
367 EXPECT_CALL(fetcher(), fetch(StrEq("/odm/manifest.xml"), _)).Times(0); 391 EXPECT_CALL(fetcher(), fetch(StrEq("/odm/manifest.xml"), _)).Times(0);
368 EXPECT_CALL(fetcher(), fetch(StrEq("/vendor/manifest.xml"), _)).Times(0); 392 EXPECT_CALL(fetcher(), fetch(StrEq("/vendor/manifest.xml"), _)).Times(0);
369 EXPECT_CALL(fetcher(), fetch(StrEq("/system/manifest.xml"), _)).Times(0); 393 EXPECT_CALL(fetcher(), fetch(StrEq("/system/manifest.xml"), _)).Times(0);
@@ -404,13 +428,17 @@ class VintfObjectIncompatibleTest : public testing::Test {
404 protected: 428 protected:
405 virtual void SetUp() { 429 virtual void SetUp() {
406 mounter().reset(); 430 mounter().reset();
407 setupMockFetcher(vendorManifestXml1, systemMatrixXml2, systemManifestXml1, 431#ifdef LIBVINTF_TARGET
408 vendorMatrixXml1); 432 productModel = android::base::GetProperty("ro.product.model", "");
433#endif
434 setupMockFetcher(vendorManifestXml1, systemMatrixXml2, systemManifestXml1, vendorMatrixXml1,
435 productModel);
409 } 436 }
410 virtual void TearDown() { 437 virtual void TearDown() {
411 Mock::VerifyAndClear(&mounter()); 438 Mock::VerifyAndClear(&mounter());
412 Mock::VerifyAndClear(&fetcher()); 439 Mock::VerifyAndClear(&fetcher());
413 } 440 }
441 std::string productModel;
414}; 442};
415 443
416// Fetch all metadata from device and ensure that it fails. 444// Fetch all metadata from device and ensure that it fails.
@@ -418,6 +446,9 @@ TEST_F(VintfObjectIncompatibleTest, TestDeviceCompatibility) {
418 std::string error; 446 std::string error;
419 std::vector<std::string> packageInfo; 447 std::vector<std::string> packageInfo;
420 448
449 if (!productModel.empty()) {
450 EXPECT_CALL(fetcher(), fetch(StrEq("/odm/manifest_" + productModel + ".xml"), _));
451 }
421 EXPECT_CALL(fetcher(), fetch(StrEq("/odm/manifest.xml"), _)); 452 EXPECT_CALL(fetcher(), fetch(StrEq("/odm/manifest.xml"), _));
422 EXPECT_CALL(fetcher(), fetch(StrEq("/vendor/manifest.xml"), _)); 453 EXPECT_CALL(fetcher(), fetch(StrEq("/vendor/manifest.xml"), _));
423 EXPECT_CALL(fetcher(), fetch(StrEq("/system/manifest.xml"), _)); 454 EXPECT_CALL(fetcher(), fetch(StrEq("/system/manifest.xml"), _));
@@ -434,6 +465,9 @@ TEST_F(VintfObjectIncompatibleTest, TestInputVsDeviceSuccess) {
434 std::string error; 465 std::string error;
435 std::vector<std::string> packageInfo = {systemMatrixXml1}; 466 std::vector<std::string> packageInfo = {systemMatrixXml1};
436 467
468 if (!productModel.empty()) {
469 EXPECT_CALL(fetcher(), fetch(StrEq("/odm/manifest_" + productModel + ".xml"), _));
470 }
437 EXPECT_CALL(fetcher(), fetch(StrEq("/odm/manifest.xml"), _)); 471 EXPECT_CALL(fetcher(), fetch(StrEq("/odm/manifest.xml"), _));
438 EXPECT_CALL(fetcher(), fetch(StrEq("/vendor/manifest.xml"), _)); 472 EXPECT_CALL(fetcher(), fetch(StrEq("/vendor/manifest.xml"), _));
439 EXPECT_CALL(fetcher(), fetch(StrEq("/system/manifest.xml"), _)); 473 EXPECT_CALL(fetcher(), fetch(StrEq("/system/manifest.xml"), _));