Merge "Add prebuild and postbuild info to OTA_analysis." am: afcbcc7149 am: 2b8dd5e2b4

Original change: https://android-review.googlesource.com/c/platform/development/+/1779885

Change-Id: I12447e612c6e8191feadf72482a9edf8aefadd1b
This commit is contained in:
Treehugger Robot
2021-07-28 20:10:43 +00:00
committed by Automerger Merge Worker
2 changed files with 88 additions and 5 deletions

View File

@@ -13,6 +13,22 @@
</li>
</ul>
</div>
<div
v-if="payload && payload.metadata"
v-bind="$attrs"
>
<ul class="align">
<li
v-for="formatter in MetadataFormat"
:key="formatter.name"
>
<strong> {{ formatter.name }} </strong>
<p class="wrap">
{{ String(payload[formatter.key]) }}
</p>
</li>
</ul>
</div>
<div v-if="payload && payload.manifest">
<ul class="align">
<li>
@@ -47,7 +63,7 @@
</template>
<script>
import { Payload } from '@/services/payload.js'
import { Payload, MetadataFormat } from '@/services/payload.js'
export default {
props: {
@@ -60,6 +76,11 @@ export default {
required: true,
},
},
data() {
return {
MetadataFormat
}
}
}
</script>
@@ -75,4 +96,16 @@ export default {
.align strong::after {
content: ':';
}
li {
list-style-type: none;
}
.wrap {
width: 50%;
display: inline-block;
white-space: pre-wrap;
word-wrap: break-word;
font-family: inherit;
}
</style>

View File

@@ -10,11 +10,33 @@
import * as zip from '@zip.js/zip.js/dist/zip-full.min.js'
import { chromeos_update_engine as update_metadata_pb } from './update_metadata_pb.js'
const /** Number */ _MAGIC = 'CrAU'
const /** String */ _MAGIC = 'CrAU'
const /** Number */ _VERSION_SIZE = 8
const /** Number */ _MANIFEST_LEN_SIZE = 8
const /** Number */ _METADATA_SIGNATURE_LEN_SIZE = 4
const /** Number */ _BRILLO_MAJOR_PAYLOAD_VERSION = 2
export const /** Array<Object> */ MetadataFormat = [
{
prefix: 'pre-build',
key: 'preBuild',
name: 'Pre-build'
},
{
prefix: 'pre-build-incremental',
key: 'preBuildVersion',
name: 'Pre-build version'
},
{
prefix: 'post-build',
key: 'postBuild',
name: 'Post-build'
},
{
prefix: 'post-build-incremental',
key: 'postBuildVersion',
name: 'Post-build version'
}
]
export class Payload {
/**
@@ -26,7 +48,10 @@ export class Payload {
this.cursor = 0
}
async unzipPayload() {
/**
* Unzip the OTA package, get payload.bin and metadata
*/
async unzip() {
let /** Array<Entry> */ entries = await this.packedFile.getEntries()
this.payload = null
for (let entry of entries) {
@@ -34,6 +59,9 @@ export class Payload {
//TODO: only read in the manifest instead of the whole payload
this.payload = await entry.getData(new zip.BlobWriter())
}
if (entry.filename == 'META-INF/com/android/metadata') {
this.metadata = await entry.getData(new zip.TextWriter())
}
}
if (!this.payload) {
alert('Please select a legit OTA package')
@@ -106,11 +134,22 @@ export class Payload {
.decode(signature_raw)
}
parseMetadata() {
for (let formatter of MetadataFormat) {
let regex = new RegExp(formatter.prefix + '.+')
if (this.metadata.match(regex)) {
this[formatter.key] =
trimEntry(this.metadata.match(regex)[0], formatter.prefix)
} else this[formatter.key] = ''
}
}
async init() {
await this.unzipPayload()
await this.unzip()
this.readHeader()
this.readManifest()
this.readSignature()
this.parseMetadata()
}
}
@@ -149,7 +188,7 @@ export class MergeOpType {
export function octToHex(bufferArray, space = true, maxLine = 16) {
let hex_table = ''
for (let i = 0; i < bufferArray.length; i++) {
if (bufferArray[i].toString(16).length===2) {
if (bufferArray[i].toString(16).length === 2) {
hex_table += bufferArray[i].toString(16) + (space ? ' ' : '')
} else {
hex_table += '0' + bufferArray[i].toString(16) + (space ? ' ' : '')
@@ -159,4 +198,15 @@ export function octToHex(bufferArray, space = true, maxLine = 16) {
}
}
return hex_table
}
/**
* Trim the prefix in an entry. This is required because the lookbehind
* regular expression is not supported in safari yet.
* @param {String} entry
* @param {String} prefix
* @return String
*/
function trimEntry(entry, prefix) {
return entry.slice(prefix.length + 1, entry.length)
}