Home | History | Annotate | Download | only in telephony
      1 /*
      2  * Copyright 2017 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.Nullable;
     20 import android.os.Parcel;
     21 import android.text.TextUtils;
     22 
     23 import java.util.Objects;
     24 
     25 /**
     26  * CellIdentity is to represent a unique TD-SCDMA cell
     27  */
     28 public final class CellIdentityTdscdma extends CellIdentity {
     29     private static final String TAG = CellIdentityTdscdma.class.getSimpleName();
     30     private static final boolean DBG = false;
     31 
     32     // 16-bit Location Area Code, 0..65535, INT_MAX if unknown.
     33     private final int mLac;
     34     // 28-bit UMTS Cell Identity described in TS 25.331, 0..268435455, INT_MAX if unknown.
     35     private final int mCid;
     36     // 8-bit Cell Parameters ID described in TS 25.331, 0..127, INT_MAX if unknown.
     37     private final int mCpid;
     38 
     39     /**
     40      * @hide
     41      */
     42     public CellIdentityTdscdma() {
     43         super(TAG, TYPE_TDSCDMA, null, null, null, null);
     44         mLac = Integer.MAX_VALUE;
     45         mCid = Integer.MAX_VALUE;
     46         mCpid = Integer.MAX_VALUE;
     47     }
     48 
     49     /**
     50      * @param mcc 3-digit Mobile Country Code, 0..999
     51      * @param mnc 2 or 3-digit Mobile Network Code, 0..999
     52      * @param lac 16-bit Location Area Code, 0..65535, INT_MAX if unknown
     53      * @param cid 28-bit UMTS Cell Identity described in TS 25.331, 0..268435455, INT_MAX if unknown
     54      * @param cpid 8-bit Cell Parameters ID described in TS 25.331, 0..127, INT_MAX if unknown
     55      *
     56      * @hide
     57      */
     58     public CellIdentityTdscdma(int mcc, int mnc, int lac, int cid, int cpid) {
     59         this(String.valueOf(mcc), String.valueOf(mnc), lac, cid, cpid, null, null);
     60     }
     61 
     62     /**
     63      * @param mcc 3-digit Mobile Country Code in string format
     64      * @param mnc 2 or 3-digit Mobile Network Code in string format
     65      * @param lac 16-bit Location Area Code, 0..65535, INT_MAX if unknown
     66      * @param cid 28-bit UMTS Cell Identity described in TS 25.331, 0..268435455, INT_MAX if unknown
     67      * @param cpid 8-bit Cell Parameters ID described in TS 25.331, 0..127, INT_MAX if unknown
     68      *
     69      * FIXME: This is a temporary constructor to facilitate migration.
     70      * @hide
     71      */
     72     public CellIdentityTdscdma(String mcc, String mnc, int lac, int cid, int cpid) {
     73         super(TAG, TYPE_TDSCDMA, mcc, mnc, null, null);
     74         mLac = lac;
     75         mCid = cid;
     76         mCpid = cpid;
     77     }
     78 
     79     /**
     80      * @param mcc 3-digit Mobile Country Code in string format
     81      * @param mnc 2 or 3-digit Mobile Network Code in string format
     82      * @param lac 16-bit Location Area Code, 0..65535, INT_MAX if unknown
     83      * @param cid 28-bit UMTS Cell Identity described in TS 25.331, 0..268435455, INT_MAX if unknown
     84      * @param cpid 8-bit Cell Parameters ID described in TS 25.331, 0..127, INT_MAX if unknown
     85      * @param alphal long alpha Operator Name String or Enhanced Operator Name String
     86      * @param alphas short alpha Operator Name String or Enhanced Operator Name String
     87      *
     88      * @hide
     89      */
     90     public CellIdentityTdscdma(String mcc, String mnc, int lac, int cid, int cpid,
     91             String alphal, String alphas) {
     92         super(TAG, TYPE_TDSCDMA, mcc, mnc, alphal, alphas);
     93         mLac = lac;
     94         mCid = cid;
     95         mCpid = cpid;
     96     }
     97 
     98     private CellIdentityTdscdma(CellIdentityTdscdma cid) {
     99         this(cid.mMccStr, cid.mMncStr, cid.mLac, cid.mCid,
    100                 cid.mCpid, cid.mAlphaLong, cid.mAlphaShort);
    101     }
    102 
    103     CellIdentityTdscdma copy() {
    104         return new CellIdentityTdscdma(this);
    105     }
    106 
    107     /**
    108      * Get Mobile Country Code in string format
    109      * @return Mobile Country Code in string format, null if unknown
    110      */
    111     public String getMccString() {
    112         return mMccStr;
    113     }
    114 
    115     /**
    116      * Get Mobile Network Code in string format
    117      * @return Mobile Network Code in string format, null if unknown
    118      */
    119     public String getMncString() {
    120         return mMncStr;
    121     }
    122 
    123     /**
    124      * @return 16-bit Location Area Code, 0..65535, INT_MAX if unknown
    125      */
    126     public int getLac() {
    127         return mLac;
    128     }
    129 
    130     /**
    131      * @return 28-bit UMTS Cell Identity described in TS 25.331, 0..268435455, INT_MAX if unknown
    132      */
    133     public int getCid() {
    134         return mCid;
    135     }
    136 
    137     /**
    138      * @return 8-bit Cell Parameters ID described in TS 25.331, 0..127, INT_MAX if unknown
    139      */
    140     public int getCpid() {
    141         return mCpid;
    142     }
    143 
    144     @Override
    145     public int hashCode() {
    146         return Objects.hash(mLac, mCid, mCpid, super.hashCode());
    147     }
    148 
    149     @Override
    150     public boolean equals(Object other) {
    151         if (this == other) {
    152             return true;
    153         }
    154 
    155         if (!(other instanceof CellIdentityTdscdma)) {
    156             return false;
    157         }
    158 
    159         CellIdentityTdscdma o = (CellIdentityTdscdma) other;
    160         return TextUtils.equals(mMccStr, o.mMccStr)
    161                 && TextUtils.equals(mMncStr, o.mMncStr)
    162                 && mLac == o.mLac
    163                 && mCid == o.mCid
    164                 && mCpid == o.mCpid
    165                 && super.equals(other);
    166     }
    167 
    168     @Override
    169     public String toString() {
    170         return new StringBuilder(TAG)
    171         .append(":{ mMcc=").append(mMccStr)
    172         .append(" mMnc=").append(mMncStr)
    173         .append(" mLac=").append(mLac)
    174         .append(" mCid=").append(mCid)
    175         .append(" mCpid=").append(mCpid)
    176         .append(" mAlphaLong=").append(mAlphaLong)
    177         .append(" mAlphaShort=").append(mAlphaShort)
    178         .append("}").toString();
    179     }
    180 
    181     /** Implement the Parcelable interface */
    182     @Override
    183     public void writeToParcel(Parcel dest, int flags) {
    184         if (DBG) log("writeToParcel(Parcel, int): " + toString());
    185         super.writeToParcel(dest, TYPE_TDSCDMA);
    186         dest.writeInt(mLac);
    187         dest.writeInt(mCid);
    188         dest.writeInt(mCpid);
    189     }
    190 
    191     /** Construct from Parcel, type has already been processed */
    192     private CellIdentityTdscdma(Parcel in) {
    193         super(TAG, TYPE_TDSCDMA, in);
    194         mLac = in.readInt();
    195         mCid = in.readInt();
    196         mCpid = in.readInt();
    197 
    198         if (DBG) log(toString());
    199     }
    200 
    201     /** Implement the Parcelable interface */
    202     @SuppressWarnings("hiding")
    203     public static final Creator<CellIdentityTdscdma> CREATOR =
    204             new Creator<CellIdentityTdscdma>() {
    205                 @Override
    206                 public CellIdentityTdscdma createFromParcel(Parcel in) {
    207                     in.readInt();   // skip
    208                     return createFromParcelBody(in);
    209                 }
    210 
    211                 @Override
    212                 public CellIdentityTdscdma[] newArray(int size) {
    213                     return new CellIdentityTdscdma[size];
    214                 }
    215             };
    216 
    217     /** @hide */
    218     protected static CellIdentityTdscdma createFromParcelBody(Parcel in) {
    219         return new CellIdentityTdscdma(in);
    220     }
    221 }
    222