Skip to content

Commit

Permalink
Updater: Android Studio support
Browse files Browse the repository at this point in the history
See README-STUDIO.txt for more info.

Change-Id: Ie673bba5618b0f00a585049cd85687a64db2b420
  • Loading branch information
Gabriele M committed Jan 23, 2018
1 parent 7005b00 commit 3fc1749
Show file tree
Hide file tree
Showing 6 changed files with 189 additions and 0 deletions.
13 changes: 13 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
*.iml
.gradle
/local.properties
.idea
.DS_Store
/build
/captures
/gradle
/gradlew
/gradlew.bat
/system_libs/*.jar
/keystore.properties
*.jks
21 changes: 21 additions & 0 deletions Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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 $@
14 changes: 14 additions & 0 deletions README-STUDIO.txt
Original file line number Diff line number Diff line change
@@ -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'.
70 changes: 70 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -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}"
}
67 changes: 67 additions & 0 deletions gen-keystore.sh
Original file line number Diff line number Diff line change
@@ -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 <<EOF
keyAlias=$KEY_ALIAS
keyPassword=$KEY_PASSWORD
storeFile=$KEYSTORE_PATH
storePassword=$KEYSTORE_PASSWORD
EOF
4 changes: 4 additions & 0 deletions keystore.properties.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
keyAlias=android
keyPassword=android
storeFile=testkey.jks
storePassword=android

0 comments on commit 3fc1749

Please sign in to comment.