Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 11d3a37d authored by Kathy Chen's avatar Kathy Chen Committed by Automerger Merge Worker
Browse files

Merge "Address API review feedback for AmbientContext. Add shell method for...

Merge "Address API review feedback for AmbientContext. Add shell method for more test coverage. Do not unregister request from the same client and delegate to AiAi to handle it." into tm-dev am: 4bb44e08

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/17200885

Change-Id: Idce474fb31140cad5cb7cfe843b12bd75a466bcf
parents ad602f02 4bb44e08
Loading
Loading
Loading
Loading
+4 −4
Original line number Original line Diff line number Diff line
@@ -10865,10 +10865,11 @@ package android.service.ambientcontext {
  }
  }
  public static final class AmbientContextDetectionResult.Builder {
  public static final class AmbientContextDetectionResult.Builder {
    ctor public AmbientContextDetectionResult.Builder();
    ctor public AmbientContextDetectionResult.Builder(@NonNull String);
    method @NonNull public android.service.ambientcontext.AmbientContextDetectionResult.Builder addEvent(@NonNull android.app.ambientcontext.AmbientContextEvent);
    method @NonNull public android.service.ambientcontext.AmbientContextDetectionResult.Builder addEvent(@NonNull android.app.ambientcontext.AmbientContextEvent);
    method @NonNull public android.service.ambientcontext.AmbientContextDetectionResult.Builder addEvents(@NonNull java.util.List<android.app.ambientcontext.AmbientContextEvent>);
    method @NonNull public android.service.ambientcontext.AmbientContextDetectionResult build();
    method @NonNull public android.service.ambientcontext.AmbientContextDetectionResult build();
    method @NonNull public android.service.ambientcontext.AmbientContextDetectionResult.Builder setPackageName(@NonNull String);
    method @NonNull public android.service.ambientcontext.AmbientContextDetectionResult.Builder clearEvents();
  }
  }
  public abstract class AmbientContextDetectionService extends android.app.Service {
  public abstract class AmbientContextDetectionService extends android.app.Service {
@@ -10889,9 +10890,8 @@ package android.service.ambientcontext {
  }
  }
  public static final class AmbientContextDetectionServiceStatus.Builder {
  public static final class AmbientContextDetectionServiceStatus.Builder {
    ctor public AmbientContextDetectionServiceStatus.Builder();
    ctor public AmbientContextDetectionServiceStatus.Builder(@NonNull String);
    method @NonNull public android.service.ambientcontext.AmbientContextDetectionServiceStatus build();
    method @NonNull public android.service.ambientcontext.AmbientContextDetectionServiceStatus build();
    method @NonNull public android.service.ambientcontext.AmbientContextDetectionServiceStatus.Builder setPackageName(@NonNull String);
    method @NonNull public android.service.ambientcontext.AmbientContextDetectionServiceStatus.Builder setStatusCode(int);
    method @NonNull public android.service.ambientcontext.AmbientContextDetectionServiceStatus.Builder setStatusCode(int);
  }
  }
+24 −10
Original line number Original line Diff line number Diff line
@@ -26,6 +26,7 @@ import com.android.internal.util.AnnotationValidations;


import java.util.ArrayList;
import java.util.ArrayList;
import java.util.List;
import java.util.List;
import java.util.Objects;


/**
/**
 * Represents a {@code AmbientContextEvent} detection result reported by the detection service.
 * 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 @NonNull String mPackageName;
        private long mBuilderFieldsSet = 0L;
        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();
            checkNotUsed();
            mBuilderFieldsSet |= 0x2;
            if (mEvents == null) {
            mPackageName = value;
                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;
            return this;
        }
        }


        /** Builds the instance. This builder should not be touched after calling this! */
        /** Builds the instance. This builder should not be touched after calling this! */
        public @NonNull AmbientContextDetectionResult build() {
        public @NonNull AmbientContextDetectionResult build() {
            checkNotUsed();
            checkNotUsed();
            mBuilderFieldsSet |= 0x4; // Mark builder used
            mBuilderFieldsSet |= 0x2; // Mark builder used


            if ((mBuilderFieldsSet & 0x1) == 0) {
            if ((mBuilderFieldsSet & 0x1) == 0) {
                mEvents = new ArrayList<>();
                mEvents = new ArrayList<>();
            }
            }
            if ((mBuilderFieldsSet & 0x2) == 0) {
                mPackageName = "";
            }
            AmbientContextDetectionResult o = new AmbientContextDetectionResult(
            AmbientContextDetectionResult o = new AmbientContextDetectionResult(
                    mEvents,
                    mEvents,
                    mPackageName);
                    mPackageName);
@@ -171,7 +185,7 @@ public final class AmbientContextDetectionResult implements Parcelable {
        }
        }


        private void checkNotUsed() {
        private void checkNotUsed() {
            if ((mBuilderFieldsSet & 0x4) != 0) {
            if ((mBuilderFieldsSet & 0x2) != 0) {
                throw new IllegalStateException(
                throw new IllegalStateException(
                        "This Builder should not be reused. Use a new Builder instance instead");
                        "This Builder should not be reused. Use a new Builder instance instead");
            }
            }
+12 −6
Original line number Original line Diff line number Diff line
@@ -134,12 +134,18 @@ public abstract class AmbientContextDetectionService extends Service {
    }
    }


    /**
    /**
     * Starts detection and provides detected events to the statusConsumer. The ongoing detection
     * Called when a client app requests starting detection of the events in the request. The
     * will keep running, until onStopDetection is called. If there were previously requested
     * implementation should keep track of whether the user has explicitly consented to detecting
     * detection from the same package, the previous request will be replaced with the new request.
     * the events using on-going ambient sensor (e.g. microphone), and agreed to share the
     * The implementation should keep track of whether the user consented each requested
     * detection results with this client app. If the user has not consented, the detection
     * AmbientContextEvent for the app. If not consented, the statusConsumer should get a response
     * should not start, and the statusConsumer should get a response with STATUS_ACCESS_DENIED.
     * 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 request The request with events to detect.
     * @param packageName the requesting app's package name
     * @param packageName the requesting app's package name
+7 −16
Original line number Original line Diff line number Diff line
@@ -24,6 +24,8 @@ import android.os.Parcelable;


import com.android.internal.util.AnnotationValidations;
import com.android.internal.util.AnnotationValidations;


import java.util.Objects;

/**
/**
 * Represents a status for the {@code AmbientContextDetectionService}.
 * Represents a status for the {@code AmbientContextDetectionService}.
 *
 *
@@ -121,7 +123,9 @@ public final class AmbientContextDetectionServiceStatus implements Parcelable {
        private @NonNull String mPackageName;
        private @NonNull String mPackageName;
        private long mBuilderFieldsSet = 0L;
        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;
            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! */
        /** Builds the instance. This builder should not be touched after calling this! */
        public @NonNull AmbientContextDetectionServiceStatus build() {
        public @NonNull AmbientContextDetectionServiceStatus build() {
            checkNotUsed();
            checkNotUsed();
            mBuilderFieldsSet |= 0x4; // Mark builder used
            mBuilderFieldsSet |= 0x2; // Mark builder used


            if ((mBuilderFieldsSet & 0x1) == 0) {
            if ((mBuilderFieldsSet & 0x1) == 0) {
                mStatusCode = AmbientContextManager.STATUS_UNKNOWN;
                mStatusCode = AmbientContextManager.STATUS_UNKNOWN;
            }
            }
            if ((mBuilderFieldsSet & 0x2) == 0) {
                mPackageName = "";
            }
            AmbientContextDetectionServiceStatus o = new AmbientContextDetectionServiceStatus(
            AmbientContextDetectionServiceStatus o = new AmbientContextDetectionServiceStatus(
                    mStatusCode,
                    mStatusCode,
                    mPackageName);
                    mPackageName);
@@ -162,7 +153,7 @@ public final class AmbientContextDetectionServiceStatus implements Parcelable {
        }
        }


        private void checkNotUsed() {
        private void checkNotUsed() {
            if ((mBuilderFieldsSet & 0x4) != 0) {
            if ((mBuilderFieldsSet & 0x2) != 0) {
                throw new IllegalStateException(
                throw new IllegalStateException(
                        "This Builder should not be reused. Use a new Builder instance instead");
                        "This Builder should not be reused. Use a new Builder instance instead");
            }
            }
+3 −4
Original line number Original line Diff line number Diff line
@@ -171,16 +171,15 @@ final class AmbientContextManagerPerUserService extends
                return;
                return;
            }
            }


            // Remove any existing intent and unregister for this package before adding a new one.
            // Remove any existing PendingIntent for this package.
            String callingPackage = pendingIntent.getCreatorPackage();
            String callingPackage = pendingIntent.getCreatorPackage();
            PendingIntent duplicatePendingIntent = findExistingRequestByPackage(callingPackage);
            PendingIntent duplicatePendingIntent = findExistingRequestByPackage(callingPackage);
            if (duplicatePendingIntent != null) {
            if (duplicatePendingIntent != null) {
                Slog.d(TAG, "Unregister duplicate request from " + callingPackage);
                Slog.d(TAG, "Replace duplicate request from " + callingPackage);
                onUnregisterObserver(callingPackage);
                mExistingPendingIntents.remove(duplicatePendingIntent);
                mExistingPendingIntents.remove(duplicatePendingIntent);
            }
            }


            // Register new package and add request to mExistingRequests
            // Register package and add pendingIntent to mExistingPendingIntents
            startDetection(request, callingPackage, createDetectionResultRemoteCallback(),
            startDetection(request, callingPackage, createDetectionResultRemoteCallback(),
                    getServerStatusCallback(clientStatusCallback));
                    getServerStatusCallback(clientStatusCallback));
            mExistingPendingIntents.add(pendingIntent);
            mExistingPendingIntents.add(pendingIntent);
Loading