1

I am adding a new SystemService to a custom build of Android 11 and I need an aidl interface for apps to communicate with it. I am just starting with the aidl file right now and to keep it simple I just have it like this.

Test.aidl file location is in framewroks/base/code/java/android/os

package android.os;

interface Test{
    void test();
}

When I build the system image again I get a whole bunch of errors related to the generated code file

out/soong/.../frameworks/base/core/java/android/os/Test.java:122: error: Methods calling system APIs should rethrow `RemoteException` as `RuntimeException` (but do not list it in the throws clause) [RethrowRemoteException]
out/soong/.../frameworks/base/core/java/android/os/Test.java:10: error: Methods calling system APIs should rethrow `RemoteException` as `RuntimeException` (but do not list it in the throws clause) [RethrowRemoteException]
out/soong/.../frameworks/base/core/java/android/os/Test.java:13: error: Missing nullability on method `asBinder` return [MissingNullability]
out/soong/.../frameworks/base/core/java/android/os/Test.java:18: error: Raw AIDL interfaces must not be exposed: Stub extends Binder [RawAidl]
out/soong/.../frameworks/base/core/java/android/os/Test.java:27: error: Missing nullability on method `asInterface` return [MissingNullability]
out/soong/.../frameworks/base/core/java/android/os/Test.java:31: error: Missing nullability on parameter `obj` in method `asInterface` [MissingNullability]
out/soong/.../frameworks/base/core/java/android/os/Test.java:42: error: Missing nullability on method `asBinder` return [MissingNullability]
out/soong/.../frameworks/base/core/java/android/os/Test.java:46: error: Methods calling system APIs should rethrow `RemoteException` as `RuntimeException` (but do not list it in the throws clause) [RethrowRemoteException]
out/soong/.../frameworks/base/core/java/android/os/Test.java:46: error: Missing nullability on parameter `data` in method `onTransact` [MissingNullability]
out/soong/.../frameworks/base/core/java/android/os/Test.java:46: error: Missing nullability on parameter `reply` in method `onTransact` [MissingNullability]
out/soong/.../frameworks/base/core/java/android/os/Test.java:105: error: Missing nullability on parameter `impl` in method `setDefaultImpl` [MissingNullability]
out/soong/.../frameworks/base/core/java/android/os/Test.java:118: error: Missing nullability on method `getDefaultImpl` return [MissingNullability]

Edit: With a quick implementation

Adding in a test implementation I basically copied how LocationManagerService was done

public class TestService extends Test.Stub {

    public static class Lifecycle extends SystemService {
        private final TestService mService;

        public Lifecycle(Context context) {
            super(context);
            mService = new TestService(context);
        }

        @Override
        public void onStart() {
            publishBinderService("test_service", mService);
        }

        @Override
        public void onBootPhase(int phase) {
            if (phase == PHASE_SYSTEM_SERVICES_READY) {
                mService.onSystemReady();
            } else if (phase == PHASE_THIRD_PARTY_APPS_CAN_START) {

            }
        }
    }

    public TestService(Context context){

    }

    @Override
    public void test() {
        try {

        } catch (RemoteException e) {

        }
    }

    public void onSystemReady() {

    }

}

then in the SystemService.java class I start the service like this

try{
   mSystemServiceManager.startService(TestService.Lifecycle.class);
}catch (Exception e){

}

The errors still persist.

I dont know what the problem is or how to fix it as this is all errors in the generated java code.

Edit 2:

As pointed out by Ahaan Ugale it looks like the errors are lint checks by the build system, when using @hide on the interface the errors go away but I dont want to hide it. The point of this AIDL file is to have external apps interface with this new system service for this device. If there is another way to accomplish this I am happy to hear it.

2
  • 1
    My best guess is that the Android build system runs internal API checks to validate the custom AIDL and its underlying implementation. This validation fails because you only declared your AIDL but did not provide any implementation or exposed it to clients. Commented Feb 4 at 20:29
  • @Jay I edited my question adding a quick implementation of the interface Commented Feb 4 at 21:03

1 Answer 1

0

These look like errors from the SDK linter. AIDL interfaces added in that directory are by default exposed in the built public SDK. You need to exclude it (as done for the other interfaces there) like this:

/**
 * {@hide}
 */
interface Test {
Sign up to request clarification or add additional context in comments.

5 Comments

the whole point of this new AIDL is for external apps to interface with a new system service I am creating
Just for clarity, using @hide does stop the errors but I dont want to hide it from externals apps. If there is another way to accomplish what I am trying to do I am open to options
AIDL should be an implementation detail of the API, you shouldn't expose it directly. Add a wrapper around the AIDL interface that you can then make sure complies with the API linter. You can't do that with the AIDL interface directly since it's generated code. You could alternatively disable the API linter, but complying with the linter's requirements has some advantages (such as consistency for the API's clients).
wouldn't my TestService class be that implementation of the aidl though?
No, that's the implementation of your service that's running in a system process. The API that apps call would have an implementation running in the app's process, that's making remote calls to your service. Right now, that implementation for you is just the AIDL generated remote-proxy code. You need to add something that wraps that implementation (calls the generated methods internally). A simple file you can see for reference is frameworks/base/core/java/android/view/translation/UiTranslationManager.java. Look at how it wraps calls to the ITranslationManager aidl object.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.