1 /* 2 * Copyright (C) 2022 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.multichip; 18 19 import android.os.PersistableBundle; 20 21 /** 22 * Defines parameters from return value for {@link android.uwb.UwbManager#getChipInfos()}. 23 */ 24 public final class ChipInfoParams { 25 private static final String KEY_CHIP_ID = "KEY_CHIP_ID"; 26 private static final String UNKNOWN_CHIP_ID = "UNKNOWN_CHIP_ID"; 27 28 private static final String KEY_POSITION_X = "KEY_POSITION_X"; 29 private static final String KEY_POSITION_Y = "KEY_POSITION_Y"; 30 private static final String KEY_POSITION_Z = "KEY_POSITION_Z"; 31 32 private final String mChipId; 33 private final double mPositionX; 34 private final double mPositionY; 35 private final double mPositionZ; 36 ChipInfoParams(String chipId, double positionX, double positionY, double positionZ)37 private ChipInfoParams(String chipId, double positionX, double positionY, double positionZ) { 38 mChipId = chipId; 39 mPositionX = positionX; 40 mPositionY = positionY; 41 mPositionZ = positionZ; 42 } 43 44 /** Returns a String identifier of the chip. */ getChipId()45 public String getChipId() { 46 return mChipId; 47 } 48 49 /** Returns the x position of the chip as a double in meters. */ getPositionX()50 public double getPositionX() { 51 return mPositionX; 52 } 53 54 /** Returns the y position of the chip as a double in meters. */ getPositionY()55 public double getPositionY() { 56 return mPositionY; 57 } 58 59 /** Returns the z position of the chip as a double in meters. */ getPositionZ()60 public double getPositionZ() { 61 return mPositionZ; 62 } 63 64 /** Returns a {@link PersistableBundle} representation of the object. */ toBundle()65 public PersistableBundle toBundle() { 66 PersistableBundle bundle = new PersistableBundle(); 67 bundle.putString(KEY_CHIP_ID, mChipId); 68 bundle.putDouble(KEY_POSITION_X, mPositionX); 69 bundle.putDouble(KEY_POSITION_Y, mPositionY); 70 bundle.putDouble(KEY_POSITION_Z, mPositionZ); 71 return bundle; 72 } 73 74 /** Creates a new {@link ChipInfoParams} from a {@link PersistableBundle}. */ fromBundle(PersistableBundle bundle)75 public static ChipInfoParams fromBundle(PersistableBundle bundle) { 76 String chipId = bundle.getString(KEY_CHIP_ID, UNKNOWN_CHIP_ID); 77 double positionX = bundle.getDouble(KEY_POSITION_X, 0.0); 78 double positionY = bundle.getDouble(KEY_POSITION_Y, 0.0); 79 double positionZ = bundle.getDouble(KEY_POSITION_Z, 0.0); 80 return new ChipInfoParams(chipId, positionX, positionY, positionZ); 81 } 82 83 /** Creates and returns a {@link Builder}. */ createBuilder()84 public static Builder createBuilder() { 85 return new Builder(); 86 } 87 88 /** 89 * A Class for building an object representing the return type of 90 * {@link android.uwb.UwbManager#getChipInfos()}. 91 */ 92 public static class Builder { 93 String mChipId = UNKNOWN_CHIP_ID; 94 double mPositionX = 0.0; 95 double mPositionY = 0.0; 96 double mPositionZ = 0.0; 97 98 /** Sets String identifier of chip */ setChipId(String chipId)99 public Builder setChipId(String chipId) { 100 mChipId = chipId; 101 return this; 102 } 103 104 /** Sets the x position of the chip measured in meters. */ setPositionX(double positionX)105 public Builder setPositionX(double positionX) { 106 mPositionX = positionX; 107 return this; 108 } 109 110 /** Sets the y position of the chip measured in meters. */ setPositionY(double positionY)111 public Builder setPositionY(double positionY) { 112 mPositionY = positionY; 113 return this; 114 } 115 116 /** Sets the z position of the chip measured in meters. */ setPositionZ(double positionZ)117 public Builder setPositionZ(double positionZ) { 118 mPositionZ = positionZ; 119 return this; 120 } 121 122 /** 123 * Builds an object representing the return type of 124 * {@link android.uwb.UwbManager#getChipInfos()}. 125 */ build()126 public ChipInfoParams build() { 127 return new ChipInfoParams(mChipId, mPositionX, mPositionY, mPositionZ); 128 } 129 } 130 } 131