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

Commit 8c63ca65 authored by Shashwat Razdan's avatar Shashwat Razdan
Browse files

Addressing the feedback received in the API review.

API Review bugs list is here: https://b.corp.google.com/issues?q=blockingid:176851064

Test: CTS tests:

Fixes:185226923
Fixes:185226755
Fixes:185226674
Fixes:185226597
Fixes:185226790
Fixes:184585058
Fixes:184585080
Fixes:184585117
Fixes:184585343
Fixes:184585079

Change-Id: Idacee5f95ce104d1fb6de40a04ac2b74691f977e
parent ad6ad264
Loading
Loading
Loading
Loading
+23 −24
Original line number Diff line number Diff line
@@ -1615,7 +1615,7 @@ package android.app.smartspace {
    ctor public SmartspaceConfig.Builder(@NonNull android.content.Context, @NonNull String);
    method @NonNull public android.app.smartspace.SmartspaceConfig build();
    method @NonNull public android.app.smartspace.SmartspaceConfig.Builder setExtras(@NonNull android.os.Bundle);
    method @NonNull public android.app.smartspace.SmartspaceConfig.Builder setSmartspaceTargetCount(int);
    method @NonNull public android.app.smartspace.SmartspaceConfig.Builder setSmartspaceTargetCount(@IntRange(from=0, to=50) int);
  }
  public final class SmartspaceManager {
@@ -1623,23 +1623,22 @@ package android.app.smartspace {
  }
  public final class SmartspaceSession implements java.lang.AutoCloseable {
    method public void addOnTargetsAvailableListener(@NonNull java.util.concurrent.Executor, @NonNull android.app.smartspace.SmartspaceSession.OnTargetsAvailableListener);
    method public void close();
    method public void destroy();
    method protected void finalize();
    method public void notifySmartspaceEvent(@NonNull android.app.smartspace.SmartspaceTargetEvent);
    method public void registerSmartspaceUpdates(@NonNull java.util.concurrent.Executor, @NonNull android.app.smartspace.SmartspaceSession.Callback);
    method public void removeOnTargetsAvailableListener(@NonNull android.app.smartspace.SmartspaceSession.OnTargetsAvailableListener);
    method public void requestSmartspaceUpdate();
    method public void unregisterSmartspaceUpdates(@NonNull android.app.smartspace.SmartspaceSession.Callback);
  }
  public static interface SmartspaceSession.Callback {
  public static interface SmartspaceSession.OnTargetsAvailableListener {
    method public void onTargetsAvailable(@NonNull java.util.List<android.app.smartspace.SmartspaceTarget>);
  }
  public final class SmartspaceSessionId implements android.os.Parcelable {
    method public int describeContents();
    method @Nullable public String getId();
    method @NonNull public int getUserId();
    method @NonNull public android.os.UserHandle getUserHandle();
    method public void writeToParcel(@NonNull android.os.Parcel, int);
    field @NonNull public static final android.os.Parcelable.Creator<android.app.smartspace.SmartspaceSessionId> CREATOR;
  }
@@ -1650,19 +1649,19 @@ package android.app.smartspace {
    method @Nullable public String getAssociatedSmartspaceTargetId();
    method @Nullable public android.app.smartspace.SmartspaceAction getBaseAction();
    method @NonNull public android.content.ComponentName getComponentName();
    method @NonNull public long getCreationTimeMillis();
    method @NonNull public long getExpiryTimeMillis();
    method @NonNull public int getFeatureType();
    method public long getCreationTimeMillis();
    method public long getExpiryTimeMillis();
    method public int getFeatureType();
    method @Nullable public android.app.smartspace.SmartspaceAction getHeaderAction();
    method @NonNull public java.util.List<android.app.smartspace.SmartspaceAction> getIconGrid();
    method @NonNull public float getScore();
    method public float getScore();
    method @Nullable public android.net.Uri getSliceUri();
    method @NonNull public String getSmartspaceTargetId();
    method @Nullable public String getSourceNotificationKey();
    method @NonNull public android.os.UserHandle getUserHandle();
    method @Nullable public android.appwidget.AppWidgetProviderInfo getWidgetId();
    method @NonNull public boolean isSensitive();
    method @NonNull public boolean shouldShowExpanded();
    method @Nullable public android.appwidget.AppWidgetProviderInfo getWidget();
    method public boolean isSensitive();
    method public boolean shouldShowExpanded();
    method public void writeToParcel(@NonNull android.os.Parcel, int);
    field @NonNull public static final android.os.Parcelable.Creator<android.app.smartspace.SmartspaceTarget> CREATOR;
    field public static final int FEATURE_ALARM = 7; // 0x7
@@ -1697,17 +1696,17 @@ package android.app.smartspace {
    method @NonNull public android.app.smartspace.SmartspaceTarget.Builder setActionChips(@NonNull java.util.List<android.app.smartspace.SmartspaceAction>);
    method @NonNull public android.app.smartspace.SmartspaceTarget.Builder setAssociatedSmartspaceTargetId(@NonNull String);
    method @NonNull public android.app.smartspace.SmartspaceTarget.Builder setBaseAction(@NonNull android.app.smartspace.SmartspaceAction);
    method @NonNull public android.app.smartspace.SmartspaceTarget.Builder setCreationTimeMillis(@NonNull long);
    method @NonNull public android.app.smartspace.SmartspaceTarget.Builder setExpiryTimeMillis(@NonNull long);
    method @NonNull public android.app.smartspace.SmartspaceTarget.Builder setFeatureType(@NonNull int);
    method @NonNull public android.app.smartspace.SmartspaceTarget.Builder setCreationTimeMillis(long);
    method @NonNull public android.app.smartspace.SmartspaceTarget.Builder setExpiryTimeMillis(long);
    method @NonNull public android.app.smartspace.SmartspaceTarget.Builder setFeatureType(int);
    method @NonNull public android.app.smartspace.SmartspaceTarget.Builder setHeaderAction(@NonNull android.app.smartspace.SmartspaceAction);
    method @NonNull public android.app.smartspace.SmartspaceTarget.Builder setIconGrid(@NonNull java.util.List<android.app.smartspace.SmartspaceAction>);
    method @NonNull public android.app.smartspace.SmartspaceTarget.Builder setScore(@NonNull float);
    method @NonNull public android.app.smartspace.SmartspaceTarget.Builder setSensitive(@NonNull boolean);
    method @NonNull public android.app.smartspace.SmartspaceTarget.Builder setShouldShowExpanded(@NonNull boolean);
    method @NonNull public android.app.smartspace.SmartspaceTarget.Builder setScore(float);
    method @NonNull public android.app.smartspace.SmartspaceTarget.Builder setSensitive(boolean);
    method @NonNull public android.app.smartspace.SmartspaceTarget.Builder setShouldShowExpanded(boolean);
    method @NonNull public android.app.smartspace.SmartspaceTarget.Builder setSliceUri(@NonNull android.net.Uri);
    method @NonNull public android.app.smartspace.SmartspaceTarget.Builder setSourceNotificationKey(@NonNull String);
    method @NonNull public android.app.smartspace.SmartspaceTarget.Builder setWidgetId(@NonNull android.appwidget.AppWidgetProviderInfo);
    method @NonNull public android.app.smartspace.SmartspaceTarget.Builder setWidget(@NonNull android.appwidget.AppWidgetProviderInfo);
  }
  public final class SmartspaceTargetEvent implements android.os.Parcelable {
@@ -1719,11 +1718,11 @@ package android.app.smartspace {
    field @NonNull public static final android.os.Parcelable.Creator<android.app.smartspace.SmartspaceTargetEvent> CREATOR;
    field public static final int EVENT_TARGET_BLOCK = 5; // 0x5
    field public static final int EVENT_TARGET_DISMISS = 4; // 0x4
    field public static final int EVENT_TARGET_HIDDEN = 3; // 0x3
    field public static final int EVENT_TARGET_INTERACTION = 1; // 0x1
    field public static final int EVENT_TARGET_IN_VIEW = 2; // 0x2
    field public static final int EVENT_TARGET_OUT_OF_VIEW = 3; // 0x3
    field public static final int EVENT_UI_SURFACE_IN_VIEW = 6; // 0x6
    field public static final int EVENT_UI_SURFACE_OUT_OF_VIEW = 7; // 0x7
    field public static final int EVENT_TARGET_SHOWN = 2; // 0x2
    field public static final int EVENT_UI_SURFACE_HIDDEN = 7; // 0x7
    field public static final int EVENT_UI_SURFACE_SHOWN = 6; // 0x6
  }
  public static final class SmartspaceTargetEvent.Builder {
+11 −6
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@
 */
package android.app.smartspace;

import android.annotation.IntRange;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SuppressLint;
@@ -41,6 +42,7 @@ public final class SmartspaceConfig implements Parcelable {
     * The least number of smartspace targets expected to be predicted by the backend. The backend
     * will always try to satisfy this threshold but it is not guaranteed to always meet it.
     */
    @IntRange(from = 0, to = 50)
    private final int mSmartspaceTargetCount;

    /**
@@ -54,11 +56,13 @@ public final class SmartspaceConfig implements Parcelable {
    @NonNull
    private String mPackageName;

    /** Send other client UI configurations in extras.
    /**
     * Send other client UI configurations in extras.
     *
     * This can include:
     *
     *  - Desired maximum update frequency
     * - Desired maximum update frequency (For example 1 minute update frequency for AoD, 1 second
     * update frequency for home screen etc).
     * - Request to get periodic updates
     * - Request to support multiple clients for the same UISurface.
     */
@@ -179,7 +183,8 @@ public final class SmartspaceConfig implements Parcelable {
         * Used to set the expected number of cards for this context.
         */
        @NonNull
        public Builder setSmartspaceTargetCount(int smartspaceTargetCount) {
        public Builder setSmartspaceTargetCount(
                @IntRange(from = 0, to = 50) int smartspaceTargetCount) {
            this.mSmartspaceTargetCount = smartspaceTargetCount;
            return this;
        }
+24 −22
Original line number Diff line number Diff line
@@ -63,7 +63,7 @@ import java.util.function.Consumer;
 *
 *    void onDestroy() {
 *        mSmartspaceSession.unregisterPredictionUpdates()
 *        mSmartspaceSession.destroy();
 *        mSmartspaceSession.close();
 *    }
 *
 * }</pre>
@@ -81,7 +81,8 @@ public final class SmartspaceSession implements AutoCloseable {
    private final AtomicBoolean mIsClosed = new AtomicBoolean(false);

    private final SmartspaceSessionId mSessionId;
    private final ArrayMap<Callback, CallbackWrapper> mRegisteredCallbacks = new ArrayMap<>();
    private final ArrayMap<OnTargetsAvailableListener, CallbackWrapper> mRegisteredCallbacks =
            new ArrayMap<>();
    private final IBinder mToken = new Binder();

    /**
@@ -98,11 +99,11 @@ public final class SmartspaceSession implements AutoCloseable {
        IBinder b = ServiceManager.getService(Context.SMARTSPACE_SERVICE);
        mInterface = android.app.smartspace.ISmartspaceManager.Stub.asInterface(b);
        mSessionId = new SmartspaceSessionId(
                context.getPackageName() + ":" + UUID.randomUUID().toString(), context.getUserId());
                context.getPackageName() + ":" + UUID.randomUUID().toString(), context.getUser());
        try {
            mInterface.createSmartspaceSession(smartspaceConfig, mSessionId, mToken);
        } catch (RemoteException e) {
            Log.e(TAG, "Failed to cerate Smartspace session", e);
            Log.e(TAG, "Failed to create Smartspace session", e);
            e.rethrowFromSystemServer();
        }

@@ -145,24 +146,24 @@ public final class SmartspaceSession implements AutoCloseable {
     * Requests the smartspace service provide continuous updates of smartspace cards via the
     * provided callback, until the given callback is unregistered.
     *
     * @param callbackExecutor The callback executor to use when calling the callback.
     * @param callback         The Callback to be called when updates of Smartspace targets are
     * @param listenerExecutor The listener executor to use when firing the listener.
     * @param listener         The listener to be called when updates of Smartspace targets are
     *                         available.
     */
    public void registerSmartspaceUpdates(@NonNull @CallbackExecutor Executor callbackExecutor,
            @NonNull Callback callback) {
    public void addOnTargetsAvailableListener(@NonNull @CallbackExecutor Executor listenerExecutor,
            @NonNull OnTargetsAvailableListener listener) {
        if (mIsClosed.get()) {
            throw new IllegalStateException("This client has already been destroyed.");
        }

        if (mRegisteredCallbacks.containsKey(callback)) {
        if (mRegisteredCallbacks.containsKey(listener)) {
            // Skip if this callback is already registered
            return;
        }
        try {
            final CallbackWrapper callbackWrapper = new CallbackWrapper(callbackExecutor,
                    callback::onTargetsAvailable);
            mRegisteredCallbacks.put(callback, callbackWrapper);
            final CallbackWrapper callbackWrapper = new CallbackWrapper(listenerExecutor,
                    listener::onTargetsAvailable);
            mRegisteredCallbacks.put(listener, callbackWrapper);
            mInterface.registerSmartspaceUpdates(mSessionId, callbackWrapper);
            mInterface.requestSmartspaceUpdate(mSessionId);
        } catch (RemoteException e) {
@@ -175,21 +176,21 @@ public final class SmartspaceSession implements AutoCloseable {
     * Requests the smartspace service to stop providing continuous updates to the provided
     * callback until the callback is re-registered.
     *
     * @see {@link SmartspaceSession#registerSmartspaceUpdates(Executor, Callback)}.
     *
     * @param callback The callback to be unregistered.
     * @param listener The callback to be unregistered.
     * @see {@link SmartspaceSession#addOnTargetsAvailableListener(Executor,
     * OnTargetsAvailableListener)}.
     */
    public void unregisterSmartspaceUpdates(@NonNull Callback callback) {
    public void removeOnTargetsAvailableListener(@NonNull OnTargetsAvailableListener listener) {
        if (mIsClosed.get()) {
            throw new IllegalStateException("This client has already been destroyed.");
        }

        if (!mRegisteredCallbacks.containsKey(callback)) {
        if (!mRegisteredCallbacks.containsKey(listener)) {
            // Skip if this callback was never registered
            return;
        }
        try {
            final CallbackWrapper callbackWrapper = mRegisteredCallbacks.remove(callback);
            final CallbackWrapper callbackWrapper = mRegisteredCallbacks.remove(listener);
            mInterface.unregisterSmartspaceUpdates(mSessionId, callbackWrapper);
        } catch (RemoteException e) {
            Log.e(TAG, "Failed to unregister for smartspace updates", e);
@@ -201,7 +202,7 @@ public final class SmartspaceSession implements AutoCloseable {
     * Destroys the client and unregisters the callback. Any method on this class after this call
     * will throw {@link IllegalStateException}.
     */
    public void destroy() {
    private void destroy() {
        if (!mIsClosed.getAndSet(true)) {
            mCloseGuard.close();

@@ -238,6 +239,7 @@ public final class SmartspaceSession implements AutoCloseable {
    @Override
    public void close() {
        try {
            destroy();
            finalize();
        } catch (Throwable throwable) {
            throwable.printStackTrace();
@@ -245,14 +247,14 @@ public final class SmartspaceSession implements AutoCloseable {
    }

    /**
     * Callback for receiving smartspace updates.
     * Listener to receive smartspace targets from the service.
     */
    public interface Callback {
    public interface OnTargetsAvailableListener {

        /**
         * Called when a new set of smartspace targets are available.
         *
         * @param targets Sorted list of smartspace targets.
         * @param targets Ranked list of smartspace targets.
         */
        void onTargetsAvailable(@NonNull List<SmartspaceTarget> targets);
    }
+11 −10
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import android.annotation.Nullable;
import android.annotation.SystemApi;
import android.os.Parcel;
import android.os.Parcelable;
import android.os.UserHandle;

import java.util.Objects;

@@ -36,21 +37,21 @@ public final class SmartspaceSessionId implements Parcelable {
    private final String mId;

    @NonNull
    private final int mUserId;
    private final UserHandle mUserHandle;

    /**
     * Creates a new id for a Smartspace session.
     *
     * @hide
     */
    public SmartspaceSessionId(@NonNull final String id, @NonNull final int userId) {
    public SmartspaceSessionId(@NonNull final String id, @NonNull final UserHandle userHandle) {
        mId = id;
        mUserId = userId;
        mUserHandle = userHandle;
    }

    private SmartspaceSessionId(Parcel p) {
        mId = p.readString();
        mUserId = p.readInt();
        mUserHandle = p.readTypedObject(UserHandle.CREATOR);
    }

    /**
@@ -65,8 +66,8 @@ public final class SmartspaceSessionId implements Parcelable {
     * Returns the userId associated with this sessionId.
     */
    @NonNull
    public int getUserId() {
        return mUserId;
    public UserHandle getUserHandle() {
        return mUserHandle;
    }

    @Override
@@ -74,20 +75,20 @@ public final class SmartspaceSessionId implements Parcelable {
        if (!getClass().equals(o != null ? o.getClass() : null)) return false;

        SmartspaceSessionId other = (SmartspaceSessionId) o;
        return mId.equals(other.mId) && mUserId == other.mUserId;
        return mId.equals(other.mId) && mUserHandle == other.mUserHandle;
    }

    @Override
    public String toString() {
        return "SmartspaceSessionId{"
                + "mId='" + mId + '\''
                + ", mUserId=" + mUserId
                + ", mUserId=" + mUserHandle.getIdentifier()
                + '}';
    }

    @Override
    public int hashCode() {
        return Objects.hash(mId, mUserId);
        return Objects.hash(mId, mUserHandle);
    }

    @Override
@@ -98,7 +99,7 @@ public final class SmartspaceSessionId implements Parcelable {
    @Override
    public void writeToParcel(@NonNull Parcel dest, int flags) {
        dest.writeString(mId);
        dest.writeInt(mUserId);
        dest.writeTypedObject(this.mUserHandle, flags);
    }

    public static final @NonNull Creator<SmartspaceSessionId> CREATOR =
+37 −36

File changed.

Preview size limit exceeded, changes collapsed.

Loading