Skip to content

Commit

Permalink
Builds Screen Mirroring in CI
Browse files Browse the repository at this point in the history
  • Loading branch information
hufman committed Sep 27, 2021
1 parent b86ed1c commit 7fa9c01
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .github/actions/download-externals-action/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
name: "Download Build Dependencies"
description: "Downloads external dependencies to build AndroidAutoIdrive"
runs:
using: "composite"
steps:
- run: ${{ github.action_path }}/download.sh
shell: bash
5 changes: 5 additions & 0 deletions .github/actions/download-externals-action/download.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash
set -x

[ -e 'external/SmartThings_Classic_v2.1.6_apkpure.com.apk' ] ||
wget --quiet -P external 'https://bimmergestalt.s3.amazonaws.com/aaidrive/external/SmartThings_Classic_v2.1.6_apkpure.com.apk'
10 changes: 10 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ jobs:
with:
fetch-depth: 0
submodules: true

- name: Prepare cached external dependencies
uses: actions/cache@v2
with:
key: addons_external_${{ hashFiles('.github/actions/download-externals-action/download.sh') }}
path: |
external
- name: Download build dependencies
uses: ./.github/actions/download-externals-action

- name: Validate Gradle Wrapper
uses: gradle/wrapper-validation-action@v1
- name: Build the project
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
.DS_Store
/build
/captures
/external
.externalNativeBuild
.cxx
local.properties
16 changes: 16 additions & 0 deletions external/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Car Resources
=============

The car requires that all Connected Apps authenticate with BMW-signed certificate files.
Some components of this project need copies of these official certificate files to log in to the car.
These certificates and other resource files can be found in official Connected Apps, and every compatible Connected App will have a `assets/carapplications` directory inside it's APK File.
This project's build script automatically extracts the needed files from these official APKs during compilation.

Generally, the exact version of the APK doesn't matter, as long as it contains the necessary resources.
The main challenge is that some apps have removed their car compatibility, and so specific older versions need to be found.

Please place copies of the following Android APKs in this `external` directory:
- [SmartThings Classic](https://apkpure.com/smartthings-classic/com.smartthings.android/download/211001-APK?from=versions%2Fversion) v2.3.1 or earlier

After placing these files in this `external` directory, re-run the build process and it should complete successfully.
The build process should automatically extract the necessary files to the proper directories.
68 changes: 68 additions & 0 deletions screen_mirror/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,74 @@ android {
}
}

def RHMISources = [
"Smartthings": [
"com.smartthings.android/com.smartthings.android.p7b": "smartthings/smartthings.p7b",
"com.smartthings.android/rhmi/ui_description.xml": "smartthings/rhmi/ui_description.xml",
"com.smartthings.android/rhmi/bmw/images.zip": "smartthings/rhmi/bmw/images.zip",
"com.smartthings.android/rhmi/common/images.zip": "smartthings/rhmi/common/images.zip",
"com.smartthings.android/rhmi/mini/images.zip": "smartthings/rhmi/mini/images.zip",
]
]

// extract RHMI resources from official apps
task confirmRHMIResources() {
doLast {
def smartthingsFound = new FileNameByRegexFinder().getFileNames(file("../external").toString(), /(?i)smartthings.*classic.*\.apk/)
if (smartthingsFound.isEmpty()) throw new MissingResourceException("Could not locate Smartthings Classic APK in external directory")
}
}

task extractRHMIResources(type: Copy, dependsOn: confirmRHMIResources) {
description "Extracts necessary RHMI resources for compilation"

def destRoot = "src/main/assets/carapplications"

def smartthingsFound = new FileNameByRegexFinder().getFileNames(file("../external").toString(), /(?i)smartthings.*classic.*\.apk/)

def sources = [
"Smartthings": smartthingsFound[0]
]

// actually do the copy
sources.each { sourceZip ->
// only prepare the CopySpec if a destination file from this zip is missing
def missing = RHMISources[sourceZip.key].values().findAll {
!file("$destRoot/$it").exists()
}
if (!missing.isEmpty() && sourceZip.value != null) {
RHMISources[sourceZip.key].each { sourceFile ->
from({ zipTree(sourceZip.value) }) {
include "assets/carapplications/${sourceFile.key}"
eachFile { it.relativePath = new RelativePath(true, sourceFile.value) }
}
}
if (inputs.sourceFiles.empty) throw new MissingResourceException("Could not locate RHMI Resources in provided APK: ${sourceZip.value}")
}
}
into destRoot

// declare the list of expected files, to inform Gradle Caching
def outputFiles = RHMISources.values().collect({ sourceZip ->
sourceZip.values()
}).flatten().collect({
"$destRoot/$it"
})
outputs.files outputFiles

// make extra sure that the correct files were extracted from the APKs
doLast {
def missing = outputFiles.findAll {
!file(it).exists()
}
if (!missing.isEmpty()) {
throw new MissingResourceException("Missing required RHMI files:\n${missing.join("\n")}")
}
}
}

preBuild.dependsOn extractRHMIResources

dependencies {

implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
Expand Down

0 comments on commit 7fa9c01

Please sign in to comment.