1 /* 2 * Copyright (C) 2018 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.telephony; 18 19 import android.annotation.NonNull; 20 import android.os.Parcel; 21 22 import dalvik.annotation.codegen.CovariantReturnType; 23 24 import java.util.Objects; 25 26 /** 27 * A {@link CellInfo} representing an 5G NR cell that provides identity and measurement info. 28 */ 29 public final class CellInfoNr extends CellInfo { 30 private static final String TAG = "CellInfoNr"; 31 32 private CellIdentityNr mCellIdentity; 33 private final CellSignalStrengthNr mCellSignalStrength; 34 35 /** @hide */ CellInfoNr()36 public CellInfoNr() { 37 super(); 38 mCellIdentity = new CellIdentityNr(); 39 mCellSignalStrength = new CellSignalStrengthNr(); 40 } 41 CellInfoNr(Parcel in)42 private CellInfoNr(Parcel in) { 43 super(in); 44 mCellIdentity = CellIdentityNr.CREATOR.createFromParcel(in); 45 mCellSignalStrength = CellSignalStrengthNr.CREATOR.createFromParcel(in); 46 } 47 CellInfoNr(CellInfoNr other, boolean sanitizeLocationInfo)48 private CellInfoNr(CellInfoNr other, boolean sanitizeLocationInfo) { 49 super(other); 50 mCellIdentity = sanitizeLocationInfo ? other.mCellIdentity.sanitizeLocationInfo() 51 : other.mCellIdentity; 52 mCellSignalStrength = other.mCellSignalStrength; 53 } 54 55 /** @hide */ CellInfoNr(android.hardware.radio.V1_4.CellInfo ci, long timeStamp)56 public CellInfoNr(android.hardware.radio.V1_4.CellInfo ci, long timeStamp) { 57 super(ci, timeStamp); 58 final android.hardware.radio.V1_4.CellInfoNr cil = ci.info.nr(); 59 mCellIdentity = new CellIdentityNr(cil.cellidentity); 60 mCellSignalStrength = new CellSignalStrengthNr(cil.signalStrength); 61 } 62 63 /** @hide */ CellInfoNr(android.hardware.radio.V1_5.CellInfo ci, long timeStamp)64 public CellInfoNr(android.hardware.radio.V1_5.CellInfo ci, long timeStamp) { 65 super(ci, timeStamp); 66 final android.hardware.radio.V1_5.CellInfoNr cil = ci.ratSpecificInfo.nr(); 67 mCellIdentity = new CellIdentityNr(cil.cellIdentityNr); 68 mCellSignalStrength = new CellSignalStrengthNr(cil.signalStrengthNr); 69 } 70 71 /** @hide */ CellInfoNr(android.hardware.radio.V1_6.CellInfo ci, long timeStamp)72 public CellInfoNr(android.hardware.radio.V1_6.CellInfo ci, long timeStamp) { 73 super(ci, timeStamp); 74 final android.hardware.radio.V1_6.CellInfoNr cil = ci.ratSpecificInfo.nr(); 75 mCellIdentity = new CellIdentityNr(cil.cellIdentityNr); 76 mCellSignalStrength = new CellSignalStrengthNr(cil.signalStrengthNr); 77 } 78 79 /** 80 * @return a {@link CellIdentityNr} instance. 81 */ 82 @CovariantReturnType(returnType = CellIdentityNr.class, presentAfter = 29) 83 @Override 84 @NonNull getCellIdentity()85 public CellIdentity getCellIdentity() { 86 return mCellIdentity; 87 } 88 89 /** @hide */ setCellIdentity(CellIdentityNr cid)90 public void setCellIdentity(CellIdentityNr cid) { 91 mCellIdentity = cid; 92 } 93 94 /** 95 * @return a {@link CellSignalStrengthNr} instance. 96 */ 97 @CovariantReturnType(returnType = CellSignalStrengthNr.class, presentAfter = 29) 98 @Override 99 @NonNull getCellSignalStrength()100 public CellSignalStrength getCellSignalStrength() { 101 return mCellSignalStrength; 102 } 103 104 /** @hide */ 105 @Override sanitizeLocationInfo()106 public CellInfo sanitizeLocationInfo() { 107 return new CellInfoNr(this, true); 108 } 109 110 @Override hashCode()111 public int hashCode() { 112 return Objects.hash(super.hashCode(), mCellIdentity, mCellSignalStrength); 113 } 114 115 @Override equals(Object other)116 public boolean equals(Object other) { 117 if (!(other instanceof CellInfoNr)) { 118 return false; 119 } 120 121 CellInfoNr o = (CellInfoNr) other; 122 return super.equals(o) && mCellIdentity.equals(o.mCellIdentity) 123 && mCellSignalStrength.equals(o.mCellSignalStrength); 124 } 125 126 @Override toString()127 public String toString() { 128 return new StringBuilder() 129 .append(TAG + ":{") 130 .append(" " + super.toString()) 131 .append(" " + mCellIdentity) 132 .append(" " + mCellSignalStrength) 133 .append(" }") 134 .toString(); 135 } 136 137 @Override writeToParcel(Parcel dest, int flags)138 public void writeToParcel(Parcel dest, int flags) { 139 super.writeToParcel(dest, flags, TYPE_NR); 140 mCellIdentity.writeToParcel(dest, flags); 141 mCellSignalStrength.writeToParcel(dest, flags); 142 } 143 144 public static final @android.annotation.NonNull Creator<CellInfoNr> CREATOR = new Creator<CellInfoNr>() { 145 @Override 146 public CellInfoNr createFromParcel(Parcel in) { 147 // Skip the type info. 148 in.readInt(); 149 return new CellInfoNr(in); 150 } 151 152 @Override 153 public CellInfoNr[] newArray(int size) { 154 return new CellInfoNr[size]; 155 } 156 }; 157 158 /** @hide */ createFromParcelBody(Parcel in)159 protected static CellInfoNr createFromParcelBody(Parcel in) { 160 return new CellInfoNr(in); 161 } 162 } 163