Slide 1

Slide 1 text

Developing system apps without AOSP Erik Helman

Slide 2

Slide 2 text

No content

Slide 3

Slide 3 text

Custom Android Devices

Slide 4

Slide 4 text

Android Developer Boards

Slide 5

Slide 5 text

System Apps vs Regular Apps • Hidden & System APIs • Signature & Permissions • Pre-installed

Slide 6

Slide 6 text

Why? • No AOSP modifications • Developer Tooling • macOS and Windows

Slide 7

Slide 7 text

Using an emulator

Slide 8

Slide 8 text

Using an emulator

Slide 9

Slide 9 text

Using an emulator

Slide 10

Slide 10 text

Using a physical device (Pixel) $ adb shell getprop ro.treble.enabled true

Slide 11

Slide 11 text

Download a Generic System Image

Slide 12

Slide 12 text

Prepare the GSI $ unzip aosp_arm64-img-10018685.zip $ simg2img system.img system_raw.img $ gzip -c system_raw.img > system_raw.gz $ adb push system_raw.gz /storage/emulated/0/Download/

Slide 13

Slide 13 text

Flash a GSI using DSU $ adb shell am start-activity \ -n com.android.dynsystem/com.android.dynsystem.VerificationActivity \ -a android.os.image.action.START_INSTALL \ -d file:///storage/emulated/0/Download/system_raw.gz \ --el KEY_SYSTEM_SIZE $(du -b system_raw.img|cut -f1) \ --el KEY_USERDATA_SIZE

Slide 14

Slide 14 text

Generic System Images documentation developer.android.com/topic/generic-system-image

Slide 15

Slide 15 text

Permission protectionLevel

Slide 16

Slide 16 text

Converting AOSP test certificates to Android keystore $ openssl pkcs8 -inform DER -nocrypt -in platform.pk8 -out platform-signing.key $ openssl pkcs12 -export -in platform.x509.pem -inkey platform.key \ -name platform -out platform-signing.pem -password pass:password $ openssl pkcs12 -export -in platform.x509.pem -inkey platform-signing.key \ -name platform -out platform-signing.pem -password pass:password $ keytool -importkeystore -destkeystore platform-signing.keystore \ -deststorepass password -srckeystore platform.pem -srcstoretype PKCS12 -srcstorepass password

Slide 17

Slide 17 text

Using the platform key for signing signingConfigs { debug { keyAlias 'platform' keyPassword 'password' storeFile rootProject.file('platform-signing.keystore') storePassword 'password' } }

Slide 18

Slide 18 text

Installing from Android Studio

Slide 19

Slide 19 text

Installing on the /system/app or / system/priv-app partition $ adb root $ adb disable-verity $ adb reboot # Wait for device to reboot... $ adb root $ adb remount $ adb shell mkdir /system/app/YourSystemApp $ adb push YourSystemApp.apk /system/app/YourSystemApp $ adb reboot # Not usually needed Remember to bump versionCode!

Slide 20

Slide 20 text

Calling System APIs

Slide 21

Slide 21 text

Permissions frameworks/base/core/res/AndroidManifest.xml

Slide 22

Slide 22 text

Inject input events (InputManager.java)

Slide 23

Slide 23 text

Calling hidden APIs Refelctions (Slow!) private val injectMethod: Method = InputEvent::class.java .getMethod("injectInputEvent", InputEvent::class.java, Int::class.java) fun InputManager.injectEvent(inputEvent: InputEvent) { injectMethod.invoke(this, inputEvent, 0) }

Slide 24

Slide 24 text

Calling hidden APIs Add an interface

Slide 25

Slide 25 text

Calling hidden APIs Add an interface package android.hardware.input; import android.view.InputEvent; public interface InputManager { public boolean injectInputEvent(InputEvent event, int mode); }

Slide 26

Slide 26 text

Calling hidden APIs Extract framework.jar & android.jar 1. Copy files from device or emulator 2. Convert from DEX to Java classes (DexTools) 3. Package into a new android.jar file 4. Replace android.jar in your SDK

Slide 27

Slide 27 text

Calling hidden APIs Build a custom SDK $ mkdir ~/my-android-git $ cd ~/my-android-git $ repo init -u https://android.googlesource.com/platform/manifest \ -b master -g all,-notdefault,tools $ repo sync -j8 # Edit AOSP! $ . build/envsetup.sh $ lunch sdk-eng $ m

Slide 28

Slide 28 text

Android Code Search cs.android.com

Slide 29

Slide 29 text

Interesting @SystemAPI permissions

Slide 30

Slide 30 text

Interesting @SystemAPI permissions

Slide 31

Slide 31 text

Interesting @SystemAPI permissions

Slide 32

Slide 32 text

Summary • How much System APIs do you need to use? • Reflection? • Custom interface • Custom Engineering SDK • Bookmark system AndroidManifest.xml • Navigating cs.andorid.com