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

Commit fde9ae34 authored by Daniel Kim's avatar Daniel Kim Committed by Android (Google) Code Review
Browse files

Merge "Adding proximity endpoints to Attention Service Test: atest...

Merge "Adding proximity endpoints to Attention Service Test: atest AttentionManagerServiceTest Bug: 214395649"
parents da6dafc0 654abc50
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -10648,6 +10648,8 @@ package android.service.attention {
    method @Nullable public final android.os.IBinder onBind(@NonNull android.content.Intent);
    method public abstract void onCancelAttentionCheck(@NonNull android.service.attention.AttentionService.AttentionCallback);
    method public abstract void onCheckAttention(@NonNull android.service.attention.AttentionService.AttentionCallback);
    method public void onStartProximityUpdates(@NonNull android.service.attention.AttentionService.ProximityCallback);
    method public void onStopProximityUpdates();
    field public static final int ATTENTION_FAILURE_CAMERA_PERMISSION_ABSENT = 6; // 0x6
    field public static final int ATTENTION_FAILURE_CANCELLED = 3; // 0x3
    field public static final int ATTENTION_FAILURE_PREEMPTED = 4; // 0x4
@@ -10655,6 +10657,7 @@ package android.service.attention {
    field public static final int ATTENTION_FAILURE_UNKNOWN = 2; // 0x2
    field public static final int ATTENTION_SUCCESS_ABSENT = 0; // 0x0
    field public static final int ATTENTION_SUCCESS_PRESENT = 1; // 0x1
    field public static final double PROXIMITY_UNKNOWN = -1.0;
    field public static final String SERVICE_INTERFACE = "android.service.attention.AttentionService";
  }
@@ -10663,6 +10666,10 @@ package android.service.attention {
    method public void onSuccess(int, long);
  }
  public static final class AttentionService.ProximityCallback {
    method public void onProximityUpdate(double);
  }
}
package android.service.autofill {
+28 −0
Original line number Diff line number Diff line
@@ -46,6 +46,25 @@ public abstract class AttentionManagerInternal {
     */
    public abstract void cancelAttentionCheck(AttentionCallbackInternal callback);

    /**
     * Requests the continuous updates of proximity signal via the provided callback,
     * until the given callback is unregistered. Currently, AttentionManagerService only
     * anticipates one client and updates one client at a time. If a new client wants to
     * onboard to receiving Proximity updates, please make a feature request to make proximity
     * feature multi-client before depending on this feature.
     *
     * @param callback      a callback that receives the proximity updates
     * @return {@code true} if the registration should succeed.
     */
    public abstract boolean onStartProximityUpdates(ProximityCallbackInternal callback);

    /**
     * Requests to stop providing continuous updates until the callback is registered.
     *
     * @param callback a callback that was used in {@link #onStartProximityUpdates}
     */
    public abstract void onStopProximityUpdates(ProximityCallbackInternal callback);

    /** Internal interface for attention callback. */
    public abstract static class AttentionCallbackInternal {
        /**
@@ -64,4 +83,13 @@ public abstract class AttentionManagerInternal {
         */
        public abstract void onFailure(int error);
    }

    /** Internal interface for proximity callback. */
    public abstract static class ProximityCallbackInternal {
        /**
         * @param distance the estimated distance of the user (in meter)
         * The distance will be PROXIMITY_UNKNOWN if the proximity sensing was inconclusive.
         */
        public abstract void onProximityUpdate(double distance);
    }
}
+60 −0
Original line number Diff line number Diff line
@@ -24,11 +24,14 @@ import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.os.RemoteException;
import android.util.Slog;

import com.android.internal.util.Preconditions;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.ref.WeakReference;
import java.util.Objects;


/**
@@ -51,6 +54,7 @@ import java.lang.annotation.RetentionPolicy;
 */
@SystemApi
public abstract class AttentionService extends Service {
    private static final String LOG_TAG = "AttentionService";
    /**
     * The {@link Intent} that must be declared as handled by the service. To be supported, the
     * service must also require the {@link android.Manifest.permission#BIND_ATTENTION_SERVICE}
@@ -80,6 +84,9 @@ public abstract class AttentionService extends Service {
    /** Camera permission is not granted. */
    public static final int ATTENTION_FAILURE_CAMERA_PERMISSION_ABSENT = 6;

    /** Users’ proximity is unknown (proximity sensing was inconclusive and is unsupported). */
    public static final double PROXIMITY_UNKNOWN = -1;

    /**
     * Result codes for when attention check was successful.
     *
@@ -118,6 +125,20 @@ public abstract class AttentionService extends Service {
            Preconditions.checkNotNull(callback);
            AttentionService.this.onCancelAttentionCheck(new AttentionCallback(callback));
        }

        /** {@inheritDoc} */
        @Override
        public void onStartProximityUpdates(IProximityCallback callback) {
            Objects.requireNonNull(callback);
            AttentionService.this.onStartProximityUpdates(new ProximityCallback(callback));

        }

        /** {@inheritDoc} */
        @Override
        public void onStopProximityUpdates() {
            AttentionService.this.onStopProximityUpdates();
        }
    };

    @Nullable
@@ -143,6 +164,23 @@ public abstract class AttentionService extends Service {
     */
    public abstract void onCancelAttentionCheck(@NonNull AttentionCallback callback);

    /**
     * Requests the continuous updates of proximity signal via the provided callback,
     * until the given callback is unregistered.
     *
     * @param callback the callback to return the result to
     */
    public void onStartProximityUpdates(@NonNull ProximityCallback callback) {
        Slog.w(LOG_TAG, "Override this method.");
    }

    /**
     * Requests to stop providing continuous updates until the callback is registered.
     */
    public void onStopProximityUpdates() {
        Slog.w(LOG_TAG, "Override this method.");
    }

    /** Callbacks for AttentionService results. */
    public static final class AttentionCallback {
        @NonNull private final IAttentionCallback mCallback;
@@ -174,4 +212,26 @@ public abstract class AttentionService extends Service {
            }
        }
    }

    /** Callbacks for ProximityCallback results. */
    public static final class ProximityCallback {
        @NonNull private final WeakReference<IProximityCallback> mCallback;

        private ProximityCallback(@NonNull IProximityCallback callback) {
            mCallback = new WeakReference<>(callback);
        }

        /**
         * @param distance the estimated distance of the user (in meter)
         * The distance will be PROXIMITY_UNKNOWN if the proximity sensing was inconclusive.
         *
         */
        public void onProximityUpdate(double distance) {
            try {
                mCallback.get().onProximityUpdate(distance);
            } catch (RemoteException e) {
                e.rethrowFromSystemServer();
            }
        }
    }
}
+3 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package android.service.attention;

import android.service.attention.IAttentionCallback;
import android.service.attention.IProximityCallback;

/**
 * Interface for a concrete implementation to provide to the AttentionManagerService.
@@ -26,4 +27,6 @@ import android.service.attention.IAttentionCallback;
oneway interface IAttentionService {
    void checkAttention(IAttentionCallback callback);
    void cancelAttentionCheck(IAttentionCallback callback);
    void onStartProximityUpdates(IProximityCallback callback);
    void onStopProximityUpdates();
}
 No newline at end of file
+10 −0
Original line number Diff line number Diff line
package android.service.attention;

/**
 * Callback for onStartProximityUpdates request.
 *
 * @hide
 */
oneway interface IProximityCallback {
    void onProximityUpdate(double distance);
}
Loading