• 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.accounts.Account;
20 import android.annotation.IntDef;
21 import android.annotation.NonNull;
22 import android.annotation.Nullable;
23 import android.app.Service;
24 import android.content.Intent;
25 import android.nearby.aidl.ByteArrayParcel;
26 import android.nearby.aidl.FastPairAccountDevicesMetadataRequestParcel;
27 import android.nearby.aidl.FastPairAccountKeyDeviceMetadataParcel;
28 import android.nearby.aidl.FastPairAntispoofKeyDeviceMetadataRequestParcel;
29 import android.nearby.aidl.FastPairEligibleAccountParcel;
30 import android.nearby.aidl.FastPairEligibleAccountsRequestParcel;
31 import android.nearby.aidl.FastPairManageAccountDeviceRequestParcel;
32 import android.nearby.aidl.FastPairManageAccountRequestParcel;
33 import android.nearby.aidl.IFastPairAccountDevicesMetadataCallback;
34 import android.nearby.aidl.IFastPairAntispoofKeyDeviceMetadataCallback;
35 import android.nearby.aidl.IFastPairDataProvider;
36 import android.nearby.aidl.IFastPairEligibleAccountsCallback;
37 import android.nearby.aidl.IFastPairManageAccountCallback;
38 import android.nearby.aidl.IFastPairManageAccountDeviceCallback;
39 import android.os.IBinder;
40 import android.os.RemoteException;
41 import android.util.Log;
42 
43 import java.lang.annotation.Retention;
44 import java.lang.annotation.RetentionPolicy;
45 import java.util.ArrayList;
46 import java.util.Collection;
47 import java.util.List;
48 
49 /**
50  * A service class for fast pair data providers outside the system server.
51  *
52  * Fast pair providers should be wrapped in a non-exported service which returns the result of
53  * {@link #getBinder()} from the service's {@link android.app.Service#onBind(Intent)} method. The
54  * service should not be exported so that components other than the system server cannot bind to it.
55  * Alternatively, the service may be guarded by a permission that only system server can obtain.
56  *
57  * <p>Fast Pair providers are identified by their UID / package name.
58  *
59  * @hide
60  */
61 public abstract class FastPairDataProviderService extends Service {
62     /**
63      * The action the wrapping service should have in its intent filter to implement the
64      * {@link android.nearby.FastPairDataProviderBase}.
65      *
66      * @hide
67      */
68     public static final String ACTION_FAST_PAIR_DATA_PROVIDER =
69             "android.nearby.action.FAST_PAIR_DATA_PROVIDER";
70 
71     /**
72      * Manage request type to add, or opt-in.
73      *
74      * @hide
75      */
76     public static final int MANAGE_REQUEST_ADD = 0;
77 
78     /**
79      * Manage request type to remove, or opt-out.
80      *
81      * @hide
82      */
83     public static final int MANAGE_REQUEST_REMOVE = 1;
84 
85     /**
86      * @hide
87      */
88     @Retention(RetentionPolicy.SOURCE)
89     @IntDef(value = {
90             MANAGE_REQUEST_ADD,
91             MANAGE_REQUEST_REMOVE})
92     @interface ManageRequestType {}
93 
94     /**
95      * Error code for bad request.
96      *
97      * @hide
98      */
99     public static final int ERROR_CODE_BAD_REQUEST = 0;
100 
101     /**
102      * Error code for internal error.
103      *
104      * @hide
105      */
106     public static final int ERROR_CODE_INTERNAL_ERROR = 1;
107 
108     /**
109      * @hide
110      */
111     @Retention(RetentionPolicy.SOURCE)
112     @IntDef(value = {
113             ERROR_CODE_BAD_REQUEST,
114             ERROR_CODE_INTERNAL_ERROR})
115     @interface ErrorCode {}
116 
117     private final IBinder mBinder;
118     private final String mTag;
119 
120     /**
121      * Constructor of FastPairDataProviderService.
122      *
123      * @param tag TAG for on device logging.
124      * @hide
125      */
FastPairDataProviderService(@onNull String tag)126     public FastPairDataProviderService(@NonNull String tag) {
127         mBinder = new Service();
128         mTag = tag;
129     }
130 
131     @Override
132     @NonNull
onBind(@onNull Intent intent)133     public final IBinder onBind(@NonNull Intent intent) {
134         return mBinder;
135     }
136 
137     /**
138      * Callback to be invoked when an AntispoofKeyed device metadata is loaded.
139      *
140      * @hide
141      */
142     public interface FastPairAntispoofKeyDeviceMetadataCallback {
143 
144         /**
145          * Invoked once the meta data is loaded.
146          *
147          * @hide
148          */
onFastPairAntispoofKeyDeviceMetadataReceived( @onNull FastPairAntispoofKeyDeviceMetadata metadata)149         void onFastPairAntispoofKeyDeviceMetadataReceived(
150                 @NonNull FastPairAntispoofKeyDeviceMetadata metadata);
151 
152         /** Invoked in case of error.
153          *
154          * @hide
155          */
onError(@rrorCode int code, @Nullable String message)156         void onError(@ErrorCode int code, @Nullable String message);
157     }
158 
159     /**
160      * Callback to be invoked when Fast Pair devices of a given account is loaded.
161      *
162      * @hide
163      */
164     public interface FastPairAccountDevicesMetadataCallback {
165 
166         /**
167          * Should be invoked once the metadatas are loaded.
168          *
169          * @hide
170          */
onFastPairAccountDevicesMetadataReceived( @onNull Collection<FastPairAccountKeyDeviceMetadata> metadatas)171         void onFastPairAccountDevicesMetadataReceived(
172                 @NonNull Collection<FastPairAccountKeyDeviceMetadata> metadatas);
173         /**
174          * Invoked in case of error.
175          *
176          * @hide
177          */
onError(@rrorCode int code, @Nullable String message)178         void onError(@ErrorCode int code, @Nullable String message);
179     }
180 
181     /**
182      * Callback to be invoked when FastPair eligible accounts are loaded.
183      *
184      * @hide
185      */
186     public interface FastPairEligibleAccountsCallback {
187 
188         /**
189          * Should be invoked once the eligible accounts are loaded.
190          *
191          * @hide
192          */
onFastPairEligibleAccountsReceived( @onNull Collection<FastPairEligibleAccount> accounts)193         void onFastPairEligibleAccountsReceived(
194                 @NonNull Collection<FastPairEligibleAccount> accounts);
195         /**
196          * Invoked in case of error.
197          *
198          * @hide
199          */
onError(@rrorCode int code, @Nullable String message)200         void onError(@ErrorCode int code, @Nullable String message);
201     }
202 
203     /**
204      * Callback to be invoked when a management action is finished.
205      *
206      * @hide
207      */
208     public interface FastPairManageActionCallback {
209 
210         /**
211          * Should be invoked once the manage action is successful.
212          *
213          * @hide
214          */
onSuccess()215         void onSuccess();
216         /**
217          * Invoked in case of error.
218          *
219          * @hide
220          */
onError(@rrorCode int code, @Nullable String message)221         void onError(@ErrorCode int code, @Nullable String message);
222     }
223 
224     /**
225      * Fulfills the Fast Pair device metadata request by using callback to send back the
226      * device meta data of a given modelId.
227      *
228      * @hide
229      */
onLoadFastPairAntispoofKeyDeviceMetadata( @onNull FastPairAntispoofKeyDeviceMetadataRequest request, @NonNull FastPairAntispoofKeyDeviceMetadataCallback callback)230     public abstract void onLoadFastPairAntispoofKeyDeviceMetadata(
231             @NonNull FastPairAntispoofKeyDeviceMetadataRequest request,
232             @NonNull FastPairAntispoofKeyDeviceMetadataCallback callback);
233 
234     /**
235      * Fulfills the account tied Fast Pair devices metadata request by using callback to send back
236      * all Fast Pair device's metadata of a given account.
237      *
238      * @hide
239      */
onLoadFastPairAccountDevicesMetadata( @onNull FastPairAccountDevicesMetadataRequest request, @NonNull FastPairAccountDevicesMetadataCallback callback)240     public abstract void onLoadFastPairAccountDevicesMetadata(
241             @NonNull FastPairAccountDevicesMetadataRequest request,
242             @NonNull FastPairAccountDevicesMetadataCallback callback);
243 
244     /**
245      * Fulfills the Fast Pair eligible accounts request by using callback to send back Fast Pair
246      * eligible accounts.
247      *
248      * @hide
249      */
onLoadFastPairEligibleAccounts( @onNull FastPairEligibleAccountsRequest request, @NonNull FastPairEligibleAccountsCallback callback)250     public abstract void onLoadFastPairEligibleAccounts(
251             @NonNull FastPairEligibleAccountsRequest request,
252             @NonNull FastPairEligibleAccountsCallback callback);
253 
254     /**
255      * Fulfills the Fast Pair account management request by using callback to send back result.
256      *
257      * @hide
258      */
onManageFastPairAccount( @onNull FastPairManageAccountRequest request, @NonNull FastPairManageActionCallback callback)259     public abstract void onManageFastPairAccount(
260             @NonNull FastPairManageAccountRequest request,
261             @NonNull FastPairManageActionCallback callback);
262 
263     /**
264      * Fulfills the request to manage device-account mapping by using callback to send back result.
265      *
266      * @hide
267      */
onManageFastPairAccountDevice( @onNull FastPairManageAccountDeviceRequest request, @NonNull FastPairManageActionCallback callback)268     public abstract void onManageFastPairAccountDevice(
269             @NonNull FastPairManageAccountDeviceRequest request,
270             @NonNull FastPairManageActionCallback callback);
271 
272     /**
273      * Class for reading FastPairAntispoofKeyDeviceMetadataRequest, which specifies the model ID of
274      * a Fast Pair device. To fulfill this request, corresponding
275      * {@link FastPairAntispoofKeyDeviceMetadata} should be fetched and returned.
276      *
277      * @hide
278      */
279     public static class FastPairAntispoofKeyDeviceMetadataRequest {
280 
281         private final FastPairAntispoofKeyDeviceMetadataRequestParcel mMetadataRequestParcel;
282 
FastPairAntispoofKeyDeviceMetadataRequest( final FastPairAntispoofKeyDeviceMetadataRequestParcel metaDataRequestParcel)283         private FastPairAntispoofKeyDeviceMetadataRequest(
284                 final FastPairAntispoofKeyDeviceMetadataRequestParcel metaDataRequestParcel) {
285             this.mMetadataRequestParcel = metaDataRequestParcel;
286         }
287 
288         /**
289          * Get modelId (24 bit), the key for FastPairAntispoofKeyDeviceMetadata in the same format
290          * returned by Google at device registration time.
291          *
292          * ModelId format is defined at device registration time, see
293          * <a href="https://developers.google.com/nearby/fast-pair/spec#model_id">Model ID</a>.
294          * @return raw bytes of modelId in the same format returned by Google at device registration
295          *         time.
296          * @hide
297          */
getModelId()298         public @NonNull byte[] getModelId() {
299             return this.mMetadataRequestParcel.modelId;
300         }
301     }
302 
303     /**
304      * Class for reading FastPairAccountDevicesMetadataRequest, which specifies the Fast Pair
305      * account and the allow list of the FastPair device keys saved to the account (i.e., FastPair
306      * accountKeys).
307      *
308      * A Fast Pair accountKey is created when a Fast Pair device is saved to an account. It is per
309      * Fast Pair device per account.
310      *
311      * To retrieve all Fast Pair accountKeys saved to an account, the caller needs to set
312      * account with an empty allow list.
313      *
314      * To retrieve metadata of a selected list of Fast Pair devices saved to an account, the caller
315      * needs to set account with a non-empty allow list.
316      * @hide
317      */
318     public static class FastPairAccountDevicesMetadataRequest {
319 
320         private final FastPairAccountDevicesMetadataRequestParcel mMetadataRequestParcel;
321 
FastPairAccountDevicesMetadataRequest( final FastPairAccountDevicesMetadataRequestParcel metaDataRequestParcel)322         private FastPairAccountDevicesMetadataRequest(
323                 final FastPairAccountDevicesMetadataRequestParcel metaDataRequestParcel) {
324             this.mMetadataRequestParcel = metaDataRequestParcel;
325         }
326 
327         /**
328          * Get FastPair account, whose Fast Pair devices' metadata is requested.
329          *
330          * @return a FastPair account.
331          * @hide
332          */
getAccount()333         public @NonNull Account getAccount() {
334             return this.mMetadataRequestParcel.account;
335         }
336 
337         /**
338          * Get allowlist of Fast Pair devices using a collection of deviceAccountKeys.
339          * Note that as a special case, empty list actually means all FastPair devices under the
340          * account instead of none.
341          *
342          * DeviceAccountKey is 16 bytes: first byte is 0x04. Other 15 bytes are randomly generated.
343          *
344          * @return allowlist of Fast Pair devices using a collection of deviceAccountKeys.
345          * @hide
346          */
getDeviceAccountKeys()347         public @NonNull Collection<byte[]> getDeviceAccountKeys()  {
348             if (this.mMetadataRequestParcel.deviceAccountKeys == null) {
349                 return new ArrayList<byte[]>(0);
350             }
351             List<byte[]> deviceAccountKeys =
352                     new ArrayList<>(this.mMetadataRequestParcel.deviceAccountKeys.length);
353             for (ByteArrayParcel deviceAccountKey : this.mMetadataRequestParcel.deviceAccountKeys) {
354                 deviceAccountKeys.add(deviceAccountKey.byteArray);
355             }
356             return deviceAccountKeys;
357         }
358     }
359 
360     /**
361      *  Class for reading FastPairEligibleAccountsRequest. Upon receiving this request, Fast Pair
362      *  eligible accounts should be returned to bind Fast Pair devices.
363      *
364      * @hide
365      */
366     public static class FastPairEligibleAccountsRequest {
367         @SuppressWarnings("UnusedVariable")
368         private final FastPairEligibleAccountsRequestParcel mAccountsRequestParcel;
369 
FastPairEligibleAccountsRequest( final FastPairEligibleAccountsRequestParcel accountsRequestParcel)370         private FastPairEligibleAccountsRequest(
371                 final FastPairEligibleAccountsRequestParcel accountsRequestParcel) {
372             this.mAccountsRequestParcel = accountsRequestParcel;
373         }
374     }
375 
376     /**
377      * Class for reading FastPairManageAccountRequest. If the request type is MANAGE_REQUEST_ADD,
378      * the account is enabled to bind Fast Pair devices; If the request type is
379      * MANAGE_REQUEST_REMOVE, the account is disabled to bind more Fast Pair devices. Furthermore,
380      * all existing bounded Fast Pair devices are unbounded.
381      *
382      * @hide
383      */
384     public static class FastPairManageAccountRequest {
385 
386         private final FastPairManageAccountRequestParcel mAccountRequestParcel;
387 
FastPairManageAccountRequest( final FastPairManageAccountRequestParcel accountRequestParcel)388         private FastPairManageAccountRequest(
389                 final FastPairManageAccountRequestParcel accountRequestParcel) {
390             this.mAccountRequestParcel = accountRequestParcel;
391         }
392 
393         /**
394          * Get request type: MANAGE_REQUEST_ADD, or MANAGE_REQUEST_REMOVE.
395          *
396          * @hide
397          */
getRequestType()398         public @ManageRequestType int getRequestType() {
399             return this.mAccountRequestParcel.requestType;
400         }
401         /**
402          * Get account.
403          *
404          * @hide
405          */
getAccount()406         public @NonNull Account getAccount() {
407             return this.mAccountRequestParcel.account;
408         }
409     }
410 
411     /**
412      *  Class for reading FastPairManageAccountDeviceRequest. If the request type is
413      *  MANAGE_REQUEST_ADD, then a Fast Pair device is bounded to a Fast Pair account. If the
414      *  request type is MANAGE_REQUEST_REMOVE, then a Fast Pair device is removed from a Fast Pair
415      *  account.
416      *
417      * @hide
418      */
419     public static class FastPairManageAccountDeviceRequest {
420 
421         private final FastPairManageAccountDeviceRequestParcel mRequestParcel;
422 
FastPairManageAccountDeviceRequest( final FastPairManageAccountDeviceRequestParcel requestParcel)423         private FastPairManageAccountDeviceRequest(
424                 final FastPairManageAccountDeviceRequestParcel requestParcel) {
425             this.mRequestParcel = requestParcel;
426         }
427 
428         /**
429          * Get request type: MANAGE_REQUEST_ADD, or MANAGE_REQUEST_REMOVE.
430          *
431          * @hide
432          */
getRequestType()433         public @ManageRequestType int getRequestType() {
434             return this.mRequestParcel.requestType;
435         }
436         /**
437          * Get account.
438          *
439          * @hide
440          */
getAccount()441         public @NonNull Account getAccount() {
442             return this.mRequestParcel.account;
443         }
444         /**
445          * Get account key device metadata.
446          *
447          * @hide
448          */
getAccountKeyDeviceMetadata()449         public @NonNull FastPairAccountKeyDeviceMetadata getAccountKeyDeviceMetadata() {
450             return new FastPairAccountKeyDeviceMetadata(
451                     this.mRequestParcel.accountKeyDeviceMetadata);
452         }
453     }
454 
455     /**
456      * Callback class that sends back FastPairAntispoofKeyDeviceMetadata.
457      */
458     private final class WrapperFastPairAntispoofKeyDeviceMetadataCallback implements
459             FastPairAntispoofKeyDeviceMetadataCallback {
460 
461         private IFastPairAntispoofKeyDeviceMetadataCallback mCallback;
462 
WrapperFastPairAntispoofKeyDeviceMetadataCallback( IFastPairAntispoofKeyDeviceMetadataCallback callback)463         private WrapperFastPairAntispoofKeyDeviceMetadataCallback(
464                 IFastPairAntispoofKeyDeviceMetadataCallback callback) {
465             mCallback = callback;
466         }
467 
468         /**
469          * Sends back FastPairAntispoofKeyDeviceMetadata.
470          */
471         @Override
onFastPairAntispoofKeyDeviceMetadataReceived( @onNull FastPairAntispoofKeyDeviceMetadata metadata)472         public void onFastPairAntispoofKeyDeviceMetadataReceived(
473                 @NonNull FastPairAntispoofKeyDeviceMetadata metadata) {
474             try {
475                 mCallback.onFastPairAntispoofKeyDeviceMetadataReceived(metadata.mMetadataParcel);
476             } catch (RemoteException e) {
477                 throw e.rethrowFromSystemServer();
478             } catch (RuntimeException e) {
479                 Log.w(mTag, e);
480             }
481         }
482 
483         @Override
onError(@rrorCode int code, @Nullable String message)484         public void onError(@ErrorCode int code, @Nullable String message) {
485             try {
486                 mCallback.onError(code, message);
487             } catch (RemoteException e) {
488                 throw e.rethrowFromSystemServer();
489             } catch (RuntimeException e) {
490                 Log.w(mTag, e);
491             }
492         }
493     }
494 
495     /**
496      * Callback class that sends back collection of FastPairAccountKeyDeviceMetadata.
497      */
498     private final class WrapperFastPairAccountDevicesMetadataCallback implements
499             FastPairAccountDevicesMetadataCallback {
500 
501         private IFastPairAccountDevicesMetadataCallback mCallback;
502 
WrapperFastPairAccountDevicesMetadataCallback( IFastPairAccountDevicesMetadataCallback callback)503         private WrapperFastPairAccountDevicesMetadataCallback(
504                 IFastPairAccountDevicesMetadataCallback callback) {
505             mCallback = callback;
506         }
507 
508         /**
509          * Sends back collection of FastPairAccountKeyDeviceMetadata.
510          */
511         @Override
onFastPairAccountDevicesMetadataReceived( @onNull Collection<FastPairAccountKeyDeviceMetadata> metadatas)512         public void onFastPairAccountDevicesMetadataReceived(
513                 @NonNull Collection<FastPairAccountKeyDeviceMetadata> metadatas) {
514             FastPairAccountKeyDeviceMetadataParcel[] metadataParcels =
515                     new FastPairAccountKeyDeviceMetadataParcel[metadatas.size()];
516             int i = 0;
517             for (FastPairAccountKeyDeviceMetadata metadata : metadatas) {
518                 metadataParcels[i] = metadata.mMetadataParcel;
519                 i = i + 1;
520             }
521             try {
522                 mCallback.onFastPairAccountDevicesMetadataReceived(metadataParcels);
523             } catch (RemoteException e) {
524                 throw e.rethrowFromSystemServer();
525             } catch (RuntimeException e) {
526                 Log.w(mTag, e);
527             }
528         }
529 
530         @Override
onError(@rrorCode int code, @Nullable String message)531         public void onError(@ErrorCode int code, @Nullable String message) {
532             try {
533                 mCallback.onError(code, message);
534             } catch (RemoteException e) {
535                 throw e.rethrowFromSystemServer();
536             } catch (RuntimeException e) {
537                 Log.w(mTag, e);
538             }
539         }
540     }
541 
542     /**
543      * Callback class that sends back eligible Fast Pair accounts.
544      */
545     private final class WrapperFastPairEligibleAccountsCallback implements
546             FastPairEligibleAccountsCallback {
547 
548         private IFastPairEligibleAccountsCallback mCallback;
549 
WrapperFastPairEligibleAccountsCallback( IFastPairEligibleAccountsCallback callback)550         private WrapperFastPairEligibleAccountsCallback(
551                 IFastPairEligibleAccountsCallback callback) {
552             mCallback = callback;
553         }
554 
555         /**
556          * Sends back the eligible Fast Pair accounts.
557          */
558         @Override
onFastPairEligibleAccountsReceived( @onNull Collection<FastPairEligibleAccount> accounts)559         public void onFastPairEligibleAccountsReceived(
560                 @NonNull Collection<FastPairEligibleAccount> accounts) {
561             int i = 0;
562             FastPairEligibleAccountParcel[] accountParcels =
563                     new FastPairEligibleAccountParcel[accounts.size()];
564             for (FastPairEligibleAccount account: accounts) {
565                 accountParcels[i] = account.mAccountParcel;
566                 i = i + 1;
567             }
568             try {
569                 mCallback.onFastPairEligibleAccountsReceived(accountParcels);
570             } catch (RemoteException e) {
571                 throw e.rethrowFromSystemServer();
572             } catch (RuntimeException e) {
573                 Log.w(mTag, e);
574             }
575         }
576 
577         @Override
onError(@rrorCode int code, @Nullable String message)578         public void onError(@ErrorCode int code, @Nullable String message) {
579             try {
580                 mCallback.onError(code, message);
581             } catch (RemoteException e) {
582                 throw e.rethrowFromSystemServer();
583             } catch (RuntimeException e) {
584                 Log.w(mTag, e);
585             }
586         }
587     }
588 
589     /**
590      * Callback class that sends back Fast Pair account management result.
591      */
592     private final class WrapperFastPairManageAccountCallback implements
593             FastPairManageActionCallback {
594 
595         private IFastPairManageAccountCallback mCallback;
596 
WrapperFastPairManageAccountCallback( IFastPairManageAccountCallback callback)597         private WrapperFastPairManageAccountCallback(
598                 IFastPairManageAccountCallback callback) {
599             mCallback = callback;
600         }
601 
602         /**
603          * Sends back Fast Pair account opt in result.
604          */
605         @Override
onSuccess()606         public void onSuccess() {
607             try {
608                 mCallback.onSuccess();
609             } catch (RemoteException e) {
610                 throw e.rethrowFromSystemServer();
611             } catch (RuntimeException e) {
612                 Log.w(mTag, e);
613             }
614         }
615 
616         @Override
onError(@rrorCode int code, @Nullable String message)617         public void onError(@ErrorCode int code, @Nullable String message) {
618             try {
619                 mCallback.onError(code, message);
620             } catch (RemoteException e) {
621                 throw e.rethrowFromSystemServer();
622             } catch (RuntimeException e) {
623                 Log.w(mTag, e);
624             }
625         }
626     }
627 
628     /**
629      * Call back class that sends back account-device mapping management result.
630      */
631     private final class WrapperFastPairManageAccountDeviceCallback implements
632             FastPairManageActionCallback {
633 
634         private IFastPairManageAccountDeviceCallback mCallback;
635 
WrapperFastPairManageAccountDeviceCallback( IFastPairManageAccountDeviceCallback callback)636         private WrapperFastPairManageAccountDeviceCallback(
637                 IFastPairManageAccountDeviceCallback callback) {
638             mCallback = callback;
639         }
640 
641         /**
642          * Sends back the account-device mapping management result.
643          */
644         @Override
onSuccess()645         public void onSuccess() {
646             try {
647                 mCallback.onSuccess();
648             } catch (RemoteException e) {
649                 throw e.rethrowFromSystemServer();
650             } catch (RuntimeException e) {
651                 Log.w(mTag, e);
652             }
653         }
654 
655         @Override
onError(@rrorCode int code, @Nullable String message)656         public void onError(@ErrorCode int code, @Nullable String message) {
657             try {
658                 mCallback.onError(code, message);
659             } catch (RemoteException e) {
660                 throw e.rethrowFromSystemServer();
661             } catch (RuntimeException e) {
662                 Log.w(mTag, e);
663             }
664         }
665     }
666 
667     private final class Service extends IFastPairDataProvider.Stub {
668 
Service()669         Service() {
670         }
671 
672         @Override
loadFastPairAntispoofKeyDeviceMetadata( @onNull FastPairAntispoofKeyDeviceMetadataRequestParcel requestParcel, IFastPairAntispoofKeyDeviceMetadataCallback callback)673         public void loadFastPairAntispoofKeyDeviceMetadata(
674                 @NonNull FastPairAntispoofKeyDeviceMetadataRequestParcel requestParcel,
675                 IFastPairAntispoofKeyDeviceMetadataCallback callback) {
676             onLoadFastPairAntispoofKeyDeviceMetadata(
677                     new FastPairAntispoofKeyDeviceMetadataRequest(requestParcel),
678                     new WrapperFastPairAntispoofKeyDeviceMetadataCallback(callback));
679         }
680 
681         @Override
loadFastPairAccountDevicesMetadata( @onNull FastPairAccountDevicesMetadataRequestParcel requestParcel, IFastPairAccountDevicesMetadataCallback callback)682         public void loadFastPairAccountDevicesMetadata(
683                 @NonNull FastPairAccountDevicesMetadataRequestParcel requestParcel,
684                 IFastPairAccountDevicesMetadataCallback callback) {
685             onLoadFastPairAccountDevicesMetadata(
686                     new FastPairAccountDevicesMetadataRequest(requestParcel),
687                     new WrapperFastPairAccountDevicesMetadataCallback(callback));
688         }
689 
690         @Override
loadFastPairEligibleAccounts( @onNull FastPairEligibleAccountsRequestParcel requestParcel, IFastPairEligibleAccountsCallback callback)691         public void loadFastPairEligibleAccounts(
692                 @NonNull FastPairEligibleAccountsRequestParcel requestParcel,
693                 IFastPairEligibleAccountsCallback callback) {
694             onLoadFastPairEligibleAccounts(new FastPairEligibleAccountsRequest(requestParcel),
695                     new WrapperFastPairEligibleAccountsCallback(callback));
696         }
697 
698         @Override
manageFastPairAccount( @onNull FastPairManageAccountRequestParcel requestParcel, IFastPairManageAccountCallback callback)699         public void manageFastPairAccount(
700                 @NonNull FastPairManageAccountRequestParcel requestParcel,
701                 IFastPairManageAccountCallback callback) {
702             onManageFastPairAccount(new FastPairManageAccountRequest(requestParcel),
703                     new WrapperFastPairManageAccountCallback(callback));
704         }
705 
706         @Override
manageFastPairAccountDevice( @onNull FastPairManageAccountDeviceRequestParcel requestParcel, IFastPairManageAccountDeviceCallback callback)707         public void manageFastPairAccountDevice(
708                 @NonNull FastPairManageAccountDeviceRequestParcel requestParcel,
709                 IFastPairManageAccountDeviceCallback callback) {
710             onManageFastPairAccountDevice(new FastPairManageAccountDeviceRequest(requestParcel),
711                     new WrapperFastPairManageAccountDeviceCallback(callback));
712         }
713     }
714 }
715