1 /* 2 * Copyright (C) 2021 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package android.app.smartspace; 17 18 import android.annotation.CurrentTimeMillisLong; 19 import android.annotation.IntDef; 20 import android.annotation.NonNull; 21 import android.annotation.Nullable; 22 import android.annotation.SystemApi; 23 import android.app.smartspace.uitemplatedata.BaseTemplateData; 24 import android.appwidget.AppWidgetProviderInfo; 25 import android.content.ComponentName; 26 import android.net.Uri; 27 import android.os.Parcel; 28 import android.os.Parcelable; 29 import android.os.UserHandle; 30 31 import java.lang.annotation.Retention; 32 import java.lang.annotation.RetentionPolicy; 33 import java.util.ArrayList; 34 import java.util.List; 35 import java.util.Objects; 36 37 /** 38 * A {@link SmartspaceTarget} is a data class which holds all properties necessary to inflate a 39 * smartspace card. It contains data and related metadata which is supposed to be utilized by 40 * smartspace clients based on their own UI/UX requirements. Some of the properties have 41 * {@link SmartspaceAction} as their type because they can have associated actions. 42 * 43 * <p><b>NOTE: </b> 44 * If {@link mWidget} is set, it should be preferred over all other properties. 45 * Else, if {@link mSliceUri} is set, it should be preferred over all other data properties. 46 * Otherwise, the instance should be treated as a data object. 47 * 48 * @hide 49 */ 50 @SystemApi 51 public final class SmartspaceTarget implements Parcelable { 52 53 /** A unique Id for an instance of {@link SmartspaceTarget}. */ 54 @NonNull 55 private final String mSmartspaceTargetId; 56 57 /** A {@link SmartspaceAction} for the header in the Smartspace card. */ 58 @Nullable 59 private final SmartspaceAction mHeaderAction; 60 61 /** A {@link SmartspaceAction} for the base action in the Smartspace card. */ 62 @Nullable 63 private final SmartspaceAction mBaseAction; 64 65 /** A timestamp indicating when the card was created. */ 66 @CurrentTimeMillisLong 67 private final long mCreationTimeMillis; 68 69 /** 70 * A timestamp indicating when the card should be removed from view, in case the service 71 * disconnects or restarts. 72 */ 73 @CurrentTimeMillisLong 74 private final long mExpiryTimeMillis; 75 76 /** A score assigned to a target. */ 77 private final float mScore; 78 79 /** A {@link List<SmartspaceAction>} containing all action chips. */ 80 @NonNull 81 private final List<SmartspaceAction> mActionChips; 82 83 /** A {@link List<SmartspaceAction>} containing all icons for the grid. */ 84 @NonNull 85 private final List<SmartspaceAction> mIconGrid; 86 87 /** 88 * {@link FeatureType} indicating the feature type of this card. 89 * 90 * @see FeatureType 91 */ 92 @FeatureType 93 private final int mFeatureType; 94 95 /** 96 * Indicates whether the content is sensitive. Certain UI surfaces may choose to skip rendering 97 * real content until the device is unlocked. 98 */ 99 private final boolean mSensitive; 100 101 /** Indicating if the UI should show this target in its expanded state. */ 102 private final boolean mShouldShowExpanded; 103 104 /** A Notification key if the target was generated using a notification. */ 105 @Nullable 106 private final String mSourceNotificationKey; 107 108 /** {@link ComponentName} for this target. */ 109 @NonNull 110 private final ComponentName mComponentName; 111 112 /** {@link UserHandle} for this target. */ 113 @NonNull 114 private final UserHandle mUserHandle; 115 116 /** 117 * Target Id of other {@link SmartspaceTarget}s if it is associated with this target. This 118 * association is added to tell the UI that a card would be more useful if displayed with the 119 * associated smartspace target. This field is supposed to be taken as a suggestion and the 120 * association can be ignored based on the situation in the UI. It is possible to have a one way 121 * card association. In other words, Card B can be associated with Card A but not the other way 122 * around. 123 */ 124 @Nullable 125 private final String mAssociatedSmartspaceTargetId; 126 127 /** {@link Uri} Slice Uri if this target is a slice. */ 128 @Nullable 129 private final Uri mSliceUri; 130 131 /** {@link AppWidgetProviderInfo} if this target is a widget. */ 132 @Nullable 133 private final AppWidgetProviderInfo mWidget; 134 135 @Nullable 136 private final BaseTemplateData mTemplateData; 137 138 public static final int FEATURE_UNDEFINED = 0; 139 public static final int FEATURE_WEATHER = 1; 140 public static final int FEATURE_CALENDAR = 2; 141 public static final int FEATURE_COMMUTE_TIME = 3; 142 public static final int FEATURE_FLIGHT = 4; 143 public static final int FEATURE_TIPS = 5; 144 public static final int FEATURE_REMINDER = 6; 145 public static final int FEATURE_ALARM = 7; 146 public static final int FEATURE_ONBOARDING = 8; 147 public static final int FEATURE_SPORTS = 9; 148 public static final int FEATURE_WEATHER_ALERT = 10; 149 public static final int FEATURE_CONSENT = 11; 150 public static final int FEATURE_STOCK_PRICE_CHANGE = 12; 151 public static final int FEATURE_SHOPPING_LIST = 13; 152 public static final int FEATURE_LOYALTY_CARD = 14; 153 public static final int FEATURE_MEDIA = 15; 154 public static final int FEATURE_BEDTIME_ROUTINE = 16; 155 public static final int FEATURE_FITNESS_TRACKING = 17; 156 public static final int FEATURE_ETA_MONITORING = 18; 157 public static final int FEATURE_MISSED_CALL = 19; 158 public static final int FEATURE_PACKAGE_TRACKING = 20; 159 public static final int FEATURE_TIMER = 21; 160 public static final int FEATURE_STOPWATCH = 22; 161 public static final int FEATURE_UPCOMING_ALARM = 23; 162 public static final int FEATURE_GAS_STATION_PAYMENT = 24; 163 public static final int FEATURE_PAIRED_DEVICE_STATE = 25; 164 public static final int FEATURE_DRIVING_MODE = 26; 165 public static final int FEATURE_SLEEP_SUMMARY = 27; 166 public static final int FEATURE_FLASHLIGHT = 28; 167 public static final int FEATURE_TIME_TO_LEAVE = 29; 168 public static final int FEATURE_DOORBELL = 30; 169 public static final int FEATURE_MEDIA_RESUME = 31; 170 public static final int FEATURE_CROSS_DEVICE_TIMER = 32; 171 public static final int FEATURE_SEVERE_WEATHER_ALERT = 33; 172 public static final int FEATURE_HOLIDAY_ALARM = 34; 173 public static final int FEATURE_SAFETY_CHECK = 35; 174 public static final int FEATURE_MEDIA_HEADS_UP = 36; 175 public static final int FEATURE_STEP_COUNTING = 37; 176 public static final int FEATURE_EARTHQUAKE_ALERT = 38; 177 public static final int FEATURE_STEP_DATE = 39; // This represents a DATE. "STEP" is a typo. 178 public static final int FEATURE_BLAZE_BUILD_PROGRESS = 40; 179 public static final int FEATURE_EARTHQUAKE_OCCURRED = 41; 180 181 /** 182 * @hide 183 */ 184 @IntDef(prefix = {"FEATURE_"}, value = { 185 FEATURE_UNDEFINED, 186 FEATURE_WEATHER, 187 FEATURE_CALENDAR, 188 FEATURE_COMMUTE_TIME, 189 FEATURE_FLIGHT, 190 FEATURE_TIPS, 191 FEATURE_REMINDER, 192 FEATURE_ALARM, 193 FEATURE_ONBOARDING, 194 FEATURE_SPORTS, 195 FEATURE_WEATHER_ALERT, 196 FEATURE_CONSENT, 197 FEATURE_STOCK_PRICE_CHANGE, 198 FEATURE_SHOPPING_LIST, 199 FEATURE_LOYALTY_CARD, 200 FEATURE_MEDIA, 201 FEATURE_BEDTIME_ROUTINE, 202 FEATURE_FITNESS_TRACKING, 203 FEATURE_ETA_MONITORING, 204 FEATURE_MISSED_CALL, 205 FEATURE_PACKAGE_TRACKING, 206 FEATURE_TIMER, 207 FEATURE_STOPWATCH, 208 FEATURE_UPCOMING_ALARM, 209 FEATURE_GAS_STATION_PAYMENT, 210 FEATURE_PAIRED_DEVICE_STATE, 211 FEATURE_DRIVING_MODE, 212 FEATURE_SLEEP_SUMMARY, 213 FEATURE_FLASHLIGHT, 214 FEATURE_TIME_TO_LEAVE, 215 FEATURE_DOORBELL, 216 FEATURE_MEDIA_RESUME, 217 FEATURE_CROSS_DEVICE_TIMER, 218 FEATURE_SEVERE_WEATHER_ALERT, 219 FEATURE_HOLIDAY_ALARM, 220 FEATURE_SAFETY_CHECK, 221 FEATURE_MEDIA_HEADS_UP, 222 FEATURE_STEP_COUNTING, 223 FEATURE_EARTHQUAKE_ALERT, 224 FEATURE_STEP_DATE, 225 FEATURE_BLAZE_BUILD_PROGRESS, 226 FEATURE_EARTHQUAKE_OCCURRED 227 }) 228 @Retention(RetentionPolicy.SOURCE) 229 public @interface FeatureType { 230 } 231 232 public static final int UI_TEMPLATE_UNDEFINED = 0; 233 // Default template whose data is represented by {@link BaseTemplateData}. The default 234 // template is also a base card for the other types of templates. 235 public static final int UI_TEMPLATE_DEFAULT = 1; 236 // Sub-image template whose data is represented by {@link SubImageTemplateData} 237 public static final int UI_TEMPLATE_SUB_IMAGE = 2; 238 // Sub-list template whose data is represented by {@link SubListTemplateData} 239 public static final int UI_TEMPLATE_SUB_LIST = 3; 240 // Carousel template whose data is represented by {@link CarouselTemplateData} 241 public static final int UI_TEMPLATE_CAROUSEL = 4; 242 // Head-to-head template whose data is represented by {@link HeadToHeadTemplateData} 243 public static final int UI_TEMPLATE_HEAD_TO_HEAD = 5; 244 // Combined-cards template whose data is represented by {@link CombinedCardsTemplateData} 245 public static final int UI_TEMPLATE_COMBINED_CARDS = 6; 246 // Sub-card template whose data is represented by {@link SubCardTemplateData} 247 public static final int UI_TEMPLATE_SUB_CARD = 7; 248 // Reserved: 8 249 // Template type used by non-UI template features for sending logging information in the 250 // base template data. This should not be used for UI template features. 251 // public static final int UI_TEMPLATE_LOGGING_ONLY = 8; 252 253 /** 254 * The types of the Smartspace ui templates. 255 * 256 * @hide 257 */ 258 @IntDef(prefix = {"UI_TEMPLATE_"}, value = { 259 UI_TEMPLATE_UNDEFINED, 260 UI_TEMPLATE_DEFAULT, 261 UI_TEMPLATE_SUB_IMAGE, 262 UI_TEMPLATE_SUB_LIST, 263 UI_TEMPLATE_CAROUSEL, 264 UI_TEMPLATE_HEAD_TO_HEAD, 265 UI_TEMPLATE_COMBINED_CARDS, 266 UI_TEMPLATE_SUB_CARD 267 }) 268 @Retention(RetentionPolicy.SOURCE) 269 public @interface UiTemplateType { 270 } 271 SmartspaceTarget(Parcel in)272 private SmartspaceTarget(Parcel in) { 273 this.mSmartspaceTargetId = in.readString(); 274 this.mHeaderAction = in.readTypedObject(SmartspaceAction.CREATOR); 275 this.mBaseAction = in.readTypedObject(SmartspaceAction.CREATOR); 276 this.mCreationTimeMillis = in.readLong(); 277 this.mExpiryTimeMillis = in.readLong(); 278 this.mScore = in.readFloat(); 279 this.mActionChips = in.createTypedArrayList(SmartspaceAction.CREATOR); 280 this.mIconGrid = in.createTypedArrayList(SmartspaceAction.CREATOR); 281 this.mFeatureType = in.readInt(); 282 this.mSensitive = in.readBoolean(); 283 this.mShouldShowExpanded = in.readBoolean(); 284 this.mSourceNotificationKey = in.readString(); 285 this.mComponentName = in.readTypedObject(ComponentName.CREATOR); 286 this.mUserHandle = in.readTypedObject(UserHandle.CREATOR); 287 this.mAssociatedSmartspaceTargetId = in.readString(); 288 this.mSliceUri = in.readTypedObject(Uri.CREATOR); 289 this.mWidget = in.readTypedObject(AppWidgetProviderInfo.CREATOR); 290 this.mTemplateData = in.readParcelable(/* loader= */null, BaseTemplateData.class); 291 } 292 SmartspaceTarget(String smartspaceTargetId, SmartspaceAction headerAction, SmartspaceAction baseAction, long creationTimeMillis, long expiryTimeMillis, float score, List<SmartspaceAction> actionChips, List<SmartspaceAction> iconGrid, int featureType, boolean sensitive, boolean shouldShowExpanded, String sourceNotificationKey, ComponentName componentName, UserHandle userHandle, String associatedSmartspaceTargetId, Uri sliceUri, AppWidgetProviderInfo widget, BaseTemplateData templateData)293 private SmartspaceTarget(String smartspaceTargetId, 294 SmartspaceAction headerAction, SmartspaceAction baseAction, long creationTimeMillis, 295 long expiryTimeMillis, float score, 296 List<SmartspaceAction> actionChips, 297 List<SmartspaceAction> iconGrid, int featureType, boolean sensitive, 298 boolean shouldShowExpanded, String sourceNotificationKey, 299 ComponentName componentName, UserHandle userHandle, 300 String associatedSmartspaceTargetId, Uri sliceUri, 301 AppWidgetProviderInfo widget, BaseTemplateData templateData) { 302 mSmartspaceTargetId = smartspaceTargetId; 303 mHeaderAction = headerAction; 304 mBaseAction = baseAction; 305 mCreationTimeMillis = creationTimeMillis; 306 mExpiryTimeMillis = expiryTimeMillis; 307 mScore = score; 308 mActionChips = actionChips; 309 mIconGrid = iconGrid; 310 mFeatureType = featureType; 311 mSensitive = sensitive; 312 mShouldShowExpanded = shouldShowExpanded; 313 mSourceNotificationKey = sourceNotificationKey; 314 mComponentName = componentName; 315 mUserHandle = userHandle; 316 mAssociatedSmartspaceTargetId = associatedSmartspaceTargetId; 317 mSliceUri = sliceUri; 318 mWidget = widget; 319 mTemplateData = templateData; 320 } 321 322 /** 323 * Returns the Id of the target. 324 */ 325 @NonNull getSmartspaceTargetId()326 public String getSmartspaceTargetId() { 327 return mSmartspaceTargetId; 328 } 329 330 /** 331 * Returns the header action of the target. 332 */ 333 @Nullable getHeaderAction()334 public SmartspaceAction getHeaderAction() { 335 return mHeaderAction; 336 } 337 338 /** 339 * Returns the base action of the target. 340 */ 341 @Nullable getBaseAction()342 public SmartspaceAction getBaseAction() { 343 return mBaseAction; 344 } 345 346 /** 347 * Returns the creation time of the target. 348 */ 349 @CurrentTimeMillisLong getCreationTimeMillis()350 public long getCreationTimeMillis() { 351 return mCreationTimeMillis; 352 } 353 354 /** 355 * Returns the expiry time of the target. 356 */ 357 @CurrentTimeMillisLong getExpiryTimeMillis()358 public long getExpiryTimeMillis() { 359 return mExpiryTimeMillis; 360 } 361 362 /** 363 * Returns the score of the target. 364 */ getScore()365 public float getScore() { 366 return mScore; 367 } 368 369 /** 370 * Return the action chips of the target. 371 */ 372 @NonNull getActionChips()373 public List<SmartspaceAction> getActionChips() { 374 return mActionChips; 375 } 376 377 /** 378 * Return the icons of the target. 379 */ 380 @NonNull getIconGrid()381 public List<SmartspaceAction> getIconGrid() { 382 return mIconGrid; 383 } 384 385 /** 386 * Returns the feature type of the target. 387 */ 388 @FeatureType getFeatureType()389 public int getFeatureType() { 390 return mFeatureType; 391 } 392 393 /** 394 * Returns whether the target is sensitive or not. 395 */ isSensitive()396 public boolean isSensitive() { 397 return mSensitive; 398 } 399 400 /** 401 * Returns whether the target should be shown in expanded state. 402 */ shouldShowExpanded()403 public boolean shouldShowExpanded() { 404 return mShouldShowExpanded; 405 } 406 407 /** 408 * Returns the source notification key of the target. 409 */ 410 @Nullable getSourceNotificationKey()411 public String getSourceNotificationKey() { 412 return mSourceNotificationKey; 413 } 414 415 /** 416 * Returns the component name of the target. 417 */ 418 @NonNull getComponentName()419 public ComponentName getComponentName() { 420 return mComponentName; 421 } 422 423 /** 424 * Returns the user handle of the target. 425 */ 426 @NonNull getUserHandle()427 public UserHandle getUserHandle() { 428 return mUserHandle; 429 } 430 431 /** 432 * Returns the id of a target associated with this instance. 433 */ 434 @Nullable getAssociatedSmartspaceTargetId()435 public String getAssociatedSmartspaceTargetId() { 436 return mAssociatedSmartspaceTargetId; 437 } 438 439 /** 440 * Returns the slice uri, if the target is a slice. 441 */ 442 @Nullable getSliceUri()443 public Uri getSliceUri() { 444 return mSliceUri; 445 } 446 447 /** 448 * Returns the AppWidgetProviderInfo, if the target is a widget. 449 */ 450 @Nullable getWidget()451 public AppWidgetProviderInfo getWidget() { 452 return mWidget; 453 } 454 455 /** 456 * Returns the UI template data. 457 */ 458 @Nullable getTemplateData()459 public BaseTemplateData getTemplateData() { 460 return mTemplateData; 461 } 462 463 /** 464 * @see Parcelable.Creator 465 */ 466 @NonNull 467 public static final Creator<SmartspaceTarget> CREATOR = new Creator<SmartspaceTarget>() { 468 @Override 469 public SmartspaceTarget createFromParcel(Parcel source) { 470 return new SmartspaceTarget(source); 471 } 472 473 @Override 474 public SmartspaceTarget[] newArray(int size) { 475 return new SmartspaceTarget[size]; 476 } 477 }; 478 479 @Override writeToParcel(@onNull Parcel dest, int flags)480 public void writeToParcel(@NonNull Parcel dest, int flags) { 481 dest.writeString(this.mSmartspaceTargetId); 482 dest.writeTypedObject(this.mHeaderAction, flags); 483 dest.writeTypedObject(this.mBaseAction, flags); 484 dest.writeLong(this.mCreationTimeMillis); 485 dest.writeLong(this.mExpiryTimeMillis); 486 dest.writeFloat(this.mScore); 487 dest.writeTypedList(this.mActionChips); 488 dest.writeTypedList(this.mIconGrid); 489 dest.writeInt(this.mFeatureType); 490 dest.writeBoolean(this.mSensitive); 491 dest.writeBoolean(this.mShouldShowExpanded); 492 dest.writeString(this.mSourceNotificationKey); 493 dest.writeTypedObject(this.mComponentName, flags); 494 dest.writeTypedObject(this.mUserHandle, flags); 495 dest.writeString(this.mAssociatedSmartspaceTargetId); 496 dest.writeTypedObject(this.mSliceUri, flags); 497 dest.writeTypedObject(this.mWidget, flags); 498 dest.writeParcelable(this.mTemplateData, flags); 499 } 500 501 @Override describeContents()502 public int describeContents() { 503 return 0; 504 } 505 506 @Override toString()507 public String toString() { 508 return "SmartspaceTarget{" 509 + "mSmartspaceTargetId='" + mSmartspaceTargetId + '\'' 510 + ", mHeaderAction=" + mHeaderAction 511 + ", mBaseAction=" + mBaseAction 512 + ", mCreationTimeMillis=" + mCreationTimeMillis 513 + ", mExpiryTimeMillis=" + mExpiryTimeMillis 514 + ", mScore=" + mScore 515 + ", mActionChips=" + mActionChips 516 + ", mIconGrid=" + mIconGrid 517 + ", mFeatureType=" + mFeatureType 518 + ", mSensitive=" + mSensitive 519 + ", mShouldShowExpanded=" + mShouldShowExpanded 520 + ", mSourceNotificationKey='" + mSourceNotificationKey + '\'' 521 + ", mComponentName=" + mComponentName 522 + ", mUserHandle=" + mUserHandle 523 + ", mAssociatedSmartspaceTargetId='" + mAssociatedSmartspaceTargetId + '\'' 524 + ", mSliceUri=" + mSliceUri 525 + ", mWidget=" + mWidget 526 + ", mTemplateData=" + mTemplateData 527 + '}'; 528 } 529 530 @Override equals(Object o)531 public boolean equals(Object o) { 532 if (this == o) return true; 533 if (o == null || getClass() != o.getClass()) return false; 534 SmartspaceTarget that = (SmartspaceTarget) o; 535 return mCreationTimeMillis == that.mCreationTimeMillis 536 && mExpiryTimeMillis == that.mExpiryTimeMillis 537 && Float.compare(that.mScore, mScore) == 0 538 && mFeatureType == that.mFeatureType 539 && mSensitive == that.mSensitive 540 && mShouldShowExpanded == that.mShouldShowExpanded 541 && mSmartspaceTargetId.equals(that.mSmartspaceTargetId) 542 && Objects.equals(mHeaderAction, that.mHeaderAction) 543 && Objects.equals(mBaseAction, that.mBaseAction) 544 && Objects.equals(mActionChips, that.mActionChips) 545 && Objects.equals(mIconGrid, that.mIconGrid) 546 && Objects.equals(mSourceNotificationKey, that.mSourceNotificationKey) 547 && mComponentName.equals(that.mComponentName) 548 && mUserHandle.equals(that.mUserHandle) 549 && Objects.equals(mAssociatedSmartspaceTargetId, 550 that.mAssociatedSmartspaceTargetId) 551 && Objects.equals(mSliceUri, that.mSliceUri) 552 && Objects.equals(mWidget, that.mWidget) 553 && Objects.equals(mTemplateData, that.mTemplateData); 554 } 555 556 @Override hashCode()557 public int hashCode() { 558 return Objects.hash(mSmartspaceTargetId, mHeaderAction, mBaseAction, mCreationTimeMillis, 559 mExpiryTimeMillis, mScore, mActionChips, mIconGrid, mFeatureType, mSensitive, 560 mShouldShowExpanded, mSourceNotificationKey, mComponentName, mUserHandle, 561 mAssociatedSmartspaceTargetId, mSliceUri, mWidget, mTemplateData); 562 } 563 564 /** 565 * A builder for {@link SmartspaceTarget} object. 566 * 567 * @hide 568 */ 569 @SystemApi 570 public static final class Builder { 571 private final String mSmartspaceTargetId; 572 private final ComponentName mComponentName; 573 private final UserHandle mUserHandle; 574 575 private SmartspaceAction mHeaderAction; 576 private SmartspaceAction mBaseAction; 577 private long mCreationTimeMillis; 578 private long mExpiryTimeMillis; 579 private float mScore; 580 private List<SmartspaceAction> mActionChips = new ArrayList<>(); 581 private List<SmartspaceAction> mIconGrid = new ArrayList<>(); 582 private int mFeatureType; 583 private boolean mSensitive; 584 private boolean mShouldShowExpanded; 585 private String mSourceNotificationKey; 586 private String mAssociatedSmartspaceTargetId; 587 private Uri mSliceUri; 588 private AppWidgetProviderInfo mWidget; 589 private BaseTemplateData mTemplateData; 590 591 /** 592 * A builder for {@link SmartspaceTarget}. 593 * 594 * @param smartspaceTargetId the id of this target 595 * @param componentName the componentName of this target 596 * @param userHandle the userHandle of this target 597 */ Builder(@onNull String smartspaceTargetId, @NonNull ComponentName componentName, @NonNull UserHandle userHandle)598 public Builder(@NonNull String smartspaceTargetId, 599 @NonNull ComponentName componentName, @NonNull UserHandle userHandle) { 600 this.mSmartspaceTargetId = smartspaceTargetId; 601 this.mComponentName = componentName; 602 this.mUserHandle = userHandle; 603 } 604 605 /** 606 * Sets the header action. 607 */ 608 @NonNull setHeaderAction(@onNull SmartspaceAction headerAction)609 public Builder setHeaderAction(@NonNull SmartspaceAction headerAction) { 610 this.mHeaderAction = headerAction; 611 return this; 612 } 613 614 /** 615 * Sets the base action. 616 */ 617 @NonNull setBaseAction(@onNull SmartspaceAction baseAction)618 public Builder setBaseAction(@NonNull SmartspaceAction baseAction) { 619 this.mBaseAction = baseAction; 620 return this; 621 } 622 623 /** 624 * Sets the creation time. 625 */ 626 @NonNull setCreationTimeMillis(@urrentTimeMillisLong long creationTimeMillis)627 public Builder setCreationTimeMillis(@CurrentTimeMillisLong long creationTimeMillis) { 628 this.mCreationTimeMillis = creationTimeMillis; 629 return this; 630 } 631 632 /** 633 * Sets the expiration time. 634 */ 635 @NonNull setExpiryTimeMillis(@urrentTimeMillisLong long expiryTimeMillis)636 public Builder setExpiryTimeMillis(@CurrentTimeMillisLong long expiryTimeMillis) { 637 this.mExpiryTimeMillis = expiryTimeMillis; 638 return this; 639 } 640 641 /** 642 * Sets the score. 643 */ 644 @NonNull setScore(float score)645 public Builder setScore(float score) { 646 this.mScore = score; 647 return this; 648 } 649 650 /** 651 * Sets the action chips. 652 */ 653 @NonNull setActionChips(@onNull List<SmartspaceAction> actionChips)654 public Builder setActionChips(@NonNull List<SmartspaceAction> actionChips) { 655 this.mActionChips = actionChips; 656 return this; 657 } 658 659 /** 660 * Sets the icon grid. 661 */ 662 @NonNull setIconGrid(@onNull List<SmartspaceAction> iconGrid)663 public Builder setIconGrid(@NonNull List<SmartspaceAction> iconGrid) { 664 this.mIconGrid = iconGrid; 665 return this; 666 } 667 668 /** 669 * Sets the feature type. 670 */ 671 @NonNull setFeatureType(int featureType)672 public Builder setFeatureType(int featureType) { 673 this.mFeatureType = featureType; 674 return this; 675 } 676 677 /** 678 * Sets whether the contents are sensitive. 679 */ 680 @NonNull setSensitive(boolean sensitive)681 public Builder setSensitive(boolean sensitive) { 682 this.mSensitive = sensitive; 683 return this; 684 } 685 686 /** 687 * Sets whether to show the card as expanded. 688 */ 689 @NonNull setShouldShowExpanded(boolean shouldShowExpanded)690 public Builder setShouldShowExpanded(boolean shouldShowExpanded) { 691 this.mShouldShowExpanded = shouldShowExpanded; 692 return this; 693 } 694 695 /** 696 * Sets the source notification key. 697 */ 698 @NonNull setSourceNotificationKey(@onNull String sourceNotificationKey)699 public Builder setSourceNotificationKey(@NonNull String sourceNotificationKey) { 700 this.mSourceNotificationKey = sourceNotificationKey; 701 return this; 702 } 703 704 /** 705 * Sets the associated smartspace target id. 706 */ 707 @NonNull setAssociatedSmartspaceTargetId( @onNull String associatedSmartspaceTargetId)708 public Builder setAssociatedSmartspaceTargetId( 709 @NonNull String associatedSmartspaceTargetId) { 710 this.mAssociatedSmartspaceTargetId = associatedSmartspaceTargetId; 711 return this; 712 } 713 714 /** 715 * Sets the slice uri. 716 * 717 * <p><b>NOTE: </b> If {@link mWidget} is also set, {@link mSliceUri} should be ignored. 718 */ 719 @NonNull setSliceUri(@onNull Uri sliceUri)720 public Builder setSliceUri(@NonNull Uri sliceUri) { 721 this.mSliceUri = sliceUri; 722 return this; 723 } 724 725 /** 726 * Sets the widget id. 727 * 728 * <p><b>NOTE: </b> If {@link mWidget} is set, all other @Nullable params should be 729 * ignored. 730 */ 731 @NonNull setWidget(@onNull AppWidgetProviderInfo widget)732 public Builder setWidget(@NonNull AppWidgetProviderInfo widget) { 733 this.mWidget = widget; 734 return this; 735 } 736 737 /** 738 * Sets the UI template data. 739 */ 740 @NonNull setTemplateData( @ullable BaseTemplateData templateData)741 public Builder setTemplateData( 742 @Nullable BaseTemplateData templateData) { 743 mTemplateData = templateData; 744 return this; 745 } 746 747 /** 748 * Builds a new {@link SmartspaceTarget}. 749 * 750 * @throws IllegalStateException when non null fields are set as null. 751 */ 752 @NonNull build()753 public SmartspaceTarget build() { 754 if (mSmartspaceTargetId == null 755 || mComponentName == null 756 || mUserHandle == null) { 757 throw new IllegalStateException("Please assign a value to all @NonNull args."); 758 } 759 return new SmartspaceTarget(mSmartspaceTargetId, 760 mHeaderAction, mBaseAction, mCreationTimeMillis, mExpiryTimeMillis, mScore, 761 mActionChips, mIconGrid, mFeatureType, mSensitive, mShouldShowExpanded, 762 mSourceNotificationKey, mComponentName, mUserHandle, 763 mAssociatedSmartspaceTargetId, mSliceUri, mWidget, mTemplateData); 764 } 765 } 766 } 767