diff --git a/core/api/current.txt b/core/api/current.txt index cdd1deed255d2..855c75ba26275 100644 --- a/core/api/current.txt +++ b/core/api/current.txt @@ -9895,11 +9895,11 @@ package android.companion { public abstract class CompanionDeviceService extends android.app.Service { ctor public CompanionDeviceService(); + method @RequiresPermission(android.Manifest.permission.DELIVER_COMPANION_MESSAGES) public final void dispatchMessage(int, int, @NonNull byte[]); method @Nullable public final android.os.IBinder onBind(@NonNull android.content.Intent); method @MainThread public abstract void onDeviceAppeared(@NonNull String); method @MainThread public abstract void onDeviceDisappeared(@NonNull String); - method @MainThread public void onSendMessage(int, int, @NonNull byte[]); - method @RequiresPermission(android.Manifest.permission.DELIVER_COMPANION_MESSAGES) public final void receiveMessage(int, int, @NonNull byte[]); + method @MainThread public void onDispatchMessage(int, int, @NonNull byte[]); field public static final String SERVICE_INTERFACE = "android.companion.CompanionDeviceService"; } diff --git a/core/java/android/companion/CompanionDeviceManager.java b/core/java/android/companion/CompanionDeviceManager.java index a9e9ba550696e..15de0793edc3f 100644 --- a/core/java/android/companion/CompanionDeviceManager.java +++ b/core/java/android/companion/CompanionDeviceManager.java @@ -445,10 +445,7 @@ public final class CompanionDeviceManager { } /** - * Dispatch received message to system for processing. - * - *

Messages received from {@link CompanionDeviceService#onSendMessage}, which is implemented - * on another device, need to be dispatched to system for processing.

+ * Dispatch a message to system for processing. * *

Calling app must declare uses-permission * {@link android.Manifest.permission#DELIVER_COMPANION_MESSAGES}

@@ -463,10 +460,10 @@ public final class CompanionDeviceManager { * @hide */ @RequiresPermission(android.Manifest.permission.DELIVER_COMPANION_MESSAGES) - public void receiveMessage(int messageId, int associationId, @NonNull byte[] message) + public void dispatchMessage(int messageId, int associationId, @NonNull byte[] message) throws DeviceNotAssociatedException { try { - mService.receiveMessage(messageId, associationId, message); + mService.dispatchMessage(messageId, associationId, message); } catch (RemoteException e) { ExceptionUtils.propagateIfInstanceOf(e.getCause(), DeviceNotAssociatedException.class); throw e.rethrowFromSystemServer(); diff --git a/core/java/android/companion/CompanionDeviceService.java b/core/java/android/companion/CompanionDeviceService.java index 86d6b23c44938..15266d62a9634 100644 --- a/core/java/android/companion/CompanionDeviceService.java +++ b/core/java/android/companion/CompanionDeviceService.java @@ -88,20 +88,21 @@ public abstract class CompanionDeviceService extends Service { public abstract void onDeviceDisappeared(@NonNull String address); /** - * Called by system whenever the system tries to send a message to an associated device. + * Called by system whenever the system dispatches a message to the app to send it to + * an associated device. * * @param messageId system assigned id of the message to be sent * @param associationId association id of the associated device * @param message message to be sent */ @MainThread - public void onSendMessage(int messageId, int associationId, @NonNull byte[] message) { + public void onDispatchMessage(int messageId, int associationId, @NonNull byte[] message) { // do nothing. Companion apps can override this function for system to send messages. } /** - * Called when there's message received from an associated device, which needs to be dispatched - * to system for processing. + * App calls this method when there's a message received from an associated device, + * which needs to be dispatched to system for processing. * *

Calling app must declare uses-permission * {@link android.Manifest.permission#DELIVER_COMPANION_MESSAGES}

@@ -111,10 +112,10 @@ public abstract class CompanionDeviceService extends Service { * @param message messaged received from the associated device */ @RequiresPermission(android.Manifest.permission.DELIVER_COMPANION_MESSAGES) - public final void receiveMessage(int messageId, int associationId, @NonNull byte[] message) { + public final void dispatchMessage(int messageId, int associationId, @NonNull byte[] message) { CompanionDeviceManager companionDeviceManager = getSystemService(CompanionDeviceManager.class); - companionDeviceManager.receiveMessage(messageId, associationId, message); + companionDeviceManager.dispatchMessage(messageId, associationId, message); } @Nullable @@ -144,16 +145,16 @@ public abstract class CompanionDeviceService extends Service { CompanionDeviceService.this, address)); } - public void onSendMessage(int messageId, int associationId, @NonNull byte[] message) { + public void onDispatchMessage(int messageId, int associationId, @NonNull byte[] message) { Handler.getMain().sendMessage(PooledLambda.obtainMessage( - CompanionDeviceService::onSendMessage, + CompanionDeviceService::onDispatchMessage, CompanionDeviceService.this, messageId, associationId, message)); } - public final void receiveMessage(int messageId, int associationId, + public final void dispatchMessage(int messageId, int associationId, @NonNull byte[] message) { Handler.getMain().sendMessage(PooledLambda.obtainMessage( - CompanionDeviceService::receiveMessage, + CompanionDeviceService::dispatchMessage, CompanionDeviceService.this, messageId, associationId, message)); } } diff --git a/core/java/android/companion/ICompanionDeviceManager.aidl b/core/java/android/companion/ICompanionDeviceManager.aidl index 9c2bcf2092fd4..25c5cb3c4b723 100644 --- a/core/java/android/companion/ICompanionDeviceManager.aidl +++ b/core/java/android/companion/ICompanionDeviceManager.aidl @@ -55,5 +55,5 @@ interface ICompanionDeviceManager { void createAssociation(in String packageName, in String macAddress, int userId, in byte[] certificate); - void receiveMessage(in int messageId, in int associationId, in byte[] message); + void dispatchMessage(in int messageId, in int associationId, in byte[] message); } diff --git a/core/java/android/companion/ICompanionDeviceService.aidl b/core/java/android/companion/ICompanionDeviceService.aidl index 921c12467605e..25212a1f10300 100644 --- a/core/java/android/companion/ICompanionDeviceService.aidl +++ b/core/java/android/companion/ICompanionDeviceService.aidl @@ -20,5 +20,5 @@ package android.companion; oneway interface ICompanionDeviceService { void onDeviceAppeared(in String address); void onDeviceDisappeared(in String address); - void onSendMessage(in int messageId, in int associationId, in byte[] message); + void onDispatchMessage(in int messageId, in int associationId, in byte[] message); } diff --git a/services/companion/java/com/android/server/companion/CompanionDeviceManagerService.java b/services/companion/java/com/android/server/companion/CompanionDeviceManagerService.java index e00a63ea5da7f..e3b7fdd8ca7cb 100644 --- a/services/companion/java/com/android/server/companion/CompanionDeviceManagerService.java +++ b/services/companion/java/com/android/server/companion/CompanionDeviceManagerService.java @@ -631,7 +631,7 @@ public class CompanionDeviceManagerService extends SystemService implements Bind } @Override - public void receiveMessage(int messageId, int associationId, byte[] message) + public void dispatchMessage(int messageId, int associationId, byte[] message) throws RemoteException { //TODO: b/199427116 }