Merge changes Ic6b623a7,Ib6811066
* changes:
Makes minor modifications to Intent-based Service APIs
Adds AIDL definitions for register/unregisterIntent
diff --git a/core/java/android/hardware/location/ContextHubClient.java b/core/java/android/hardware/location/ContextHubClient.java
index 5de89e3..56da719 100644
--- a/core/java/android/hardware/location/ContextHubClient.java
+++ b/core/java/android/hardware/location/ContextHubClient.java
@@ -130,30 +130,42 @@
* {@link PendingIntent} through a {@link BroadcastReceiver}, and maps an {@link Intent} to a
* {@link ContextHubClientCallback}.
*
- * @param intent The PendingIntent to register for this client
- * @param nanoAppId the unique ID of the nanoapp to receive events for
+ * @param pendingIntent the PendingIntent to register for this client
+ * @param nanoAppId the unique ID of the nanoapp to receive events for
* @return true on success, false otherwise
*
* @hide
*/
@RequiresPermission(android.Manifest.permission.LOCATION_HARDWARE)
- public boolean registerIntent(@NonNull PendingIntent intent, long nanoAppId) {
- // TODO: Implement this
- return false;
+ public boolean registerIntent(@NonNull PendingIntent pendingIntent, long nanoAppId) {
+ Preconditions.checkNotNull(pendingIntent, "PendingIntent cannot be null");
+
+ try {
+ return mClientProxy.registerIntent(pendingIntent, nanoAppId);
+ } catch (RemoteException e) {
+ throw e.rethrowFromSystemServer();
+ }
}
/**
* Unregisters an intent previously registered via {@link #registerIntent(PendingIntent, long)}.
* If this intent has not been registered for this client, this method returns false.
*
+ * @param pendingIntent the PendingIntent to unregister
+ *
* @return true on success, false otherwise
*
* @hide
*/
@RequiresPermission(android.Manifest.permission.LOCATION_HARDWARE)
- public boolean unregisterIntent(@NonNull PendingIntent intent) {
- // TODO: Implement this
- return false;
+ public boolean unregisterIntent(@NonNull PendingIntent pendingIntent) {
+ Preconditions.checkNotNull(pendingIntent, "PendingIntent cannot be null");
+
+ try {
+ return mClientProxy.unregisterIntent(pendingIntent);
+ } catch (RemoteException e) {
+ throw e.rethrowFromSystemServer();
+ }
}
/**
diff --git a/core/java/android/hardware/location/ContextHubManager.java b/core/java/android/hardware/location/ContextHubManager.java
index 6541ecd..b0b77f3 100644
--- a/core/java/android/hardware/location/ContextHubManager.java
+++ b/core/java/android/hardware/location/ContextHubManager.java
@@ -800,22 +800,22 @@
* through {@link #createClient(ContextHubInfo, ContextHubClientCallback, Executor)} or
* equivalent at an earlier time.
*
- * @param intent the intent that is associated with a client
- * @param hubInfo the hub to attach this client to
- * @param callback the notification callback to register
- * @param executor the executor to invoke the callback
+ * @param pendingIntent the PendingIntent that has been registered with a client
+ * @param hubInfo the hub to attach this client to
+ * @param callback the notification callback to register
+ * @param executor the executor to invoke the callback
* @return the registered client object
*
- * @throws IllegalArgumentException if hubInfo does not represent a valid hub, or the intent
+ * @throws IllegalArgumentException if hubInfo does not represent a valid hub, or pendingIntent
* was not associated with a client
* @throws IllegalStateException if there were too many registered clients at the service
- * @throws NullPointerException if intent, hubInfo, callback, or executor is null
+ * @throws NullPointerException if pendingIntent, hubInfo, callback, or executor is null
*
* @hide
*/
@RequiresPermission(android.Manifest.permission.LOCATION_HARDWARE)
@NonNull public ContextHubClient createClient(
- @NonNull PendingIntent intent, @NonNull ContextHubInfo hubInfo,
+ @NonNull PendingIntent pendingIntent, @NonNull ContextHubInfo hubInfo,
@NonNull ContextHubClientCallback callback,
@NonNull @CallbackExecutor Executor executor) {
// TODO: Implement this
@@ -823,26 +823,27 @@
}
/**
- * Equivalent to {@link #createClient(Intent, ContextHubInfo, ContextHubClientCallback,
+ * Equivalent to {@link #createClient(PendingIntent, ContextHubInfo, ContextHubClientCallback,
* Executor)} with the executor using the main thread's Looper.
*
- * @param intent the intent that is associated with a client
- * @param hubInfo the hub to attach this client to
- * @param callback the notification callback to register
+ * @param pendingIntent the PendingIntent that has been registered with a client
+ * @param hubInfo the hub to attach this client to
+ * @param callback the notification callback to register
* @return the registered client object
*
- * @throws IllegalArgumentException if hubInfo does not represent a valid hub, or the intent
+ * @throws IllegalArgumentException if hubInfo does not represent a valid hub, or pendingIntent
* was not associated with a client
* @throws IllegalStateException if there were too many registered clients at the service
- * @throws NullPointerException if intent, hubInfo, or callback is null
+ * @throws NullPointerException if pendingIntent, hubInfo, or callback is null
*
* @hide
*/
@RequiresPermission(android.Manifest.permission.LOCATION_HARDWARE)
@NonNull public ContextHubClient createClient(
- @NonNull PendingIntent intent, @NonNull ContextHubInfo hubInfo,
+ @NonNull PendingIntent pendingIntent, @NonNull ContextHubInfo hubInfo,
@NonNull ContextHubClientCallback callback) {
- return createClient(intent, hubInfo, callback, new HandlerExecutor(Handler.getMain()));
+ return createClient(
+ pendingIntent, hubInfo, callback, new HandlerExecutor(Handler.getMain()));
}
/**
diff --git a/core/java/android/hardware/location/IContextHubClient.aidl b/core/java/android/hardware/location/IContextHubClient.aidl
index d81126a..7559cd5 100644
--- a/core/java/android/hardware/location/IContextHubClient.aidl
+++ b/core/java/android/hardware/location/IContextHubClient.aidl
@@ -16,6 +16,7 @@
package android.hardware.location;
+import android.app.PendingIntent;
import android.hardware.location.NanoAppMessage;
/**
@@ -28,4 +29,10 @@
// Closes the connection with the Context Hub
void close();
+
+ // Registers a PendingIntent with the client
+ boolean registerIntent(in PendingIntent intent, long nanoAppId);
+
+ // Unregisters a PendingIntent from the client
+ boolean unregisterIntent(in PendingIntent intent);
}
diff --git a/services/core/java/com/android/server/location/ContextHubClientBroker.java b/services/core/java/com/android/server/location/ContextHubClientBroker.java
index 99a04d7..1d0ab8f 100644
--- a/services/core/java/com/android/server/location/ContextHubClientBroker.java
+++ b/services/core/java/com/android/server/location/ContextHubClientBroker.java
@@ -16,6 +16,7 @@
package com.android.server.location;
+import android.app.PendingIntent;
import android.content.Context;
import android.hardware.contexthub.V1_0.ContextHubMsg;
import android.hardware.contexthub.V1_0.IContexthub;
@@ -138,6 +139,27 @@
}
/**
+ * @param intent the intent to register
+ * @param nanoAppId the ID of the nanoapp to send events for
+ * @return true on success, false otherwise
+ */
+ @Override
+ public boolean registerIntent(PendingIntent intent, long nanoAppId) {
+ // TODO: Implement this
+ return false;
+ }
+
+ /**
+ * @param intent the intent to unregister
+ * @return true on success, false otherwise
+ */
+ @Override
+ public boolean unregisterIntent(PendingIntent intent) {
+ // TODO: Implement this
+ return false;
+ }
+
+ /**
* Closes the connection for this client with the service.
*/
@Override