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

Commit d65add42 authored by Liam, Lee Pong Lam's avatar Liam, Lee Pong Lam
Browse files

Add flaggedapi for smartspace remote views

Bug: 300157758
Test: Manual
Change-Id: I944aa53f7b4b8511bae06913451561a3f204b000
parent 874b217b
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -2451,6 +2451,7 @@ package android.app.smartspace {
    method public int getFeatureType();
    method @Nullable public android.app.smartspace.SmartspaceAction getHeaderAction();
    method @NonNull public java.util.List<android.app.smartspace.SmartspaceAction> getIconGrid();
    method @FlaggedApi("android.app.smartspace.flags.remote_views") @Nullable public android.widget.RemoteViews getRemoteViews();
    method public float getScore();
    method @Nullable public android.net.Uri getSliceUri();
    method @NonNull public String getSmartspaceTargetId();
@@ -2525,6 +2526,7 @@ package android.app.smartspace {
    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 @FlaggedApi("android.app.smartspace.flags.remote_views") @NonNull public android.app.smartspace.SmartspaceTarget.Builder setRemoteViews(@NonNull android.widget.RemoteViews);
    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);
+53 −5
Original line number Diff line number Diff line
@@ -16,10 +16,12 @@
package android.app.smartspace;

import android.annotation.CurrentTimeMillisLong;
import android.annotation.FlaggedApi;
import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SystemApi;
import android.app.smartspace.flags.Flags;
import android.app.smartspace.uitemplatedata.BaseTemplateData;
import android.appwidget.AppWidgetProviderInfo;
import android.content.ComponentName;
@@ -27,6 +29,7 @@ import android.net.Uri;
import android.os.Parcel;
import android.os.Parcelable;
import android.os.UserHandle;
import android.widget.RemoteViews;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@@ -41,7 +44,8 @@ import java.util.Objects;
 * {@link SmartspaceAction} as their type because they can have associated actions.
 *
 * <p><b>NOTE: </b>
 * If {@link mWidget} is set, it should be preferred over all other properties.
 * If either {@link mRemoteViews} or {@link mWidget} is set, it should be preferred over all
 * other properties. (An exception is thrown if both are set.)
 * Else, if {@link mSliceUri} is set, it should be preferred over all other data properties.
 * Otherwise, the instance should be treated as a data object.
 *
@@ -132,6 +136,9 @@ public final class SmartspaceTarget implements Parcelable {
    @Nullable
    private final AppWidgetProviderInfo mWidget;

    @Nullable
    private final RemoteViews mRemoteViews;

    @Nullable
    private final BaseTemplateData mTemplateData;

@@ -288,6 +295,7 @@ public final class SmartspaceTarget implements Parcelable {
        this.mSliceUri = in.readTypedObject(Uri.CREATOR);
        this.mWidget = in.readTypedObject(AppWidgetProviderInfo.CREATOR);
        this.mTemplateData = in.readParcelable(/* loader= */null, BaseTemplateData.class);
        this.mRemoteViews = in.readTypedObject(RemoteViews.CREATOR);
    }

    private SmartspaceTarget(String smartspaceTargetId,
@@ -298,7 +306,7 @@ public final class SmartspaceTarget implements Parcelable {
            boolean shouldShowExpanded, String sourceNotificationKey,
            ComponentName componentName, UserHandle userHandle,
            String associatedSmartspaceTargetId, Uri sliceUri,
            AppWidgetProviderInfo widget, BaseTemplateData templateData) {
            AppWidgetProviderInfo widget, BaseTemplateData templateData, RemoteViews remoteViews) {
        mSmartspaceTargetId = smartspaceTargetId;
        mHeaderAction = headerAction;
        mBaseAction = baseAction;
@@ -317,6 +325,7 @@ public final class SmartspaceTarget implements Parcelable {
        mSliceUri = sliceUri;
        mWidget = widget;
        mTemplateData = templateData;
        mRemoteViews = remoteViews;
    }

    /**
@@ -460,6 +469,15 @@ public final class SmartspaceTarget implements Parcelable {
        return mTemplateData;
    }

    /**
     * Returns the {@link RemoteViews} to show over the target.
     */
    @FlaggedApi(Flags.FLAG_REMOTE_VIEWS)
    @Nullable
    public RemoteViews getRemoteViews() {
        return mRemoteViews;
    }

    /**
     * @see Parcelable.Creator
     */
@@ -496,6 +514,7 @@ public final class SmartspaceTarget implements Parcelable {
        dest.writeTypedObject(this.mSliceUri, flags);
        dest.writeTypedObject(this.mWidget, flags);
        dest.writeParcelable(this.mTemplateData, flags);
        dest.writeTypedObject(this.mRemoteViews, flags);
    }

    @Override
@@ -524,6 +543,7 @@ public final class SmartspaceTarget implements Parcelable {
                + ", mSliceUri=" + mSliceUri
                + ", mWidget=" + mWidget
                + ", mTemplateData=" + mTemplateData
                + ", mRemoteViews=" + mRemoteViews
                + '}';
    }

@@ -550,7 +570,8 @@ public final class SmartspaceTarget implements Parcelable {
                that.mAssociatedSmartspaceTargetId)
                && Objects.equals(mSliceUri, that.mSliceUri)
                && Objects.equals(mWidget, that.mWidget)
                && Objects.equals(mTemplateData, that.mTemplateData);
                && Objects.equals(mTemplateData, that.mTemplateData)
                && Objects.equals(mRemoteViews, that.mRemoteViews);
    }

    @Override
@@ -558,7 +579,7 @@ public final class SmartspaceTarget implements Parcelable {
        return Objects.hash(mSmartspaceTargetId, mHeaderAction, mBaseAction, mCreationTimeMillis,
                mExpiryTimeMillis, mScore, mActionChips, mIconGrid, mFeatureType, mSensitive,
                mShouldShowExpanded, mSourceNotificationKey, mComponentName, mUserHandle,
                mAssociatedSmartspaceTargetId, mSliceUri, mWidget, mTemplateData);
                mAssociatedSmartspaceTargetId, mSliceUri, mWidget, mTemplateData, mRemoteViews);
    }

    /**
@@ -588,6 +609,8 @@ public final class SmartspaceTarget implements Parcelable {
        private AppWidgetProviderInfo mWidget;
        private BaseTemplateData mTemplateData;

        private RemoteViews mRemoteViews;

        /**
         * A builder for {@link SmartspaceTarget}.
         *
@@ -727,9 +750,15 @@ public final class SmartspaceTarget implements Parcelable {
         *
         * <p><b>NOTE: </b> If {@link mWidget} is set, all other @Nullable params should be
         * ignored.
         *
         * @throws An {@link IllegalStateException} is thrown if {@link mRemoteViews} is set.
         */
        @NonNull
        public Builder setWidget(@NonNull AppWidgetProviderInfo widget) {
            if (mRemoteViews != null) {
                throw new IllegalStateException(
                        "Widget providers and RemoteViews cannot be used at the same time.");
            }
            this.mWidget = widget;
            return this;
        }
@@ -744,6 +773,25 @@ public final class SmartspaceTarget implements Parcelable {
            return this;
        }

        /**
         * Sets the {@link RemoteViews}.
         *
         * <p><b>NOTE: </b> If {@link RemoteViews} is set, all other @Nullable params should be
         * ignored.
         *
         * @throws An {@link IllegalStateException} is thrown if {@link mWidget} is set.
         */
        @FlaggedApi(Flags.FLAG_REMOTE_VIEWS)
        @NonNull
        public Builder setRemoteViews(@NonNull RemoteViews remoteViews) {
            if (mWidget != null) {
                throw new IllegalStateException(
                        "Widget providers and RemoteViews cannot be used at the same time.");
            }
            mRemoteViews = remoteViews;
            return this;
        }

        /**
         * Builds a new {@link SmartspaceTarget}.
         *
@@ -760,7 +808,7 @@ public final class SmartspaceTarget implements Parcelable {
                    mHeaderAction, mBaseAction, mCreationTimeMillis, mExpiryTimeMillis, mScore,
                    mActionChips, mIconGrid, mFeatureType, mSensitive, mShouldShowExpanded,
                    mSourceNotificationKey, mComponentName, mUserHandle,
                    mAssociatedSmartspaceTargetId, mSliceUri, mWidget, mTemplateData);
                    mAssociatedSmartspaceTargetId, mSliceUri, mWidget, mTemplateData, mRemoteViews);
        }
    }
}