1 /* 2 * Copyright 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.android.ranging.rtt.backend.internal; 18 19 import android.net.MacAddress; 20 import android.net.wifi.aware.PeerHandle; 21 import android.net.wifi.rtt.RangingResult; 22 import android.net.wifi.rtt.ResponderLocation; 23 import android.os.Build; 24 import android.util.Log; 25 26 import androidx.annotation.NonNull; 27 28 /** 29 * This class is transform class of RangingResult to fit with RttAdapter. 30 */ 31 public class RttRangingPosition { 32 private static final String TAG = RttRangingPosition.class.getName(); 33 34 private int mDistanceMm; 35 private int mDistanceStdDevMm; 36 private byte[] mLci; 37 private byte[] mLcr; 38 private MacAddress mMacAddress; 39 // private long mMaxTimeBetweenNtbMeasurementsMicros; 40 private int mMeasurementBandwidth; 41 private int mMeasurementChannelFrequencyMHz; 42 // private long mMinTimeBetweenNtbMeasurementsMicros; 43 private int mNumAttemptedMeasurements; 44 private int mNumSuccessfulMeasurements; 45 private PeerHandle mPeerHandle; 46 private long mRangingTimestampMillis; 47 private int mRssi; 48 private int mStatus; 49 private ResponderLocation mUnverifiedResponderLocation; 50 boolean mIs80211azNtbMeasurement; 51 boolean mIs80211mcMeasurement; 52 53 Azimuth mAzimuth; 54 Elevation mElevation; 55 56 57 /** 58 * Create empty Ranging Position for RTT. 59 */ RttRangingPosition()60 public RttRangingPosition() { 61 mDistanceMm = 0; 62 mDistanceStdDevMm = 0; 63 mLci = null; 64 mLcr = null; 65 mMacAddress = null; 66 mMeasurementBandwidth = 0; 67 mMeasurementChannelFrequencyMHz = 0; 68 mNumAttemptedMeasurements = 0; 69 mNumSuccessfulMeasurements = 0; 70 mPeerHandle = null; 71 mAzimuth = null; 72 mElevation = null; 73 mRangingTimestampMillis = System.currentTimeMillis(); 74 } 75 76 /** 77 * Create Ranging Position for RTT from RangingResult 78 */ RttRangingPosition(@onNull RangingResult rangingResult)79 public RttRangingPosition(@NonNull RangingResult rangingResult) { 80 mDistanceMm = rangingResult.getDistanceMm(); 81 mDistanceStdDevMm = rangingResult.getDistanceStdDevMm(); 82 mLci = rangingResult.getLci(); 83 mLcr = rangingResult.getLcr(); 84 mMacAddress = rangingResult.getMacAddress(); 85 // mMaxTimeBetweenNtbMeasurementsMicros = rangingResult 86 // .getMaxTimeBetweenNtbMeasurementsMicros(); 87 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) { 88 mMeasurementBandwidth = rangingResult.getMeasurementBandwidth(); 89 mMeasurementChannelFrequencyMHz = rangingResult.getMeasurementChannelFrequencyMHz(); 90 } 91 // mMinTimeBetweenNtbMeasurementsMicros = rangingResult 92 // .getMinTimeBetweenNtbMeasurementsMicros(); 93 mNumAttemptedMeasurements = rangingResult.getNumAttemptedMeasurements(); 94 mNumSuccessfulMeasurements = rangingResult.getNumSuccessfulMeasurements(); 95 mPeerHandle = rangingResult.getPeerHandle(); 96 mAzimuth = null; 97 mElevation = null; 98 mRangingTimestampMillis = rangingResult.getRangingTimestampMillis(); 99 100 } 101 102 /** 103 * get Distamce(Unit : mm) 104 */ getDistance()105 public double getDistance() { 106 return mDistanceMm; 107 } 108 109 /** 110 * get Rssi Dbm 111 */ getRssiDbm()112 public int getRssiDbm() { 113 return mRssi; 114 } 115 116 /** 117 * get Ranging Time stamp(Unit : ms) 118 */ getRangingTimestampMillis()119 public long getRangingTimestampMillis() { 120 return mRangingTimestampMillis; 121 } 122 123 // WiFi RTT doesn't support Azimuth yet. 124 125 /** 126 * get Azumith(Not supported yet) 127 */ getAzimuth()128 public Azimuth getAzimuth() { 129 Log.w(TAG, "Azimuth feature is not yet supported in WiFi RTT"); 130 return mAzimuth; 131 } 132 133 // WiFi RTT doesn't support Elevation yet. 134 135 /** 136 * get Elevation(Not supported yet) 137 */ getElevation()138 public Elevation getElevation() { 139 Log.w(TAG, "Elevation feature is not yet supported in WiFi RTT"); 140 return mElevation; 141 } 142 143 /** 144 * Azimuth data(Not supported yet) 145 */ 146 public static class Azimuth { getValue()147 public int getValue() { 148 return 0; 149 } 150 } 151 152 /** 153 * Elevation data(Not supported yet) 154 */ 155 public static class Elevation { getValue()156 public int getValue() { 157 return 0; 158 } 159 } 160 } 161