1

I'm building a version of the AOSP for custom hardware and I'd like to use some root permissions (INJECT_EVENTS, UPDATE_DEVICE_STATS, CONNECTIVITY_INTERNAL).

For rev control, it would be ideal to use an APK-based distribution. As such, I'd like to include the APK in the build instead of building the source every time. The program gets successfully included, but the system privileges are ignored.

Is there a way to include this program such that it receives the necessary privileges? I'm hoping there is some connection that either LOCAL_CERTIFICATE, LOCAL_MODULE_CLASS or BUILD_PREBUILT in Android.mk can achieve.

EDIT: The solution was to first determine the signatures that were being used to build the Android system. They existed in /build/target/product/security/platform inside the AOSP. Once I had these signatures, I could then create a new keystore. I then imported the keys into the new keystore using the tool keytool-importkeypair found here.

https://github.com/getfatday/keytool-importkeypair

Once that was done, I could select the keystore inside Android Studio and correctly install and debug the program that had the necessary permissions.

  • There is no such thing as "root privileges" for an app within "android" - no application-provided code in AOSP runs as root. Perhaps you misunderstand how Android permissions and root are entirely orthagonal? Actual "root" execution of application-provided code only exists in various systems which have a root-exploit hack grafted onto them, and is specific to however that hack decides to allow itself to be used. – Chris Stratton Dec 11 '15 at 04:38

2 Answers2

5

Here is what I have: my application is a system application which I develop using Android Studio. When I want to include it in my ROM, here are the steps:

  1. Export the app as an unsigned apk from Android Studio
  2. Place the apk in packages/apps/your_app folder
  3. Use the Android.mk like this:

.

LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE := your_app
LOCAL_CERTIFICATE := platform
LOCAL_PRIVILEGED_MODULE := true // if required
LOCAL_MODULE_CLASS := APPS
LOCAL_SRC_FILES := app-release-unsigned.apk
include $(BUILD_PREBUILT)

In addition to this, you can also generate keystore file from the platform certificates. You can google that, it involves several shell commands (I use the same approach) and then you can run your app on your device from Android Studio with appropriate signing configuration.

Ponnarasu
  • 635
  • 1
  • 11
  • 24
1

So you are making a custom Android build, just need to put your app source in the same directory level with other system apps, such as Phone, Messages, Calendar ... then it will eventually be built and generated as a system app, which will stay in /system/app after burning the image to the hardware.

Pete Houston
  • 14,931
  • 6
  • 47
  • 60
  • That is the way the project was initially set up, but it makes independent app development / revision control a bit of a nightmare. Instead of keeping individual app source inside the AOSP repository, I'd like to keep the app in its own land where any developer can easily "checkout, modify, compile, run" from within Android Studio. Any modifications to the trunk of that application would not be pushed into the AOSP trunk without going through a proper release procedure. – ColoradoIcculus Dec 11 '15 at 21:49
  • 1
    use git if you want to avoid the nightmare problem – Pete Houston Dec 13 '15 at 03:35
  • @PeteHouston I need help here... Developing AOSP with Android Studio 3.1 Cannot build test apk for instrumented tests https://stackoverflow.com/questions/50415724/developing-aosp-with-android-studio-3-1-cannot-build-test-apk-for-instrumented-t – likejudo Jun 15 '18 at 15:59