turtletramp's blog

Android OS Dev

Some notes to remember

Android 6 AOSP

How to get memory status information

Memory is a critical factor on low end Android devices and it's wise to monitor it when running critical / memory intensive apps while developing these. Fur further details see here.

You are in a critical situation if you can find:

  • `ActivityManager: Process .... (pid ....) has died` in logcat info logs
  • in dmsg you can see `... kill ...`

It's very likely that the lowmemorykiller is triggering this because the active app demands more memory but the system does not have enough available.

To check memory usage you can:

  • `adb shell dumpsys meminfo` which will provide a more clear Android specific memory view (as some parts of memory is shared between apps so it has to be counted differentely)
  • `adb shell free -m` if your system supports busybox
  • `adb shell cat /proc/swaps` in case the target system supports swapping
  • `adb shell cat/proc/meminfo`

Hint's on how to create Android OS system apps with Android Studio

NOTE: Not every part below needs to be done to achieve higher rights as a normal system app but it may help as an incomplete list of possible important things...

What makes an app a system app:

Generating a keystore usable with Android Studio from the platform keys

NOTE: This is only possible if you have access to the platform keys of the OS you are targeting and this is typically only possible if you are creating your own custom ROM or are working for somebody building/developing Android OS based devices.



  • get the keytool-importpair script
  • execute: ./keytool-importkeypair -k ~/.android/my_keystore.jks -p my_password -pk8 $ANDROID_ROOT/build/target/product/security/platform.pk8 -cert $ANDROID_ROOT/build/target/product/security/platform.x509.pem -alias platform -p my_password

To use this keystore there are 2 ways:

Building a signed APK on demand (outside of normal builds)

  • add the new keystore and it's key to Android Studio (Build --> Generate signed Bundle/APK...)
    • in Android Studio choose signing version V1 as V2 will only be allowed starting with Android 7.0 (details see here)

Integrating it in the gradle build (preferred for debugging purpose)

  • either go to Files --> Project structure --> app
  • create a new "Signing" configuration to use your new keystore (in the "Signing" tab)
  • use that signing configuration in the "Build Types" tab parameter "Signing config"

device owner


  • create a /data/system/device_policies.xml file with owner system:system and permissions 600
  • create a /data/system/device_owner_2.xml file with owner system:system and permissions 600
  • example of content of these files see the linke above
  • to have the device owner app preinstalled copy it to /system/priv-app/<somefolder>/<yourapp>.apk and give 600 permissions to system:system owner (on newer systems it might also be the /system_ext/priv-app/... folder
  • in case special permissions are needed check https://source.android.com/docs/core/permissions/perms-allowlist on how to set allowed permissions