summaryrefslogtreecommitdiffstats
path: root/tzdatacheck/tzdatacheck.cpp
diff options
context:
space:
mode:
authorNeil Fuller <nfuller@google.com>2017-02-09 11:53:07 +0000
committerNeil Fuller <nfuller@google.com>2017-02-09 11:53:07 +0000
commitf54cadb83dbf2117b1bce5ec71cde826df7fd955 (patch)
tree4b5ab8973c7f87d0afcacc382a20bf4e28dd2507 /tzdatacheck/tzdatacheck.cpp
parenta8629e8e15d91b72a9e9b9351db91750fb212b70 (diff)
downloadcore-f54cadb83dbf2117b1bce5ec71cde826df7fd955.tar.gz
core-f54cadb83dbf2117b1bce5ec71cde826df7fd955.tar.bz2
core-f54cadb83dbf2117b1bce5ec71cde826df7fd955.zip
Add bundle format minor version check logic
The code now checks the minor version for completeness. Bug: 31008728 Test: Manual testing Change-Id: I28840065f794bd28de6282e81dc55336f77ab2d1
Diffstat (limited to 'tzdatacheck/tzdatacheck.cpp')
-rw-r--r--tzdatacheck/tzdatacheck.cpp51
1 files changed, 41 insertions, 10 deletions
diff --git a/tzdatacheck/tzdatacheck.cpp b/tzdatacheck/tzdatacheck.cpp
index fb5c84bb6..a7bb60cf6 100644
--- a/tzdatacheck/tzdatacheck.cpp
+++ b/tzdatacheck/tzdatacheck.cpp
@@ -38,8 +38,16 @@ static const char* BUNDLE_VERSION_FILENAME = "/bundle_version";
// We only need the first 13 to determine if it is suitable for the device.
static const int BUNDLE_VERSION_LENGTH = 13;
// The major version of the bundle format supported by this code as a null-terminated char[].
-static const char REQUIRED_BUNDLE_VERSION[] = "001";
-static const size_t REQUIRED_BUNDLE_VERSION_LEN = sizeof(REQUIRED_BUNDLE_VERSION) - 1; // exclude \0
+static const char SUPPORTED_BUNDLE_MAJOR_VERSION[] = "001";
+// The length of the bundle format major version excluding the \0
+static const size_t SUPPORTED_BUNDLE_MAJOR_VERSION_LEN = sizeof(SUPPORTED_BUNDLE_MAJOR_VERSION) - 1;
+// The minor version of the bundle format supported by this code as a null-terminated char[].
+static const char SUPPORTED_BUNDLE_MINOR_VERSION[] = "001";
+// The length of the bundle format minor version excluding the \0
+static const size_t SUPPORTED_BUNDLE_MINOR_VERSION_LEN = sizeof(SUPPORTED_BUNDLE_MINOR_VERSION) - 1;
+// The length of the bundle format version. e.g. 001.001
+static const size_t SUPPORTED_BUNDLE_VERSION_LEN =
+ SUPPORTED_BUNDLE_MAJOR_VERSION_LEN + SUPPORTED_BUNDLE_MINOR_VERSION_LEN + 1;
// The length of the IANA rules version bytes. e.g. 2016a
static const size_t RULES_VERSION_LEN = 5;
// Bundle version bytes are: AAA.BBB|CCCCC - the rules version is CCCCC
@@ -321,15 +329,38 @@ int main(int argc, char* argv[]) {
return 4;
}
- // Check the first 3 bytes of the bundleVersionHeader: these are the major version (e.g. 001).
- // It must match exactly to be ok. The minor version is currently ignored.
- if (strncmp(&bundleVersion[0], REQUIRED_BUNDLE_VERSION, REQUIRED_BUNDLE_VERSION_LEN) != 0) {
+ std::string actualBundleVersion =
+ std::string(bundleVersion.data(), SUPPORTED_BUNDLE_VERSION_LEN);
+ // Check the first 3 bytes of the bundle version: these are the major version (e.g. 001).
+ // It must match the one we support exactly to be ok.
+ if (strncmp(
+ &bundleVersion[0],
+ SUPPORTED_BUNDLE_MAJOR_VERSION,
+ SUPPORTED_BUNDLE_MAJOR_VERSION_LEN) != 0) {
+
+ LOG(INFO) << "bundle version file " << bundleVersionFileName
+ << " major version is not the required version " << SUPPORTED_BUNDLE_MAJOR_VERSION
+ << ", was \"" << actualBundleVersion << "\". Deleting bundle dir.";
+ // This implies there has been an OTA and the installed bundle is not compatible with the
+ // new version of Android. Remove the installed bundle.
+ deleteConfigUpdaterMetadataDir(dataZoneInfoDir);
+ deleteUpdateBundleDir(dataCurrentDirName);
+ return 5;
+ }
+
+ // Check the last 3 bytes of the bundle version: these are the minor version (e.g. 001).
+ // If the version in the bundle is < the minor version required by this device it cannot be
+ // used.
+ if (strncmp(
+ &bundleVersion[4],
+ SUPPORTED_BUNDLE_MINOR_VERSION,
+ SUPPORTED_BUNDLE_MINOR_VERSION_LEN) < 0) {
+
LOG(INFO) << "bundle version file " << bundleVersionFileName
- << " is not the required version " << REQUIRED_BUNDLE_VERSION
- << ". Deleting bundle dir.";
- // This shouldn't happen with 001, but it in future, this will imply there has been an OTA
- // and the installed bundle is not compatible with the new version of Android. Remove the
- // installed bundle.
+ << " minor version is not the required version " << SUPPORTED_BUNDLE_MINOR_VERSION
+ << ", was \"" << actualBundleVersion << "\". Deleting bundle dir.";
+ // This implies there has been an OTA and the installed bundle is not compatible with the
+ // new version of Android. Remove the installed bundle.
deleteConfigUpdaterMetadataDir(dataZoneInfoDir);
deleteUpdateBundleDir(dataCurrentDirName);
return 5;