summaryrefslogtreecommitdiff
path: root/core/java/android
diff options
context:
space:
mode:
Diffstat (limited to 'core/java/android')
-rw-r--r--core/java/android/service/ambientcontext/AmbientContextDetectionResult.java34
-rw-r--r--core/java/android/service/ambientcontext/AmbientContextDetectionService.java18
-rw-r--r--core/java/android/service/ambientcontext/AmbientContextDetectionServiceStatus.java23
3 files changed, 43 insertions, 32 deletions
diff --git a/core/java/android/service/ambientcontext/AmbientContextDetectionResult.java b/core/java/android/service/ambientcontext/AmbientContextDetectionResult.java
index 227194e60a7e..a216ed501687 100644
--- a/core/java/android/service/ambientcontext/AmbientContextDetectionResult.java
+++ b/core/java/android/service/ambientcontext/AmbientContextDetectionResult.java
@@ -26,6 +26,7 @@ import com.android.internal.util.AnnotationValidations;
import java.util.ArrayList;
import java.util.List;
+import java.util.Objects;
/**
* Represents a {@code AmbientContextEvent} detection result reported by the detection service.
@@ -127,7 +128,9 @@ public final class AmbientContextDetectionResult implements Parcelable {
private @NonNull String mPackageName;
private long mBuilderFieldsSet = 0L;
- public Builder() {
+ public Builder(@NonNull String packageName) {
+ Objects.requireNonNull(packageName);
+ mPackageName = packageName;
}
/**
@@ -144,26 +147,37 @@ public final class AmbientContextDetectionResult implements Parcelable {
}
/**
- * The package to deliver the response to.
+ * Adds a list of events to the builder.
*/
- public @NonNull Builder setPackageName(@NonNull String value) {
+ public @NonNull Builder addEvents(@NonNull List<AmbientContextEvent> values) {
checkNotUsed();
- mBuilderFieldsSet |= 0x2;
- mPackageName = value;
+ if (mEvents == null) {
+ mBuilderFieldsSet |= 0x1;
+ mEvents = new ArrayList<>();
+ }
+ mEvents.addAll(values);
+ return this;
+ }
+
+ /**
+ * Clears all events from the builder.
+ */
+ public @NonNull Builder clearEvents() {
+ checkNotUsed();
+ if (mEvents != null) {
+ mEvents.clear();
+ }
return this;
}
/** Builds the instance. This builder should not be touched after calling this! */
public @NonNull AmbientContextDetectionResult build() {
checkNotUsed();
- mBuilderFieldsSet |= 0x4; // Mark builder used
+ mBuilderFieldsSet |= 0x2; // Mark builder used
if ((mBuilderFieldsSet & 0x1) == 0) {
mEvents = new ArrayList<>();
}
- if ((mBuilderFieldsSet & 0x2) == 0) {
- mPackageName = "";
- }
AmbientContextDetectionResult o = new AmbientContextDetectionResult(
mEvents,
mPackageName);
@@ -171,7 +185,7 @@ public final class AmbientContextDetectionResult implements Parcelable {
}
private void checkNotUsed() {
- if ((mBuilderFieldsSet & 0x4) != 0) {
+ if ((mBuilderFieldsSet & 0x2) != 0) {
throw new IllegalStateException(
"This Builder should not be reused. Use a new Builder instance instead");
}
diff --git a/core/java/android/service/ambientcontext/AmbientContextDetectionService.java b/core/java/android/service/ambientcontext/AmbientContextDetectionService.java
index 6224aa1d102e..8cf34115c6c4 100644
--- a/core/java/android/service/ambientcontext/AmbientContextDetectionService.java
+++ b/core/java/android/service/ambientcontext/AmbientContextDetectionService.java
@@ -134,12 +134,18 @@ public abstract class AmbientContextDetectionService extends Service {
}
/**
- * Starts detection and provides detected events to the statusConsumer. The ongoing detection
- * will keep running, until onStopDetection is called. If there were previously requested
- * detection from the same package, the previous request will be replaced with the new request.
- * The implementation should keep track of whether the user consented each requested
- * AmbientContextEvent for the app. If not consented, the statusConsumer should get a response
- * with STATUS_ACCESS_DENIED.
+ * Called when a client app requests starting detection of the events in the request. The
+ * implementation should keep track of whether the user has explicitly consented to detecting
+ * the events using on-going ambient sensor (e.g. microphone), and agreed to share the
+ * detection results with this client app. If the user has not consented, the detection
+ * should not start, and the statusConsumer should get a response with STATUS_ACCESS_DENIED.
+ * If the user has made the consent and the underlying services are available, the
+ * implementation should start detection and provide detected events to the
+ * detectionResultConsumer. If the type of event needs immediate attention, the implementation
+ * should send result as soon as detected. Otherwise, the implementation can bulk send response.
+ * The ongoing detection will keep running, until onStopDetection is called. If there were
+ * previously requested detection from the same package, regardless of the type of events in
+ * the request, the previous request will be replaced with the new request.
*
* @param request The request with events to detect.
* @param packageName the requesting app's package name
diff --git a/core/java/android/service/ambientcontext/AmbientContextDetectionServiceStatus.java b/core/java/android/service/ambientcontext/AmbientContextDetectionServiceStatus.java
index 3e92f39893de..199e674e4b54 100644
--- a/core/java/android/service/ambientcontext/AmbientContextDetectionServiceStatus.java
+++ b/core/java/android/service/ambientcontext/AmbientContextDetectionServiceStatus.java
@@ -24,6 +24,8 @@ import android.os.Parcelable;
import com.android.internal.util.AnnotationValidations;
+import java.util.Objects;
+
/**
* Represents a status for the {@code AmbientContextDetectionService}.
*
@@ -121,7 +123,9 @@ public final class AmbientContextDetectionServiceStatus implements Parcelable {
private @NonNull String mPackageName;
private long mBuilderFieldsSet = 0L;
- public Builder() {
+ public Builder(@NonNull String packageName) {
+ Objects.requireNonNull(packageName);
+ mPackageName = packageName;
}
/**
@@ -134,27 +138,14 @@ public final class AmbientContextDetectionServiceStatus implements Parcelable {
return this;
}
- /**
- * The package to deliver the response to.
- */
- public @NonNull Builder setPackageName(@NonNull String value) {
- checkNotUsed();
- mBuilderFieldsSet |= 0x2;
- mPackageName = value;
- return this;
- }
-
/** Builds the instance. This builder should not be touched after calling this! */
public @NonNull AmbientContextDetectionServiceStatus build() {
checkNotUsed();
- mBuilderFieldsSet |= 0x4; // Mark builder used
+ mBuilderFieldsSet |= 0x2; // Mark builder used
if ((mBuilderFieldsSet & 0x1) == 0) {
mStatusCode = AmbientContextManager.STATUS_UNKNOWN;
}
- if ((mBuilderFieldsSet & 0x2) == 0) {
- mPackageName = "";
- }
AmbientContextDetectionServiceStatus o = new AmbientContextDetectionServiceStatus(
mStatusCode,
mPackageName);
@@ -162,7 +153,7 @@ public final class AmbientContextDetectionServiceStatus implements Parcelable {
}
private void checkNotUsed() {
- if ((mBuilderFieldsSet & 0x4) != 0) {
+ if ((mBuilderFieldsSet & 0x2) != 0) {
throw new IllegalStateException(
"This Builder should not be reused. Use a new Builder instance instead");
}