1 /*
2  * Copyright (C) 2023 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 com.android.server.remoteauth.ranging;
17 
18 import android.annotation.NonNull;
19 import android.annotation.Nullable;
20 
21 import androidx.annotation.IntDef;
22 
23 import com.google.common.collect.ImmutableList;
24 
25 import java.lang.annotation.Retention;
26 import java.lang.annotation.RetentionPolicy;
27 import java.util.ArrayList;
28 import java.util.List;
29 
30 /** The ranging capabilities of the device. */
31 public class RangingCapabilities {
32 
33     /** Possible ranging methods */
34     @Retention(RetentionPolicy.SOURCE)
35     @IntDef(
36             value = {
37                 RANGING_METHOD_UNKNOWN,
38                 RANGING_METHOD_UWB,
39             })
40     public @interface RangingMethod {}
41 
42     /** Unknown ranging method. */
43     public static final int RANGING_METHOD_UNKNOWN = 0x0;
44 
45     /** Ultra-wideband ranging. */
46     public static final int RANGING_METHOD_UWB = 0x1;
47 
48     private final ImmutableList<Integer> mSupportedRangingMethods;
49     private final androidx.core.uwb.backend.impl.internal.RangingCapabilities
50             mUwbRangingCapabilities;
51 
52     /**
53      * Gets the list of supported ranging methods of the device.
54      *
55      * @return list of {@link RangingMethod}
56      */
getSupportedRangingMethods()57     public ImmutableList<Integer> getSupportedRangingMethods() {
58         return mSupportedRangingMethods;
59     }
60 
61     /**
62      * Gets the UWB ranging capabilities of the device.
63      *
64      * @return UWB ranging capabilities, null if UWB is not a supported {@link RangingMethod} in
65      *     {@link #getSupportedRangingMethods}.
66      */
67     @Nullable
getUwbRangingCapabilities()68     public androidx.core.uwb.backend.impl.internal.RangingCapabilities getUwbRangingCapabilities() {
69         return mUwbRangingCapabilities;
70     }
71 
RangingCapabilities( List<Integer> supportedRangingMethods, androidx.core.uwb.backend.impl.internal.RangingCapabilities uwbRangingCapabilities)72     private RangingCapabilities(
73             List<Integer> supportedRangingMethods,
74             androidx.core.uwb.backend.impl.internal.RangingCapabilities uwbRangingCapabilities) {
75         mSupportedRangingMethods = ImmutableList.copyOf(supportedRangingMethods);
76         mUwbRangingCapabilities = uwbRangingCapabilities;
77     }
78 
79     /** Builder class for {@link RangingCapabilities}. */
80     public static final class Builder {
81         private List<Integer> mSupportedRangingMethods = new ArrayList<>();
82         private androidx.core.uwb.backend.impl.internal.RangingCapabilities mUwbRangingCapabilities;
83 
84         /** Adds a supported {@link RangingMethod} */
addSupportedRangingMethods(@angingMethod int rangingMethod)85         public Builder addSupportedRangingMethods(@RangingMethod int rangingMethod) {
86             mSupportedRangingMethods.add(rangingMethod);
87             return this;
88         }
89 
90         /** Sets the uwb ranging capabilities. */
setUwbRangingCapabilities( @onNull androidx.core.uwb.backend.impl.internal.RangingCapabilities uwbRangingCapabilities)91         public Builder setUwbRangingCapabilities(
92                 @NonNull
93                         androidx.core.uwb.backend.impl.internal.RangingCapabilities
94                                 uwbRangingCapabilities) {
95             mUwbRangingCapabilities = uwbRangingCapabilities;
96             return this;
97         }
98 
99         /** Builds {@link RangingCapabilities}. */
build()100         public RangingCapabilities build() {
101             return new RangingCapabilities(mSupportedRangingMethods, mUwbRangingCapabilities);
102         }
103     }
104 }
105