diff --git a/core/api/system-current.txt b/core/api/system-current.txt index 1a7810adc5b47628d53fd1c80bc241664754cb6e..250d329c87610877243778417253da7389c13034 100644 --- a/core/api/system-current.txt +++ b/core/api/system-current.txt @@ -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); diff --git a/core/java/android/app/smartspace/SmartspaceTarget.java b/core/java/android/app/smartspace/SmartspaceTarget.java index 3c66a15399d3e81000d656641ba8e2d498efd63e..f6f65c73dfb9fcea3ee0f3686298d998820bfd96 100644 --- a/core/java/android/app/smartspace/SmartspaceTarget.java +++ b/core/java/android/app/smartspace/SmartspaceTarget.java @@ -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); } } }