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.NonNull; 21 import android.annotation.Nullable; 22 import android.nearby.aidl.FastPairEligibleAccountParcel; 23 24 /** 25 * Class for FastPairEligibleAccount and its builder. 26 * 27 * @hide 28 */ 29 public class FastPairEligibleAccount { 30 31 FastPairEligibleAccountParcel mAccountParcel; 32 FastPairEligibleAccount(FastPairEligibleAccountParcel accountParcel)33 FastPairEligibleAccount(FastPairEligibleAccountParcel accountParcel) { 34 this.mAccountParcel = accountParcel; 35 } 36 37 /** 38 * Get Account. 39 * 40 * @hide 41 */ 42 @Nullable getAccount()43 public Account getAccount() { 44 return this.mAccountParcel.account; 45 } 46 47 /** 48 * Get OptIn Status. 49 * 50 * @hide 51 */ isOptIn()52 public boolean isOptIn() { 53 return this.mAccountParcel.optIn; 54 } 55 56 /** 57 * Builder used to create FastPairEligibleAccount. 58 * 59 * @hide 60 */ 61 public static final class Builder { 62 63 private final FastPairEligibleAccountParcel mBuilderParcel; 64 65 /** 66 * Default constructor of Builder. 67 * 68 * @hide 69 */ Builder()70 public Builder() { 71 mBuilderParcel = new FastPairEligibleAccountParcel(); 72 mBuilderParcel.account = null; 73 mBuilderParcel.optIn = false; 74 } 75 76 /** 77 * Set Account. 78 * 79 * @param account Fast Pair eligible account. 80 * @return The builder, to facilitate chaining {@code builder.setXXX(..).setXXX(..)}. 81 * @hide 82 */ 83 @NonNull setAccount(@ullable Account account)84 public Builder setAccount(@Nullable Account account) { 85 mBuilderParcel.account = account; 86 return this; 87 } 88 89 /** 90 * Set whether the account is opt into Fast Pair. 91 * 92 * @param optIn Whether the Fast Pair eligible account opts into Fast Pair. 93 * @return The builder, to facilitate chaining {@code builder.setXXX(..).setXXX(..)}. 94 * @hide 95 */ 96 @NonNull setOptIn(boolean optIn)97 public Builder setOptIn(boolean optIn) { 98 mBuilderParcel.optIn = optIn; 99 return this; 100 } 101 102 /** 103 * Build {@link FastPairEligibleAccount} with the currently set configuration. 104 * 105 * @hide 106 */ 107 @NonNull build()108 public FastPairEligibleAccount build() { 109 return new FastPairEligibleAccount(mBuilderParcel); 110 } 111 } 112 } 113