From 3fc17494eb5621da7bbd652dd8622e686da0c3cf Mon Sep 17 00:00:00 2001 From: Gabriele M Date: Thu, 30 Nov 2017 23:41:00 +0100 Subject: [PATCH] Updater: Android Studio support See README-STUDIO.txt for more info. Change-Id: Ie673bba5618b0f00a585049cd85687a64db2b420 --- .gitignore | 13 +++++++ Android.mk | 21 ++++++++++++ README-STUDIO.txt | 14 ++++++++ build.gradle | 70 ++++++++++++++++++++++++++++++++++++++ gen-keystore.sh | 67 ++++++++++++++++++++++++++++++++++++ keystore.properties.sample | 4 +++ 6 files changed, 189 insertions(+) create mode 100644 .gitignore create mode 100644 README-STUDIO.txt create mode 100644 build.gradle create mode 100755 gen-keystore.sh create mode 100644 keystore.properties.sample diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..0df13ab2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,13 @@ +*.iml +.gradle +/local.properties +.idea +.DS_Store +/build +/captures +/gradle +/gradlew +/gradlew.bat +/system_libs/*.jar +/keystore.properties +*.jks diff --git a/Android.mk b/Android.mk index 835e737f..0aeea1f1 100644 --- a/Android.mk +++ b/Android.mk @@ -35,3 +35,24 @@ LOCAL_PRIVILEGED_MODULE := true LOCAL_PROGUARD_FLAG_FILES := proguard.flags include $(BUILD_PACKAGE) + + +include $(CLEAR_VARS) +LOCAL_MODULE := UpdaterStudio +LOCAL_MODULE_CLASS := FAKE +LOCAL_MODULE_SUFFIX := -timestamp +updater_system_deps := $(call java-lib-deps,framework) +updater_system_libs_path := $(abspath $(LOCAL_PATH))/system_libs + +include $(BUILD_SYSTEM)/base_rules.mk + +.PHONY: copy_updater_system_deps +copy_updater_system_deps: $(updater_system_deps) + $(hide) mkdir -p $(updater_system_libs_path) + $(hide) rm -rf $(updater_system_libs_path)/*.jar + $(hide) cp $(updater_system_deps) $(updater_system_libs_path)/framework.jar + +$(LOCAL_BUILT_MODULE): copy_updater_system_deps + $(hide) echo "Fake: $@" + $(hide) mkdir -p $(dir $@) + $(hide) touch $@ diff --git a/README-STUDIO.txt b/README-STUDIO.txt new file mode 100644 index 00000000..32c9aac5 --- /dev/null +++ b/README-STUDIO.txt @@ -0,0 +1,14 @@ +How to build with Android Studio +================================ + +Updater needs access to the system API, therefore it can't be built only using +the public SDK. You first need to generate the libraries with all the needed +classes. The application also needs elevated privileges, so you need to sign +it with the right key to update the one in the system partition. To do this: + + - Generate a keystore and keystore.properties using gen-keystore.sh + - Build the dependencies running 'make UpdaterStudio'. This command will add + the needed libraries in system_libraries/. + +You need to do the above once, unless Android Studio can't find some symbol. +In this case, rebuild the system libraries with 'make UpdaterStudio'. diff --git a/build.gradle b/build.gradle new file mode 100644 index 00000000..454da2a9 --- /dev/null +++ b/build.gradle @@ -0,0 +1,70 @@ +repositories { + google() + jcenter() +} + +buildscript { + repositories { + google() + jcenter() + } + + dependencies { + classpath 'com.android.tools.build:gradle:3.0.1' + } +} + +def keystorePropertiesFile = rootProject.file("keystore.properties") +def keystoreProperties = new Properties() +keystoreProperties.load(new FileInputStream(keystorePropertiesFile)) + +apply plugin: 'com.android.application' + +android { + compileSdkVersion 24 + buildToolsVersion '26.0.3' + + defaultConfig { + minSdkVersion 24 + targetSdkVersion 24 + } + + lintOptions { + ignore 'ProtectedPermissions' + // These depend on translations + ignore 'ExtraTranslation', 'ImpliedQuantity', 'MissingQuantity', 'MissingTranslation' + } + + sourceSets { + main { + res.srcDirs = ['res'] + java.srcDirs = ['src'] + manifest.srcFile 'AndroidManifest.xml' + } + } + + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + + signingConfigs { + debug { + keyAlias keystoreProperties['keyAlias'] + keyPassword keystoreProperties['keyPassword'] + storeFile file(keystoreProperties['storeFile']) + storePassword keystoreProperties['storePassword'] + } + } +} + +dependencies { + compileOnly fileTree(dir: 'system_libs/', include: ['*.jar']) + + def supportLibVersion = "24.2.1" + implementation "com.android.support:appcompat-v7:${supportLibVersion}" + implementation "com.android.support:cardview-v7:${supportLibVersion}" + implementation "com.android.support:design:${supportLibVersion}" + implementation "com.android.support:preference-v7:${supportLibVersion}" + implementation "com.android.support:recyclerview-v7:${supportLibVersion}" +} diff --git a/gen-keystore.sh b/gen-keystore.sh new file mode 100755 index 00000000..ee3d0e80 --- /dev/null +++ b/gen-keystore.sh @@ -0,0 +1,67 @@ +#!/bin/sh + +if [ $# -ne 6 ]; then + echo "Usage: `basename $0` PRIVATE_KEY CERTIFICATE \\" + echo " KEYSTORE_PASSWRD KEY_PASSWORD KEY_ALIAS \\" + echo " OUTPUT_KEYSTORE_PATH" + echo + echo "Example:" + echo " `basename $0` \\" + echo " ../../../build/target/product/security/testkey.pk8 \\" + echo " ../../../build/target/product/security/testkey.x509.pem \\" + echo " keystore-password key-password android testkey.jks" + exit 0 +fi + +PRIVATE_KEY="$1" +CERTIFICATE="$2" +KEYSTORE_PASSWORD="$3" +KEY_PASSWORD="$4" +KEY_ALIAS="$5" +KEYSTORE_PATH="$6" + +if [ -f "$KEYSTORE_PATH" ]; then + echo "$KEYSTORE_PATH already exists" + exit 1 +fi + +tmpdir=`mktemp -d` +trap 'rm -rf $tmpdir;' 0 + +key="$tmpdir/platform.key" +pk12="$tmpdir/platform.pk12" +openssl pkcs8 -in "$PRIVATE_KEY" -inform DER -outform PEM -nocrypt -out "$key" +if [ $? -ne 0 ]; then + exit 1 +fi +openssl pkcs12 -export -in "$CERTIFICATE" -inkey "$key" -name "$KEY_ALIAS" \ + -out "$pk12" -password pass:"$KEY_PASSWORD" +if [ $? -ne 0 ]; then + exit 1 +fi + +keytool -importkeystore \ + -srckeystore "$pk12" -srcstoretype pkcs12 -srcstorepass "$KEY_PASSWORD" \ + -destkeystore "$KEYSTORE_PATH" -deststorepass "$KEYSTORE_PASSWORD" \ + -destkeypass "$KEY_PASSWORD" +if [ $? -ne 0 ]; then + exit 1 +fi + + +echo +echo "Generating keystore.properties..." +if [ -f keystore.properties ]; then + echo "keystore.properties already exists, overwrite it? [Y/n]" + read reply + if [ "$reply" = "n" -o "$reply" = "N" ]; then + exit 0 + fi +fi + +cat > keystore.properties <