0

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.

Lino
  • 5,084
  • 3
  • 21
  • 39

1 Answers1

0

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", ...
zomega
  • 1,538
  • 8
  • 26
  • I did not understand whether RadioManager.java class is accessible (it exists) or not in standard sdk because when I try to declare a RadioManager object I get "cannot resolven symbol". If not, is it accessible only if I build and import AOSP in Android Studio? Thanks in advance – Federico Borci Mar 13 '23 at 11:38
  • @FedericoBorci You will never get permission from the system to access RadioManager. Even if you import the classes. Only system apps which can be created by the device manufacturer will get permission. Are you working at a device manufacturer? – zomega Mar 13 '23 at 12:07
  • No I am not working at a device manufacturer. I just want to make an example of application for AAOS that implements radio (with DAB+ signal) using the following documentation: https://source.android.com/docs/devices/automotive/broadcast-radio – Federico Borci Mar 13 '23 at 14:54
  • @FedericoBorci Well I explained everything in my answer. You don't need to import the classes. You can do reflection. But the OS won't grant you access. – zomega Mar 13 '23 at 15:03