- 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
1 |
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:
1 |
cp ~/AndroidStudioProjects/SysApp/app/src/main/* -r . |
- Add the following Android.mk file to sysapp folder:
1 2 3 4 5 6 |
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:
1 2 3 4 5 6 7 8 |
<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:
1 2 |
LOCAL_CERTIFICATE := platform LOCAL_PRIVILEGED_MODULE := true</span> |
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