Tips&Tricks Android Os Dev (en)
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 [https://source.android.com/devices/tech/perf/low-ram#intro|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 differently)adb shell free -m
if your system supports busyboxadb shell cat /proc/swaps
in case the target system supports swappingadb 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:
- Manifest (
<application>
properties; see also [http://devarea.com/aosp-creating-a-system-application/#.XIjsfYUo9hE])- add coreApp=“true” (will start the app at boot even before user has to enter PIN for encrypted systems and mentioned here: https://caoducquan.wordpress.com/2014/04/23/androidmanifest-xml-coreapp-attribute/)
- set android:sharedUserId=“android.uid.system” (to run your app with the system user privileges)
- to get execution permissions of level signature and signatureOrSystem
- it is stored in the /system partition
- or it is signed with the platform key of the OS itself
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.
References:
- https://stackoverflow.com/questions/51723768/how-to-sign-android-app-with-platform-keys-using-gradle
- https://stackoverflow.com/questions/4247818/android-after-building-platform-source-how-to-sign-arbitrary-apk-with-platform
- https://github.com/getfatday/keytool-importkeypair/blob/master/keytool-importkeypair
Steps:
- 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 [https://stackoverflow.com/questions/44386464/android-app-installation-failed-package-com-my-app-has-no-certificates-at-entry#comment75773013_44386464|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
https://qa.h-mdm.com/2042/grant-device-owner-rights-without-adb-and-enrollment
- 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