diff options
| author | 2017-03-24 23:32:44 +0000 | |
|---|---|---|
| committer | 2017-03-24 23:32:45 +0000 | |
| commit | 26638e89bfe2c2ec33e6c9d92d0f6427f3060a57 (patch) | |
| tree | c2fd4346462091524425ec78d2351e88c8684724 /libs | |
| parent | a8fad9bd6ca694bb0f86d617c72122d2220ec253 (diff) | |
| parent | 41dc32858bfaa14ea3eea9c2828f6183ac5e7048 (diff) | |
Merge "libdvrcommon: Remove revision code."
Diffstat (limited to 'libs')
| -rw-r--r-- | libs/vr/libdvrcommon/Android.bp | 2 | ||||
| -rw-r--r-- | libs/vr/libdvrcommon/include/private/dvr/revision.h | 47 | ||||
| -rw-r--r-- | libs/vr/libdvrcommon/revision.cpp | 175 | ||||
| -rw-r--r-- | libs/vr/libdvrcommon/revision_path.cpp | 15 | ||||
| -rw-r--r-- | libs/vr/libdvrcommon/revision_path.h | 9 | ||||
| -rw-r--r-- | libs/vr/libdvrcommon/tests/revision_app_tests.cpp | 34 | ||||
| -rw-r--r-- | libs/vr/libdvrcommon/tests/revision_tests.cpp | 27 |
7 files changed, 0 insertions, 309 deletions
diff --git a/libs/vr/libdvrcommon/Android.bp b/libs/vr/libdvrcommon/Android.bp index 81404a4fc3..eb78348f4a 100644 --- a/libs/vr/libdvrcommon/Android.bp +++ b/libs/vr/libdvrcommon/Android.bp @@ -14,8 +14,6 @@ sourceFiles = [ "frame_time_history.cpp", - "revision.cpp", - "revision_path.cpp", "sync_util.cpp", ] diff --git a/libs/vr/libdvrcommon/include/private/dvr/revision.h b/libs/vr/libdvrcommon/include/private/dvr/revision.h deleted file mode 100644 index dda0fceb62..0000000000 --- a/libs/vr/libdvrcommon/include/private/dvr/revision.h +++ /dev/null @@ -1,47 +0,0 @@ -#ifndef LIBS_VR_LIBDVRCOMMON_INCLUDE_PRIVATE_DVR_REVISION_H_ -#define LIBS_VR_LIBDVRCOMMON_INCLUDE_PRIVATE_DVR_REVISION_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -// List of DreamOS products -typedef enum DvrProduct { - DVR_PRODUCT_UNKNOWN, - DVR_PRODUCT_A00, - DVR_PRODUCT_A65R, - DVR_PRODUCT_TWILIGHT = DVR_PRODUCT_A65R -} DvrProduct; - -// List of possible revisions. -typedef enum DvrRevision { - DVR_REVISION_UNKNOWN, - DVR_REVISION_P1, - DVR_REVISION_P2, - DVR_REVISION_P3, -} DvrRevision; - -// Query the device's product. -// -// @return DvrProduct value, or DvrProductUnknown on error. -DvrProduct dvr_get_product(); - -// Query the device's revision. -// -// @return DvrRevision value, or DvrRevisionUnknown on error. -DvrRevision dvr_get_revision(); - -// Returns the device's board revision string. -// -// @return NULL-terminated string such as 'a00-p1'. -const char* dvr_get_product_revision_str(); - -// Returns the device's serial number. -// -// @return Returns NULL on error, or a NULL-terminated string. -const char* dvr_get_serial_number(); - -#ifdef __cplusplus -} -#endif // extern "C" -#endif // LIBS_VR_LIBDVRCOMMON_INCLUDE_PRIVATE_DVR_REVISION_H_ diff --git a/libs/vr/libdvrcommon/revision.cpp b/libs/vr/libdvrcommon/revision.cpp deleted file mode 100644 index 7925f657a2..0000000000 --- a/libs/vr/libdvrcommon/revision.cpp +++ /dev/null @@ -1,175 +0,0 @@ -#include "private/dvr/revision.h" - -#include <errno.h> -#include <fcntl.h> -#include <stdlib.h> -#include <string.h> -#include <sys/mman.h> -#include <sys/stat.h> -#include <sys/types.h> -#include <unistd.h> - -#include <log/log.h> - -#include "revision_path.h" - -namespace { - -// Allows quicker access to the product revision. If non-zero, then -// the product revision file has already been processed. -static bool global_product_revision_processed = false; - -static bool global_serial_number_processed = false; - -// The product. -static DvrProduct global_product = DVR_PRODUCT_UNKNOWN; - -// The revision. -static DvrRevision global_revision = DVR_REVISION_UNKNOWN; - -// Maximum size of the product revision string. -constexpr int kProductRevisionStringSize = 32; - -// Maximum size of the serial number. -constexpr int kSerialNumberStringSize = 32; - -// The product revision string. -static char global_product_revision_str[kProductRevisionStringSize + 1] = ""; - -// The serial number string -static char global_serial_number[kSerialNumberStringSize + 1] = ""; - -// Product and revision combinations. -struct DvrProductRevision { - const char* str; - DvrProduct product; - DvrRevision revision; -}; - -// Null-terminated list of all product and revision combinations. -static constexpr DvrProductRevision kProductRevisions[] = { - {"a00-p1", DVR_PRODUCT_A00, DVR_REVISION_P1}, - {"a00-p2", DVR_PRODUCT_A00, DVR_REVISION_P2}, - {"a00-p3", DVR_PRODUCT_A00, DVR_REVISION_P3}, - {"twilight-p1", DVR_PRODUCT_A65R, DVR_REVISION_P1}, - {"twilight-p2", DVR_PRODUCT_A65R, DVR_REVISION_P2}, - {NULL, DVR_PRODUCT_UNKNOWN, DVR_REVISION_UNKNOWN}}; - -// Read the product revision string, and store the global data. -static void process_product_revision() { - int fd; - ssize_t read_rc; - const DvrProductRevision* product_revision = kProductRevisions; - - // Of course in a multi-threaded environment, for a few microseconds - // during process startup, it is possible that this function will be - // called and execute fully multiple times. That is why the product - // revision string is statically allocated. - - if (global_product_revision_processed) - return; - - // Whether there was a failure or not, we don't want to do this again. - // Upon failure it's most likely to fail again anyway. - - fd = open(dvr_product_revision_file_path(), O_RDONLY); - if (fd < 0) { - ALOGE("Could not open '%s' to get product revision: %s", - dvr_product_revision_file_path(), strerror(errno)); - global_product_revision_processed = true; - return; - } - - read_rc = read(fd, global_product_revision_str, kProductRevisionStringSize); - if (read_rc <= 0) { - ALOGE("Could not read from '%s': %s", dvr_product_revision_file_path(), - strerror(errno)); - global_product_revision_processed = true; - return; - } - - close(fd); - - global_product_revision_str[read_rc] = '\0'; - - while (product_revision->str) { - if (!strcmp(product_revision->str, global_product_revision_str)) - break; - product_revision++; - } - - if (product_revision->str) { - global_product = product_revision->product; - global_revision = product_revision->revision; - } else { - ALOGE("Unable to match '%s' to a product/revision.", - global_product_revision_str); - } - - global_product_revision_processed = true; -} - -} // anonymous namespace - -extern "C" DvrProduct dvr_get_product() { - process_product_revision(); - return global_product; -} - -extern "C" DvrRevision dvr_get_revision() { - process_product_revision(); - return global_revision; -} - -extern "C" const char* dvr_get_product_revision_str() { - process_product_revision(); - return global_product_revision_str; -} - -extern "C" const char* dvr_get_serial_number() { - process_product_revision(); - if (global_product == DVR_PRODUCT_A00) { - if (!global_serial_number_processed) { -#ifdef DVR_HOST - global_serial_number_processed = true; -#else - int width = 4; - uintptr_t addr = 0x00074138; - uintptr_t endaddr = addr + width - 1; - - int fd = open("/dev/mem", O_RDWR | O_SYNC); - if (fd < 0) { - if (errno == EPERM) - global_serial_number_processed = true; - fprintf(stderr, "cannot open /dev/mem\n"); - return global_serial_number; - } - - off64_t mmap_start = addr & ~(PAGE_SIZE - 1); - size_t mmap_size = endaddr - mmap_start + 1; - mmap_size = (mmap_size + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1); - - void* page = mmap64(0, mmap_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, - mmap_start); - - if (page == MAP_FAILED) { - global_serial_number_processed = true; - fprintf(stderr, "cannot mmap region\n"); - close(fd); - return global_serial_number; - } - - uint32_t* x = - reinterpret_cast<uint32_t*>((((uintptr_t)page) + (addr & 4095))); - snprintf(global_serial_number, kSerialNumberStringSize, "%08x", *x); - global_serial_number_processed = true; - - munmap(page, mmap_size); - close(fd); -#endif - } - return global_serial_number; - } else { - return nullptr; - } -} diff --git a/libs/vr/libdvrcommon/revision_path.cpp b/libs/vr/libdvrcommon/revision_path.cpp deleted file mode 100644 index c49f9aafef..0000000000 --- a/libs/vr/libdvrcommon/revision_path.cpp +++ /dev/null @@ -1,15 +0,0 @@ -#include "revision_path.h" - -namespace { - -// The path to the product revision file. -static const char* kProductRevisionFilePath = - "/sys/firmware/devicetree/base/goog,board-revision"; - -} // anonymous namespace - -// This exists in a separate file so that it can be replaced for -// testing. -const char* dvr_product_revision_file_path() { - return kProductRevisionFilePath; -} diff --git a/libs/vr/libdvrcommon/revision_path.h b/libs/vr/libdvrcommon/revision_path.h deleted file mode 100644 index afcea46e88..0000000000 --- a/libs/vr/libdvrcommon/revision_path.h +++ /dev/null @@ -1,9 +0,0 @@ -#ifndef ANDROID_DVR_LIBDVRCOMMON_REVISION_PATH_H_ -#define ANDROID_DVR_LIBDVRCOMMON_REVISION_PATH_H_ - -// Returns the revision file path. -// This exists in a separate file so that it can be replaced for -// testing. -const char* dvr_product_revision_file_path(); - -#endif // ANDROID_DVR_LIBDVRCOMMON_REVISION_PATH_H_ diff --git a/libs/vr/libdvrcommon/tests/revision_app_tests.cpp b/libs/vr/libdvrcommon/tests/revision_app_tests.cpp deleted file mode 100644 index 772481b8f6..0000000000 --- a/libs/vr/libdvrcommon/tests/revision_app_tests.cpp +++ /dev/null @@ -1,34 +0,0 @@ -#include <dvr/test/app_test.h> -#include <gtest/gtest.h> -#include <private/dvr/revision.h> - -// Making sure this information is not available -// inside the sandbox - -namespace { - -TEST(RevisionTests, GetProduct) { - ASSERT_EQ(DVR_PRODUCT_UNKNOWN, dvr_get_product()); -} - -TEST(RevisionTests, GetRevision) { - ASSERT_EQ(DVR_REVISION_UNKNOWN, dvr_get_revision()); -} - -TEST(RevisionTests, GetRevisionStr) { - ASSERT_STREQ("", dvr_get_product_revision_str()); -} - -TEST(RevisionTests, GetSerialNo) { - ASSERT_EQ(nullptr, dvr_get_serial_number()); -} - -} // namespace - -int main(int argc, char* argv[]) { - dreamos::test::AppTestBegin(); - ::testing::InitGoogleTest(&argc, argv); - int result = RUN_ALL_TESTS(); - dreamos::test::AppTestEnd(result); - return result; -} diff --git a/libs/vr/libdvrcommon/tests/revision_tests.cpp b/libs/vr/libdvrcommon/tests/revision_tests.cpp deleted file mode 100644 index 9abf4805a6..0000000000 --- a/libs/vr/libdvrcommon/tests/revision_tests.cpp +++ /dev/null @@ -1,27 +0,0 @@ -#include <gtest/gtest.h> -#include <private/dvr/revision.h> - -namespace { - -TEST(RevisionTests, GetProduct) { - ASSERT_NE(DVR_PRODUCT_UNKNOWN, dvr_get_product()); -} - -TEST(RevisionTests, GetRevision) { - ASSERT_NE(DVR_REVISION_UNKNOWN, dvr_get_revision()); -} - -TEST(RevisionTests, GetRevisionStr) { - ASSERT_NE(nullptr, dvr_get_product_revision_str()); -} - -TEST(RevisionTests, GetSerialNo) { - ASSERT_NE(nullptr, dvr_get_serial_number()); -} - -} // namespace - -int main(int argc, char* argv[]) { - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} |