• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.FastPairDiscoveryItemParcel;
22 
23 /**
24  * Class for FastPairDiscoveryItem and its builder.
25  *
26  * @hide
27  */
28 public class FastPairDiscoveryItem {
29 
30     FastPairDiscoveryItemParcel mMetadataParcel;
31 
FastPairDiscoveryItem( FastPairDiscoveryItemParcel metadataParcel)32     FastPairDiscoveryItem(
33             FastPairDiscoveryItemParcel metadataParcel) {
34         this.mMetadataParcel = metadataParcel;
35     }
36 
37     /**
38      * Get Id.
39      *
40      * @hide
41      */
42     @Nullable
getId()43     public String getId() {
44         return mMetadataParcel.id;
45     }
46 
47     /**
48      * Get MacAddress.
49      *
50      * @hide
51      */
52     @Nullable
getMacAddress()53     public String getMacAddress() {
54         return mMetadataParcel.macAddress;
55     }
56 
57     /**
58      * Get ActionUrl.
59      *
60      * @hide
61      */
62     @Nullable
getActionUrl()63     public String getActionUrl() {
64         return mMetadataParcel.actionUrl;
65     }
66 
67     /**
68      * Get DeviceName.
69      *
70      * @hide
71      */
72     @Nullable
getDeviceName()73     public String getDeviceName() {
74         return mMetadataParcel.deviceName;
75     }
76 
77     /**
78      * Get Title.
79      *
80      * @hide
81      */
82     @Nullable
getTitle()83     public String getTitle() {
84         return mMetadataParcel.title;
85     }
86 
87     /**
88      * Get Description.
89      *
90      * @hide
91      */
92     @Nullable
getDescription()93     public String getDescription() {
94         return mMetadataParcel.description;
95     }
96 
97     /**
98      * Get DisplayUrl.
99      *
100      * @hide
101      */
102     @Nullable
getDisplayUrl()103     public String getDisplayUrl() {
104         return mMetadataParcel.displayUrl;
105     }
106 
107     /**
108      * Get LastObservationTimestampMillis.
109      *
110      * @hide
111      */
getLastObservationTimestampMillis()112     public long getLastObservationTimestampMillis() {
113         return mMetadataParcel.lastObservationTimestampMillis;
114     }
115 
116     /**
117      * Get FirstObservationTimestampMillis.
118      *
119      * @hide
120      */
getFirstObservationTimestampMillis()121     public long getFirstObservationTimestampMillis() {
122         return mMetadataParcel.firstObservationTimestampMillis;
123     }
124 
125     /**
126      * Get State.
127      *
128      * @hide
129      */
getState()130     public int getState() {
131         return mMetadataParcel.state;
132     }
133 
134     /**
135      * Get ActionUrlType.
136      *
137      * @hide
138      */
getActionUrlType()139     public int getActionUrlType() {
140         return mMetadataParcel.actionUrlType;
141     }
142 
143     /**
144      * Get Rssi.
145      *
146      * @hide
147      */
getRssi()148     public int getRssi() {
149         return mMetadataParcel.rssi;
150     }
151 
152     /**
153      * Get PendingAppInstallTimestampMillis.
154      *
155      * @hide
156      */
getPendingAppInstallTimestampMillis()157     public long getPendingAppInstallTimestampMillis() {
158         return mMetadataParcel.pendingAppInstallTimestampMillis;
159     }
160 
161     /**
162      * Get TxPower.
163      *
164      * @hide
165      */
getTxPower()166     public int getTxPower() {
167         return mMetadataParcel.txPower;
168     }
169 
170     /**
171      * Get AppName.
172      *
173      * @hide
174      */
175     @Nullable
getAppName()176     public String getAppName() {
177         return mMetadataParcel.appName;
178     }
179 
180     /**
181      * Get PackageName.
182      *
183      * @hide
184      */
185     @Nullable
getPackageName()186     public String getPackageName() {
187         return mMetadataParcel.packageName;
188     }
189 
190     /**
191      * Get TriggerId.
192      *
193      * @hide
194      */
195     @Nullable
getTriggerId()196     public String getTriggerId() {
197         return mMetadataParcel.triggerId;
198     }
199 
200     /**
201      * Get IconPng, which is submitted at device registration time to display on notification. It is
202      * a 32-bit PNG with dimensions of 512px by 512px.
203      *
204      * @return IconPng in 32-bit PNG with dimensions of 512px by 512px.
205      * @hide
206      */
207     @Nullable
getIconPng()208     public byte[] getIconPng() {
209         return mMetadataParcel.iconPng;
210     }
211 
212     /**
213      * Get IconFifeUrl.
214      *
215      * @hide
216      */
217     @Nullable
getIconFfeUrl()218     public String getIconFfeUrl() {
219         return mMetadataParcel.iconFifeUrl;
220     }
221 
222     /**
223      * Get authenticationPublicKeySecp256r1, which is same as AntiSpoof public key, see
224      * <a href="https://developers.google.com/nearby/fast-pair/spec#data_format">Data Format</a>.
225      *
226      * @return 64-byte authenticationPublicKeySecp256r1.
227      * @hide
228      */
229     @Nullable
getAuthenticationPublicKeySecp256r1()230     public byte[] getAuthenticationPublicKeySecp256r1() {
231         return mMetadataParcel.authenticationPublicKeySecp256r1;
232     }
233 
234     /**
235      * Builder used to create FastPairDiscoveryItem.
236      *
237      * @hide
238      */
239     public static final class Builder {
240 
241         private final FastPairDiscoveryItemParcel mBuilderParcel;
242 
243         /**
244          * Default constructor of Builder.
245          *
246          * @hide
247          */
Builder()248         public Builder() {
249             mBuilderParcel = new FastPairDiscoveryItemParcel();
250         }
251 
252         /**
253          * Set Id.
254          *
255          * @param id Unique id.
256          * @return The builder, to facilitate chaining {@code builder.setXXX(..).setXXX(..)}.
257          *
258          * @hide
259          */
260         @NonNull
setId(@ullable String id)261         public Builder setId(@Nullable String id) {
262             mBuilderParcel.id = id;
263             return this;
264         }
265 
266         /**
267          * Set MacAddress.
268          *
269          * @param macAddress Fast Pair device rotating mac address.
270          * @return The builder, to facilitate chaining {@code builder.setXXX(..).setXXX(..)}.
271          * @hide
272          */
273         @NonNull
setMacAddress(@ullable String macAddress)274         public Builder setMacAddress(@Nullable String macAddress) {
275             mBuilderParcel.macAddress = macAddress;
276             return this;
277         }
278 
279         /**
280          * Set ActionUrl.
281          *
282          * @param actionUrl Action Url of Fast Pair device.
283          * @return The builder, to facilitate chaining {@code builder.setXXX(..).setXXX(..)}.
284          * @hide
285          */
286         @NonNull
setActionUrl(@ullable String actionUrl)287         public Builder setActionUrl(@Nullable String actionUrl) {
288             mBuilderParcel.actionUrl = actionUrl;
289             return this;
290         }
291 
292         /**
293          * Set DeviceName.
294          * @param deviceName Fast Pair device name.
295          * @return The builder, to facilitate chaining {@code builder.setXXX(..).setXXX(..)}.
296          * @hide
297          */
298         @NonNull
setDeviceName(@ullable String deviceName)299         public Builder setDeviceName(@Nullable String deviceName) {
300             mBuilderParcel.deviceName = deviceName;
301             return this;
302         }
303 
304         /**
305          * Set Title.
306          *
307          * @param title Title of Fast Pair device.
308          * @return The builder, to facilitate chaining {@code builder.setXXX(..).setXXX(..)}.
309          * @hide
310          */
311         @NonNull
setTitle(@ullable String title)312         public Builder setTitle(@Nullable String title) {
313             mBuilderParcel.title = title;
314             return this;
315         }
316 
317         /**
318          * Set Description.
319          *
320          * @param description Description of Fast Pair device.
321          * @return The builder, to facilitate chaining {@code builder.setXXX(..).setXXX(..)}.
322          * @hide
323          */
324         @NonNull
setDescription(@ullable String description)325         public Builder setDescription(@Nullable String description) {
326             mBuilderParcel.description = description;
327             return this;
328         }
329 
330         /**
331          * Set DisplayUrl.
332          *
333          * @param displayUrl Display Url of Fast Pair device.
334          * @return The builder, to facilitate chaining {@code builder.setXXX(..).setXXX(..)}.
335          * @hide
336          */
337         @NonNull
setDisplayUrl(@ullable String displayUrl)338         public Builder setDisplayUrl(@Nullable String displayUrl) {
339             mBuilderParcel.displayUrl = displayUrl;
340             return this;
341         }
342 
343         /**
344          * Set LastObservationTimestampMillis.
345          *
346          * @param lastObservationTimestampMillis Last observed timestamp of Fast Pair device, keyed
347          *                                       by a rotating id.
348          * @return The builder, to facilitate chaining {@code builder.setXXX(..).setXXX(..)}.
349          * @hide
350          */
351         @NonNull
setLastObservationTimestampMillis( long lastObservationTimestampMillis)352         public Builder setLastObservationTimestampMillis(
353                 long lastObservationTimestampMillis) {
354             mBuilderParcel.lastObservationTimestampMillis = lastObservationTimestampMillis;
355             return this;
356         }
357 
358         /**
359          * Set FirstObservationTimestampMillis.
360          *
361          * @param firstObservationTimestampMillis First observed timestamp of Fast Pair device,
362          *                                        keyed by a rotating id.
363          * @return The builder, to facilitate chaining {@code builder.setXXX(..).setXXX(..)}.
364          * @hide
365          */
366         @NonNull
setFirstObservationTimestampMillis( long firstObservationTimestampMillis)367         public Builder setFirstObservationTimestampMillis(
368                 long firstObservationTimestampMillis) {
369             mBuilderParcel.firstObservationTimestampMillis = firstObservationTimestampMillis;
370             return this;
371         }
372 
373         /**
374          * Set State.
375          *
376          * @param state Item's current state. e.g. if the item is blocked.
377          * @return The builder, to facilitate chaining {@code builder.setXXX(..).setXXX(..)}.
378          * @hide
379          */
380         @NonNull
setState(int state)381         public Builder setState(int state) {
382             mBuilderParcel.state = state;
383             return this;
384         }
385 
386         /**
387          * Set ActionUrlType.
388          *
389          * @param actionUrlType The resolved url type for the action_url.
390          * @return The builder, to facilitate chaining {@code builder.setXXX(..).setXXX(..)}.
391          * @hide
392          */
393         @NonNull
setActionUrlType(int actionUrlType)394         public Builder setActionUrlType(int actionUrlType) {
395             mBuilderParcel.actionUrlType = actionUrlType;
396             return this;
397         }
398 
399         /**
400          * Set Rssi.
401          *
402          * @param rssi Beacon's RSSI value.
403          * @return The builder, to facilitate chaining {@code builder.setXXX(..).setXXX(..)}.
404          * @hide
405          */
406         @NonNull
setRssi(int rssi)407         public Builder setRssi(int rssi) {
408             mBuilderParcel.rssi = rssi;
409             return this;
410         }
411 
412         /**
413          * Set PendingAppInstallTimestampMillis.
414          *
415          * @param pendingAppInstallTimestampMillis The timestamp when the user is redirected to App
416          *                                         Store after clicking on the item.
417          * @return The builder, to facilitate chaining {@code builder.setXXX(..).setXXX(..)}.
418          * @hide
419          */
420         @NonNull
setPendingAppInstallTimestampMillis(long pendingAppInstallTimestampMillis)421         public Builder setPendingAppInstallTimestampMillis(long pendingAppInstallTimestampMillis) {
422             mBuilderParcel.pendingAppInstallTimestampMillis = pendingAppInstallTimestampMillis;
423             return this;
424         }
425 
426         /**
427          * Set TxPower.
428          *
429          * @param txPower Beacon's tx power.
430          * @return The builder, to facilitate chaining {@code builder.setXXX(..).setXXX(..)}.
431          * @hide
432          */
433         @NonNull
setTxPower(int txPower)434         public Builder setTxPower(int txPower) {
435             mBuilderParcel.txPower = txPower;
436             return this;
437         }
438 
439         /**
440          * Set AppName.
441          *
442          * @param appName Human readable name of the app designated to open the uri.
443          * @return The builder, to facilitate chaining {@code builder.setXXX(..).setXXX(..)}.
444          * @hide
445          */
446         @NonNull
setAppName(@ullable String appName)447         public Builder setAppName(@Nullable String appName) {
448             mBuilderParcel.appName = appName;
449             return this;
450         }
451 
452         /**
453          * Set PackageName.
454          *
455          * @param packageName Package name of the App that owns this item.
456          * @return The builder, to facilitate chaining {@code builder.setXXX(..).setXXX(..)}.
457          * @hide
458          */
459         @NonNull
setPackageName(@ullable String packageName)460         public Builder setPackageName(@Nullable String packageName) {
461             mBuilderParcel.packageName = packageName;
462             return this;
463         }
464 
465         /**
466          * Set TriggerId.
467          *
468          * @param triggerId TriggerId identifies the trigger/beacon that is attached with a message.
469          * @return The builder, to facilitate chaining {@code builder.setXXX(..).setXXX(..)}.
470          * @hide
471          */
472         @NonNull
setTriggerId(@ullable String triggerId)473         public Builder setTriggerId(@Nullable String triggerId) {
474             mBuilderParcel.triggerId = triggerId;
475             return this;
476         }
477 
478         /**
479          * Set IconPng.
480          *
481          * @param iconPng Bytes of item icon in PNG format displayed in Discovery item list.
482          * @return The builder, to facilitate chaining {@code builder.setXXX(..).setXXX(..)}.
483          * @hide
484          */
485         @NonNull
setIconPng(@ullable byte[] iconPng)486         public Builder setIconPng(@Nullable byte[] iconPng) {
487             mBuilderParcel.iconPng = iconPng;
488             return this;
489         }
490 
491         /**
492          * Set IconFifeUrl.
493          *
494          * @param iconFifeUrl A FIFE URL of the item icon displayed in Discovery item list.
495          * @return The builder, to facilitate chaining {@code builder.setXXX(..).setXXX(..)}.
496          * @hide
497          */
498         @NonNull
setIconFfeUrl(@ullable String iconFifeUrl)499         public Builder setIconFfeUrl(@Nullable String iconFifeUrl) {
500             mBuilderParcel.iconFifeUrl = iconFifeUrl;
501             return this;
502         }
503 
504         /**
505          * Set authenticationPublicKeySecp256r1, which is same as AntiSpoof public key, see
506          * <a href="https://developers.google.com/nearby/fast-pair/spec#data_format">Data Format</a>
507          *
508          * @param authenticationPublicKeySecp256r1 64-byte Fast Pair device public key.
509          * @return The builder, to facilitate chaining {@code builder.setXXX(..).setXXX(..)}.
510          * @hide
511          */
512         @NonNull
setAuthenticationPublicKeySecp256r1( @ullable byte[] authenticationPublicKeySecp256r1)513         public Builder setAuthenticationPublicKeySecp256r1(
514                 @Nullable byte[] authenticationPublicKeySecp256r1) {
515             mBuilderParcel.authenticationPublicKeySecp256r1 = authenticationPublicKeySecp256r1;
516             return this;
517         }
518 
519         /**
520          * Build {@link FastPairDiscoveryItem} with the currently set configuration.
521          *
522          * @hide
523          */
524         @NonNull
build()525         public FastPairDiscoveryItem build() {
526             return new FastPairDiscoveryItem(mBuilderParcel);
527         }
528     }
529 }
530