javaandroidframeworksandroid-sourceautomotive

Importing Android AOSP "base" Framework for Automotive OS Application in Android Studio


How can I import the Android AOSP "base" framework (specifically I need frameworks/base/core/java/android/hardware/radio/) into Android Studio? Is it possible to import only the framework so the classes I need for my project, or do I need to download the entire repository and build it? My goal is to create an application for Android Automotive OS using the documentation provided at https://source.android.com/docs/devices/automotive/broadcast-radio.

I have tried to download the AOSP source code and I am currently waiting for build it on an Ubuntu environment. However, the process is taking a significant amount of time and resources and I am wondering if there are other options to do it.


Solution

  • Only system apps are allowed to control broadcast radios. This means you cannot create an app which can be downloaded on the Play Store for example.

    Broadcast radio is controlled through the RadioManager service. RadioManager is a system service just like ActivityManager, BatteryManager or AudioManager.

    When you look into the source code of RadioManager you can see this above the AIDL methods:

    @RequiresPermission(Manifest.permission.ACCESS_BROADCAST_RADIO)
    

    So you need to declare this permission in the manifest:

    <uses-permission android:name="android.permission.ACCESS_BROADCAST_RADIO"/>
    

    But Android Studio will tell you that only system apps can get this permission. You need to be a manufacturer or have root access to gain this permission.

    When you have this permission you normally get the RadioManager like this:

    RadioManager m = (RadioManager)getSystemService(Context.RADIO_SERVICE);
    

    Because normally you are building the whole OS you have all these classes.

    If you really want to build your own radio broadcast app without building the whole Android OS you can do this:

    Object o = getSystemService("broadcastradio");
    

    But you will see it returning null because you don't have the permission.

    Let's assume you got a RadioManager object you can use Java reflection to call methods:

    o.getClass().getDeclaredMethod("listModules", ...