admin管理员组

文章数量:1415673

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.

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.

Share Improve this question edited Feb 5 at 13:44 tyczj asked Feb 4 at 19:51 tyczjtyczj 74.2k57 gold badges208 silver badges311 bronze badges Recognized by Mobile Development Collective 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. – Jay Commented Feb 4 at 20:29
  • @Jay I edited my question adding a quick implementation of the interface – tyczj Commented Feb 4 at 21:03
Add a comment  | 

1 Answer 1

Reset to default 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 {

本文标签: androidCreating an AIDL file to communicate with a service in AOSPStack Overflow