Rahul Ravikumar | 0533600 | 2019-10-14 15:04:32 -0700 | [diff] [blame] | 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 java.util.Objects; |
| 23 | |
| 24 | /** |
| 25 | * A {@link CellInfo} representing an 5G NR cell that provides identity and measurement info. |
| 26 | */ |
| 27 | public final class CellInfoNr extends CellInfo { |
| 28 | private static final String TAG = "CellInfoNr"; |
| 29 | |
| 30 | private final CellIdentityNr mCellIdentity; |
| 31 | private final CellSignalStrengthNr mCellSignalStrength; |
| 32 | |
| 33 | private CellInfoNr(Parcel in) { |
| 34 | super(in); |
| 35 | mCellIdentity = CellIdentityNr.CREATOR.createFromParcel(in); |
| 36 | mCellSignalStrength = CellSignalStrengthNr.CREATOR.createFromParcel(in); |
| 37 | } |
| 38 | |
| 39 | private CellInfoNr(CellInfoNr other, boolean sanitizeLocationInfo) { |
| 40 | super(other); |
| 41 | mCellIdentity = sanitizeLocationInfo ? other.mCellIdentity.sanitizeLocationInfo() |
| 42 | : other.mCellIdentity; |
| 43 | mCellSignalStrength = other.mCellSignalStrength; |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * @return a {@link CellIdentityNr} instance. |
| 48 | */ |
| 49 | @Override |
| 50 | @NonNull |
| 51 | public CellIdentity getCellIdentity() { |
| 52 | return mCellIdentity; |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * @return a {@link CellSignalStrengthNr} instance. |
| 57 | */ |
| 58 | @Override |
| 59 | @NonNull |
| 60 | public CellSignalStrength getCellSignalStrength() { |
| 61 | return mCellSignalStrength; |
| 62 | } |
| 63 | |
| 64 | /** @hide */ |
| 65 | @Override |
| 66 | public CellInfo sanitizeLocationInfo() { |
| 67 | return new CellInfoNr(this, true); |
| 68 | } |
| 69 | |
| 70 | @Override |
| 71 | public int hashCode() { |
| 72 | return Objects.hash(super.hashCode(), mCellIdentity, mCellSignalStrength); |
| 73 | } |
| 74 | |
| 75 | @Override |
| 76 | public boolean equals(Object other) { |
| 77 | if (!(other instanceof CellInfoNr)) { |
| 78 | return false; |
| 79 | } |
| 80 | |
| 81 | CellInfoNr o = (CellInfoNr) other; |
| 82 | return super.equals(o) && mCellIdentity.equals(o.mCellIdentity) |
| 83 | && mCellSignalStrength.equals(o.mCellSignalStrength); |
| 84 | } |
| 85 | |
| 86 | @Override |
| 87 | public String toString() { |
| 88 | return new StringBuilder() |
| 89 | .append(TAG + ":{") |
| 90 | .append(" " + super.toString()) |
| 91 | .append(" " + mCellIdentity) |
| 92 | .append(" " + mCellSignalStrength) |
| 93 | .append(" }") |
| 94 | .toString(); |
| 95 | } |
| 96 | |
| 97 | @Override |
| 98 | public void writeToParcel(Parcel dest, int flags) { |
| 99 | super.writeToParcel(dest, flags, TYPE_NR); |
| 100 | mCellIdentity.writeToParcel(dest, flags); |
| 101 | mCellSignalStrength.writeToParcel(dest, flags); |
| 102 | } |
| 103 | |
| 104 | public static final @android.annotation.NonNull Creator<CellInfoNr> CREATOR = new Creator<CellInfoNr>() { |
| 105 | @Override |
| 106 | public CellInfoNr createFromParcel(Parcel in) { |
| 107 | // Skip the type info. |
| 108 | in.readInt(); |
| 109 | return new CellInfoNr(in); |
| 110 | } |
| 111 | |
| 112 | @Override |
| 113 | public CellInfoNr[] newArray(int size) { |
| 114 | return new CellInfoNr[size]; |
| 115 | } |
| 116 | }; |
| 117 | |
| 118 | /** @hide */ |
| 119 | protected static CellInfoNr createFromParcelBody(Parcel in) { |
| 120 | return new CellInfoNr(in); |
| 121 | } |
| 122 | } |