1 /*
2  * Copyright (C) 2024 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 com.google.uwb.support.aliro;
18 
19 import android.os.Build.VERSION_CODES;
20 import android.os.PersistableBundle;
21 import android.uwb.RangingSession;
22 
23 import androidx.annotation.RequiresApi;
24 
25 /**
26  * Defines parameters for Aliro reconfigure operation - this started out as identical to {@code
27  * CccRangingReconfiguredParams}.
28  *
29  * <p>This is passed as a bundle to the client callback
30  * {@link RangingSession.Callback#onReconfigured}.
31  */
32 @RequiresApi(VERSION_CODES.LOLLIPOP)
33 public class AliroRangingReconfiguredParams extends AliroParams {
34 
35     private static final int BUNDLE_VERSION_1 = 1;
36     private static final int BUNDLE_VERSION_CURRENT = BUNDLE_VERSION_1;
37 
38     @Override
getBundleVersion()39     protected int getBundleVersion() {
40         return BUNDLE_VERSION_CURRENT;
41     }
42 
fromBundle(PersistableBundle bundle)43     public static AliroRangingReconfiguredParams fromBundle(PersistableBundle bundle) {
44         if (!isCorrectProtocol(bundle)) {
45             throw new IllegalArgumentException("Invalid protocol");
46         }
47 
48         switch (getBundleVersion(bundle)) {
49             case BUNDLE_VERSION_1:
50                 return parseVersion1(bundle);
51 
52             default:
53                 throw new IllegalArgumentException("Invalid bundle version");
54         }
55     }
56 
parseVersion1(PersistableBundle unusedBundle)57     private static AliroRangingReconfiguredParams parseVersion1(PersistableBundle unusedBundle) {
58         // Nothing to parse for now
59         return new AliroRangingReconfiguredParams.Builder().build();
60     }
61 
62     /** Builder */
63     public static class Builder {
build()64         public AliroRangingReconfiguredParams build() {
65             return new AliroRangingReconfiguredParams();
66         }
67     }
68 }
69