- Create an android studio project with simple activity
- Design:
- add Edittext, button and textview
- Change the layout to LinearLayout with vertical orientation
- Code
- Change the superclass to Activity
- Implement the button click event – read the text in the edittext control, convert to uppercase and write to the textview control
- Build and run on the emulator
Add the application to AOSP
- Create a folder “app” in ~/aosp/device/generic/goldfish
- Add the following Android.mk file
include $(call all-subdir-makefiles)
- Create a new directory “sysapp” in the folder app for the system application
- Copy the files from the android studio project to the new folder:
cp ~/AndroidStudioProjects/SysApp/app/src/main/* -r .
- Add the following Android.mk file to sysapp folder:
LOCAL_PATH:= $(call my-dir) include $(CLEAR_VARS) LOCAL_MODULE_TAGS := eng LOCAL_SRC_FILES := $(call all-java-files-under,java) LOCAL_PACKAGE_NAME := sysapp include $(BUILD_PACKAGE)
- Use mm to build the code – remove styles to make it compiled
- build the emulator and test your work
Make Your Application Run with System Privileges
Add coreApp and sharedUserId to the manifest file:
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="app.mabel.com.jnitest" coreApp="true" android:sharedUserId="android.uid.system"> .... </manifest>
Add the following vars to main Android.mk file:
LOCAL_CERTIFICATE := platform LOCAL_PRIVILEGED_MODULE := true
Build the rom and test your work
Now run the application, connect to the device using adb and run ps -A to see all the processes. You will see application run as system user