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 17 package android.nearby; 18 19 import android.annotation.NonNull; 20 import android.annotation.Nullable; 21 import android.nearby.aidl.FastPairDeviceMetadataParcel; 22 23 /** 24 * Class for the properties of a given type of Fast Pair device, including images and text. 25 * 26 * @hide 27 */ 28 public class FastPairDeviceMetadata { 29 30 FastPairDeviceMetadataParcel mMetadataParcel; 31 FastPairDeviceMetadata( FastPairDeviceMetadataParcel metadataParcel)32 FastPairDeviceMetadata( 33 FastPairDeviceMetadataParcel metadataParcel) { 34 this.mMetadataParcel = metadataParcel; 35 } 36 37 /** 38 * Get ImageUrl, which will be displayed in notification. 39 * 40 * @hide 41 */ 42 @Nullable getImageUrl()43 public String getImageUrl() { 44 return mMetadataParcel.imageUrl; 45 } 46 47 /** 48 * Get IntentUri, which will be launched to install companion app. 49 * 50 * @hide 51 */ 52 @Nullable getIntentUri()53 public String getIntentUri() { 54 return mMetadataParcel.intentUri; 55 } 56 57 /** 58 * Get BLE transmit power, as described in Fast Pair spec, see 59 * <a href="https://developers.google.com/nearby/fast-pair/spec#transmit_power">Transmit Power</a> 60 * 61 * @hide 62 */ getBleTxPower()63 public int getBleTxPower() { 64 return mMetadataParcel.bleTxPower; 65 } 66 67 /** 68 * Get Fast Pair Half Sheet trigger distance in meters. 69 * 70 * @hide 71 */ getTriggerDistance()72 public float getTriggerDistance() { 73 return mMetadataParcel.triggerDistance; 74 } 75 76 /** 77 * Get Fast Pair device image, which is submitted at device registration time to display on 78 * notification. It is a 32-bit PNG with dimensions of 512px by 512px. 79 * 80 * @return Fast Pair device image in 32-bit PNG with dimensions of 512px by 512px. 81 * @hide 82 */ 83 @Nullable getImage()84 public byte[] getImage() { 85 return mMetadataParcel.image; 86 } 87 88 /** 89 * Get Fast Pair device type. 90 * DEVICE_TYPE_UNSPECIFIED = 0; 91 * HEADPHONES = 1; 92 * TRUE_WIRELESS_HEADPHONES = 7; 93 * @hide 94 */ getDeviceType()95 public int getDeviceType() { 96 return mMetadataParcel.deviceType; 97 } 98 99 /** 100 * Get Fast Pair device name. e.g., "Pixel Buds A-Series". 101 * 102 * @hide 103 */ 104 @Nullable getName()105 public String getName() { 106 return mMetadataParcel.name; 107 } 108 109 /** 110 * Get true wireless image url for left bud. 111 * 112 * @hide 113 */ 114 @Nullable getTrueWirelessImageUrlLeftBud()115 public String getTrueWirelessImageUrlLeftBud() { 116 return mMetadataParcel.trueWirelessImageUrlLeftBud; 117 } 118 119 /** 120 * Get true wireless image url for right bud. 121 * 122 * @hide 123 */ 124 @Nullable getTrueWirelessImageUrlRightBud()125 public String getTrueWirelessImageUrlRightBud() { 126 return mMetadataParcel.trueWirelessImageUrlRightBud; 127 } 128 129 /** 130 * Get true wireless image url for case. 131 * 132 * @hide 133 */ 134 @Nullable getTrueWirelessImageUrlCase()135 public String getTrueWirelessImageUrlCase() { 136 return mMetadataParcel.trueWirelessImageUrlCase; 137 } 138 139 /** 140 * Get InitialNotificationDescription, which is a translated string of 141 * "Tap to pair. Earbuds will be tied to %s" based on locale. 142 * 143 * @hide 144 */ 145 @Nullable getInitialNotificationDescription()146 public String getInitialNotificationDescription() { 147 return mMetadataParcel.initialNotificationDescription; 148 } 149 150 /** 151 * Get InitialNotificationDescriptionNoAccount, which is a translated string of 152 * "Tap to pair with this device" based on locale. 153 * 154 * @hide 155 */ 156 @Nullable getInitialNotificationDescriptionNoAccount()157 public String getInitialNotificationDescriptionNoAccount() { 158 return mMetadataParcel.initialNotificationDescriptionNoAccount; 159 } 160 161 /** 162 * Get OpenCompanionAppDescription, which is a translated string of 163 * "Tap to finish setup" based on locale. 164 * 165 * @hide 166 */ 167 @Nullable getOpenCompanionAppDescription()168 public String getOpenCompanionAppDescription() { 169 return mMetadataParcel.openCompanionAppDescription; 170 } 171 172 /** 173 * Get UpdateCompanionAppDescription, which is a translated string of 174 * "Tap to update device settings and finish setup" based on locale. 175 * 176 * @hide 177 */ 178 @Nullable getUpdateCompanionAppDescription()179 public String getUpdateCompanionAppDescription() { 180 return mMetadataParcel.updateCompanionAppDescription; 181 } 182 183 /** 184 * Get DownloadCompanionAppDescription, which is a translated string of 185 * "Tap to download device app on Google Play and see all features" based on locale. 186 * 187 * @hide 188 */ 189 @Nullable getDownloadCompanionAppDescription()190 public String getDownloadCompanionAppDescription() { 191 return mMetadataParcel.downloadCompanionAppDescription; 192 } 193 194 /** 195 * Get UnableToConnectTitle, which is a translated string of 196 * "Unable to connect" based on locale. 197 */ 198 @Nullable getUnableToConnectTitle()199 public String getUnableToConnectTitle() { 200 return mMetadataParcel.unableToConnectTitle; 201 } 202 203 /** 204 * Get UnableToConnectDescription, which is a translated string of 205 * "Try manually pairing to the device" based on locale. 206 * 207 * @hide 208 */ 209 @Nullable getUnableToConnectDescription()210 public String getUnableToConnectDescription() { 211 return mMetadataParcel.unableToConnectDescription; 212 } 213 214 /** 215 * Get InitialPairingDescription, which is a translated string of 216 * "%s will appear on devices linked with %s" based on locale. 217 * 218 * @hide 219 */ 220 @Nullable getInitialPairingDescription()221 public String getInitialPairingDescription() { 222 return mMetadataParcel.initialPairingDescription; 223 } 224 225 /** 226 * Get ConnectSuccessCompanionAppInstalled, which is a translated string of 227 * "Your device is ready to be set up" based on locale. 228 * 229 * @hide 230 */ 231 @Nullable getConnectSuccessCompanionAppInstalled()232 public String getConnectSuccessCompanionAppInstalled() { 233 return mMetadataParcel.connectSuccessCompanionAppInstalled; 234 } 235 236 /** 237 * Get ConnectSuccessCompanionAppNotInstalled, which is a translated string of 238 * "Download the device app on Google Play to see all available features" based on locale. 239 * 240 * @hide 241 */ 242 @Nullable getConnectSuccessCompanionAppNotInstalled()243 public String getConnectSuccessCompanionAppNotInstalled() { 244 return mMetadataParcel.connectSuccessCompanionAppNotInstalled; 245 } 246 247 /** 248 * Get SubsequentPairingDescription, which is a translated string of 249 * "Connect %s to this phone" based on locale. 250 * 251 * @hide 252 */ 253 @Nullable getSubsequentPairingDescription()254 public String getSubsequentPairingDescription() { 255 return mMetadataParcel.subsequentPairingDescription; 256 } 257 258 /** 259 * Get RetroactivePairingDescription, which is a translated string of 260 * "Save device to %s for faster pairing to your other devices" based on locale. 261 * 262 * @hide 263 */ 264 @Nullable getRetroactivePairingDescription()265 public String getRetroactivePairingDescription() { 266 return mMetadataParcel.retroactivePairingDescription; 267 } 268 269 /** 270 * Get WaitLaunchCompanionAppDescription, which is a translated string of 271 * "This will take a few moments" based on locale. 272 * 273 * @hide 274 */ 275 @Nullable getWaitLaunchCompanionAppDescription()276 public String getWaitLaunchCompanionAppDescription() { 277 return mMetadataParcel.waitLaunchCompanionAppDescription; 278 } 279 280 /** 281 * Get FailConnectGoToSettingsDescription, which is a translated string of 282 * "Try manually pairing to the device by going to Settings" based on locale. 283 * 284 * @hide 285 */ 286 @Nullable getFailConnectGoToSettingsDescription()287 public String getFailConnectGoToSettingsDescription() { 288 return mMetadataParcel.failConnectGoToSettingsDescription; 289 } 290 291 /** 292 * Builder used to create FastPairDeviceMetadata. 293 * 294 * @hide 295 */ 296 public static final class Builder { 297 298 private final FastPairDeviceMetadataParcel mBuilderParcel; 299 300 /** 301 * Default constructor of Builder. 302 * 303 * @hide 304 */ Builder()305 public Builder() { 306 mBuilderParcel = new FastPairDeviceMetadataParcel(); 307 mBuilderParcel.imageUrl = null; 308 mBuilderParcel.intentUri = null; 309 mBuilderParcel.name = null; 310 mBuilderParcel.bleTxPower = 0; 311 mBuilderParcel.triggerDistance = 0; 312 mBuilderParcel.image = null; 313 mBuilderParcel.deviceType = 0; // DEVICE_TYPE_UNSPECIFIED 314 mBuilderParcel.trueWirelessImageUrlLeftBud = null; 315 mBuilderParcel.trueWirelessImageUrlRightBud = null; 316 mBuilderParcel.trueWirelessImageUrlCase = null; 317 mBuilderParcel.initialNotificationDescription = null; 318 mBuilderParcel.initialNotificationDescriptionNoAccount = null; 319 mBuilderParcel.openCompanionAppDescription = null; 320 mBuilderParcel.updateCompanionAppDescription = null; 321 mBuilderParcel.downloadCompanionAppDescription = null; 322 mBuilderParcel.unableToConnectTitle = null; 323 mBuilderParcel.unableToConnectDescription = null; 324 mBuilderParcel.initialPairingDescription = null; 325 mBuilderParcel.connectSuccessCompanionAppInstalled = null; 326 mBuilderParcel.connectSuccessCompanionAppNotInstalled = null; 327 mBuilderParcel.subsequentPairingDescription = null; 328 mBuilderParcel.retroactivePairingDescription = null; 329 mBuilderParcel.waitLaunchCompanionAppDescription = null; 330 mBuilderParcel.failConnectGoToSettingsDescription = null; 331 } 332 333 /** 334 * Set ImageUlr. 335 * 336 * @param imageUrl Image Ulr. 337 * @return The builder, to facilitate chaining {@code builder.setXXX(..).setXXX(..)}. 338 * @hide 339 */ 340 @NonNull setImageUrl(@ullable String imageUrl)341 public Builder setImageUrl(@Nullable String imageUrl) { 342 mBuilderParcel.imageUrl = imageUrl; 343 return this; 344 } 345 346 /** 347 * Set IntentUri. 348 * 349 * @param intentUri Intent uri. 350 * @return The builder, to facilitate chaining {@code builder.setXXX(..).setXXX(..)}. 351 * @hide 352 */ 353 @NonNull setIntentUri(@ullable String intentUri)354 public Builder setIntentUri(@Nullable String intentUri) { 355 mBuilderParcel.intentUri = intentUri; 356 return this; 357 } 358 359 /** 360 * Set device name. 361 * 362 * @param name Device name. 363 * @return The builder, to facilitate chaining {@code builder.setXXX(..).setXXX(..)}. 364 * @hide 365 */ 366 @NonNull setName(@ullable String name)367 public Builder setName(@Nullable String name) { 368 mBuilderParcel.name = name; 369 return this; 370 } 371 372 /** 373 * Set ble transmission power. 374 * 375 * @param bleTxPower Ble transmission power. 376 * @return The builder, to facilitate chaining {@code builder.setXXX(..).setXXX(..)}. 377 * @hide 378 */ 379 @NonNull setBleTxPower(int bleTxPower)380 public Builder setBleTxPower(int bleTxPower) { 381 mBuilderParcel.bleTxPower = bleTxPower; 382 return this; 383 } 384 385 /** 386 * Set trigger distance. 387 * 388 * @param triggerDistance Fast Pair trigger distance. 389 * @return The builder, to facilitate chaining {@code builder.setXXX(..).setXXX(..)}. 390 * @hide 391 */ 392 @NonNull setTriggerDistance(float triggerDistance)393 public Builder setTriggerDistance(float triggerDistance) { 394 mBuilderParcel.triggerDistance = triggerDistance; 395 return this; 396 } 397 398 /** 399 * Set image. 400 * 401 * @param image Fast Pair device image, which is submitted at device registration time to 402 * display on notification. It is a 32-bit PNG with dimensions of 403 * 512px by 512px. 404 * @return The builder, to facilitate chaining {@code builder.setXXX(..).setXXX(..)}. 405 * @hide 406 */ 407 @NonNull setImage(@ullable byte[] image)408 public Builder setImage(@Nullable byte[] image) { 409 mBuilderParcel.image = image; 410 return this; 411 } 412 413 /** 414 * Set device type. 415 * 416 * @param deviceType Fast Pair device type. 417 * @return The builder, to facilitate chaining {@code builder.setXXX(..).setXXX(..)}. 418 * @hide 419 */ 420 @NonNull setDeviceType(int deviceType)421 public Builder setDeviceType(int deviceType) { 422 mBuilderParcel.deviceType = deviceType; 423 return this; 424 } 425 426 /** 427 * Set true wireless image url for left bud. 428 * 429 * @param trueWirelessImageUrlLeftBud True wireless image url for left bud. 430 * @return The builder, to facilitate chaining {@code builder.setXXX(..).setXXX(..)}. 431 * @hide 432 */ 433 @NonNull setTrueWirelessImageUrlLeftBud( @ullable String trueWirelessImageUrlLeftBud)434 public Builder setTrueWirelessImageUrlLeftBud( 435 @Nullable String trueWirelessImageUrlLeftBud) { 436 mBuilderParcel.trueWirelessImageUrlLeftBud = trueWirelessImageUrlLeftBud; 437 return this; 438 } 439 440 /** 441 * Set true wireless image url for right bud. 442 * 443 * @param trueWirelessImageUrlRightBud True wireless image url for right bud. 444 * @return The builder, to facilitate chaining {@code builder.setXXX(..).setXXX(..)}. 445 * @hide 446 */ 447 @NonNull setTrueWirelessImageUrlRightBud( @ullable String trueWirelessImageUrlRightBud)448 public Builder setTrueWirelessImageUrlRightBud( 449 @Nullable String trueWirelessImageUrlRightBud) { 450 mBuilderParcel.trueWirelessImageUrlRightBud = trueWirelessImageUrlRightBud; 451 return this; 452 } 453 454 /** 455 * Set true wireless image url for case. 456 * 457 * @param trueWirelessImageUrlCase True wireless image url for case. 458 * @return The builder, to facilitate chaining {@code builder.setXXX(..).setXXX(..)}. 459 * @hide 460 */ 461 @NonNull setTrueWirelessImageUrlCase(@ullable String trueWirelessImageUrlCase)462 public Builder setTrueWirelessImageUrlCase(@Nullable String trueWirelessImageUrlCase) { 463 mBuilderParcel.trueWirelessImageUrlCase = trueWirelessImageUrlCase; 464 return this; 465 } 466 467 /** 468 * Set InitialNotificationDescription. 469 * 470 * @param initialNotificationDescription Initial notification description. 471 * @return The builder, to facilitate chaining {@code builder.setXXX(..).setXXX(..)}. 472 * @hide 473 */ 474 @NonNull setInitialNotificationDescription( @ullable String initialNotificationDescription)475 public Builder setInitialNotificationDescription( 476 @Nullable String initialNotificationDescription) { 477 mBuilderParcel.initialNotificationDescription = initialNotificationDescription; 478 return this; 479 } 480 481 /** 482 * Set InitialNotificationDescriptionNoAccount. 483 * 484 * @param initialNotificationDescriptionNoAccount Initial notification description when 485 * account is not present. 486 * @return The builder, to facilitate chaining {@code builder.setXXX(..).setXXX(..)}. 487 * @hide 488 */ 489 @NonNull setInitialNotificationDescriptionNoAccount( @ullable String initialNotificationDescriptionNoAccount)490 public Builder setInitialNotificationDescriptionNoAccount( 491 @Nullable String initialNotificationDescriptionNoAccount) { 492 mBuilderParcel.initialNotificationDescriptionNoAccount = 493 initialNotificationDescriptionNoAccount; 494 return this; 495 } 496 497 /** 498 * Set OpenCompanionAppDescription. 499 * 500 * @param openCompanionAppDescription Description for opening companion app. 501 * @return The builder, to facilitate chaining {@code builder.setXXX(..).setXXX(..)}. 502 * @hide 503 */ 504 @NonNull setOpenCompanionAppDescription( @ullable String openCompanionAppDescription)505 public Builder setOpenCompanionAppDescription( 506 @Nullable String openCompanionAppDescription) { 507 mBuilderParcel.openCompanionAppDescription = openCompanionAppDescription; 508 return this; 509 } 510 511 /** 512 * Set UpdateCompanionAppDescription. 513 * 514 * @param updateCompanionAppDescription Description for updating companion app. 515 * @return The builder, to facilitate chaining {@code builder.setXXX(..).setXXX(..)}. 516 * @hide 517 */ 518 @NonNull setUpdateCompanionAppDescription( @ullable String updateCompanionAppDescription)519 public Builder setUpdateCompanionAppDescription( 520 @Nullable String updateCompanionAppDescription) { 521 mBuilderParcel.updateCompanionAppDescription = updateCompanionAppDescription; 522 return this; 523 } 524 525 /** 526 * Set DownloadCompanionAppDescription. 527 * 528 * @param downloadCompanionAppDescription Description for downloading companion app. 529 * @return The builder, to facilitate chaining {@code builder.setXXX(..).setXXX(..)}. 530 * @hide 531 */ 532 @NonNull setDownloadCompanionAppDescription( @ullable String downloadCompanionAppDescription)533 public Builder setDownloadCompanionAppDescription( 534 @Nullable String downloadCompanionAppDescription) { 535 mBuilderParcel.downloadCompanionAppDescription = downloadCompanionAppDescription; 536 return this; 537 } 538 539 /** 540 * Set UnableToConnectTitle. 541 * 542 * @param unableToConnectTitle Title when Fast Pair device is unable to be connected to. 543 * @return The builder, to facilitate chaining {@code builder.setXXX(..).setXXX(..)}. 544 * @hide 545 */ 546 @NonNull setUnableToConnectTitle(@ullable String unableToConnectTitle)547 public Builder setUnableToConnectTitle(@Nullable String unableToConnectTitle) { 548 mBuilderParcel.unableToConnectTitle = unableToConnectTitle; 549 return this; 550 } 551 552 /** 553 * Set UnableToConnectDescription. 554 * 555 * @param unableToConnectDescription Description when Fast Pair device is unable to be 556 * connected to. 557 * @return The builder, to facilitate chaining {@code builder.setXXX(..).setXXX(..)}. 558 * @hide 559 */ 560 @NonNull setUnableToConnectDescription( @ullable String unableToConnectDescription)561 public Builder setUnableToConnectDescription( 562 @Nullable String unableToConnectDescription) { 563 mBuilderParcel.unableToConnectDescription = unableToConnectDescription; 564 return this; 565 } 566 567 /** 568 * Set InitialPairingDescription. 569 * 570 * @param initialPairingDescription Description for Fast Pair initial pairing. 571 * @return The builder, to facilitate chaining {@code builder.setXXX(..).setXXX(..)}. 572 * @hide 573 */ 574 @NonNull setInitialPairingDescription(@ullable String initialPairingDescription)575 public Builder setInitialPairingDescription(@Nullable String initialPairingDescription) { 576 mBuilderParcel.initialPairingDescription = initialPairingDescription; 577 return this; 578 } 579 580 /** 581 * Set ConnectSuccessCompanionAppInstalled. 582 * 583 * @param connectSuccessCompanionAppInstalled Description that let user open the companion 584 * app. 585 * @return The builder, to facilitate chaining {@code builder.setXXX(..).setXXX(..)}. 586 * @hide 587 */ 588 @NonNull setConnectSuccessCompanionAppInstalled( @ullable String connectSuccessCompanionAppInstalled)589 public Builder setConnectSuccessCompanionAppInstalled( 590 @Nullable String connectSuccessCompanionAppInstalled) { 591 mBuilderParcel.connectSuccessCompanionAppInstalled = 592 connectSuccessCompanionAppInstalled; 593 return this; 594 } 595 596 /** 597 * Set ConnectSuccessCompanionAppNotInstalled. 598 * 599 * @param connectSuccessCompanionAppNotInstalled Description that let user download the 600 * companion app. 601 * @return The builder, to facilitate chaining {@code builder.setXXX(..).setXXX(..)}. 602 * @hide 603 */ 604 @NonNull setConnectSuccessCompanionAppNotInstalled( @ullable String connectSuccessCompanionAppNotInstalled)605 public Builder setConnectSuccessCompanionAppNotInstalled( 606 @Nullable String connectSuccessCompanionAppNotInstalled) { 607 mBuilderParcel.connectSuccessCompanionAppNotInstalled = 608 connectSuccessCompanionAppNotInstalled; 609 return this; 610 } 611 612 /** 613 * Set SubsequentPairingDescription. 614 * 615 * @param subsequentPairingDescription Description that reminds user there is a paired 616 * device nearby. 617 * @return The builder, to facilitate chaining {@code builder.setXXX(..).setXXX(..)}. 618 * @hide 619 */ 620 @NonNull setSubsequentPairingDescription( @ullable String subsequentPairingDescription)621 public Builder setSubsequentPairingDescription( 622 @Nullable String subsequentPairingDescription) { 623 mBuilderParcel.subsequentPairingDescription = subsequentPairingDescription; 624 return this; 625 } 626 627 /** 628 * Set RetroactivePairingDescription. 629 * 630 * @param retroactivePairingDescription Description that reminds users opt in their device. 631 * @return The builder, to facilitate chaining {@code builder.setXXX(..).setXXX(..)}. 632 * @hide 633 */ 634 @NonNull setRetroactivePairingDescription( @ullable String retroactivePairingDescription)635 public Builder setRetroactivePairingDescription( 636 @Nullable String retroactivePairingDescription) { 637 mBuilderParcel.retroactivePairingDescription = retroactivePairingDescription; 638 return this; 639 } 640 641 /** 642 * Set WaitLaunchCompanionAppDescription. 643 * 644 * @param waitLaunchCompanionAppDescription Description that indicates companion app is 645 * about to launch. 646 * @return The builder, to facilitate chaining {@code builder.setXXX(..).setXXX(..)}. 647 * @hide 648 */ 649 @NonNull setWaitLaunchCompanionAppDescription( @ullable String waitLaunchCompanionAppDescription)650 public Builder setWaitLaunchCompanionAppDescription( 651 @Nullable String waitLaunchCompanionAppDescription) { 652 mBuilderParcel.waitLaunchCompanionAppDescription = 653 waitLaunchCompanionAppDescription; 654 return this; 655 } 656 657 /** 658 * Set FailConnectGoToSettingsDescription. 659 * 660 * @param failConnectGoToSettingsDescription Description that indicates go to bluetooth 661 * settings when connection fail. 662 * @return The builder, to facilitate chaining {@code builder.setXXX(..).setXXX(..)}. 663 * @hide 664 */ 665 @NonNull setFailConnectGoToSettingsDescription( @ullable String failConnectGoToSettingsDescription)666 public Builder setFailConnectGoToSettingsDescription( 667 @Nullable String failConnectGoToSettingsDescription) { 668 mBuilderParcel.failConnectGoToSettingsDescription = 669 failConnectGoToSettingsDescription; 670 return this; 671 } 672 673 /** 674 * Build {@link FastPairDeviceMetadata} with the currently set configuration. 675 * 676 * @hide 677 */ 678 @NonNull build()679 public FastPairDeviceMetadata build() { 680 return new FastPairDeviceMetadata(mBuilderParcel); 681 } 682 } 683 } 684