1 /*
2  * Copyright (C) 2020 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.IntRange;
20 import android.annotation.NonNull;
21 import android.annotation.Nullable;
22 import android.os.Parcel;
23 import android.os.Parcelable;
24 
25 import java.util.Objects;
26 
27 /**
28  * Information to represent a closed subscriber group.
29  */
30 public final class ClosedSubscriberGroupInfo implements Parcelable {
31     private static final String TAG = "ClosedSubscriberGroupInfo";
32 
33     private final boolean mCsgIndicator;
34 
35     private final String mHomeNodebName;
36 
37     private final int mCsgIdentity;
38 
39     /** @hide */
ClosedSubscriberGroupInfo(boolean csgIndicator, @Nullable String homeNodebName, int csgIdentity)40     public ClosedSubscriberGroupInfo(boolean csgIndicator, @Nullable String homeNodebName,
41             int csgIdentity) {
42         mCsgIndicator = csgIndicator;
43         mHomeNodebName = (homeNodebName == null) ? "" : homeNodebName;
44         mCsgIdentity = csgIdentity;
45     }
46 
47     /**
48      * Indicates whether the cell is restricted to only CSG members.
49      *
50      * A cell not broadcasting the CSG Indication but reporting CSG information is considered a
51      * Hybrid Cell.
52      * Refer to the "csg-Indication" field in 3GPP TS 36.331 section 6.2.2
53      * SystemInformationBlockType1.
54      * Also refer to "CSG Indicator" in 3GPP TS 25.331 section 10.2.48.8.1 and TS 25.304.
55      *
56      * @return true if the cell is restricted to group members only.
57      */
getCsgIndicator()58     public boolean getCsgIndicator() {
59         return mCsgIndicator;
60     }
61 
62     /**
63      * Returns human-readable name of the closed subscriber group operating this cell (Node-B).
64      *
65      * Refer to "hnb-Name" in TS 36.331 section 6.2.2 SystemInformationBlockType9.
66      * Also refer to "HNB Name" in 3GPP TS25.331 section 10.2.48.8.23 and TS 23.003 section 4.8.
67      *
68      * @return the home Node-B name if available.
69      */
getHomeNodebName()70     public @NonNull String getHomeNodebName() {
71         return mHomeNodebName;
72     }
73 
74     /**
75      * The identity of the closed subscriber group that the cell belongs to.
76      *
77      * Refer to "CSG-Identity" in TS 36.336 section 6.3.4.
78      * Also refer to "CSG Identity" in 3GPP TS 25.331 section 10.3.2.8 and TS 23.003 section 4.7.
79      *
80      * @return the unique 27-bit CSG Identity.
81      */
82     @IntRange(from = 0, to = 0x7FFFFFF)
getCsgIdentity()83     public int getCsgIdentity() {
84         return mCsgIdentity;
85     }
86 
87     @Override
hashCode()88     public int hashCode() {
89         return Objects.hash(mCsgIndicator, mHomeNodebName, mCsgIdentity);
90     }
91 
92     @Override
equals(Object other)93     public boolean equals(Object other) {
94         if (!(other instanceof ClosedSubscriberGroupInfo)) {
95             return false;
96         }
97 
98         ClosedSubscriberGroupInfo o = (ClosedSubscriberGroupInfo) other;
99         return mCsgIndicator == o.mCsgIndicator && o.mHomeNodebName.equals(mHomeNodebName)
100                 && mCsgIdentity == o.mCsgIdentity;
101     }
102 
103     @Override
toString()104     public String toString() {
105         return new StringBuilder(TAG + ":{")
106                 .append(" mCsgIndicator = ").append(mCsgIndicator)
107                 .append(" mHomeNodebName = ").append(mHomeNodebName)
108                 .append(" mCsgIdentity = ").append(mCsgIdentity)
109                 .toString();
110     }
111 
112     @Override
writeToParcel(@onNull Parcel dest, int type)113     public void writeToParcel(@NonNull Parcel dest, int type) {
114         dest.writeBoolean(mCsgIndicator);
115         dest.writeString(mHomeNodebName);
116         dest.writeInt(mCsgIdentity);
117     }
118 
119     /** Construct from Parcel, type has already been processed */
ClosedSubscriberGroupInfo(Parcel in)120     private ClosedSubscriberGroupInfo(Parcel in) {
121         this(in.readBoolean(), in.readString(), in.readInt());
122     }
123 
124     /**
125      * Implement the Parcelable interface
126      */
127     @Override
describeContents()128     public int describeContents() {
129         return 0;
130     }
131 
132     /** Implement the Parcelable interface */
133     public static final @android.annotation.NonNull Creator<ClosedSubscriberGroupInfo> CREATOR =
134             new Creator<ClosedSubscriberGroupInfo>() {
135                 @Override
136                 public ClosedSubscriberGroupInfo createFromParcel(Parcel in) {
137                     return createFromParcelBody(in);
138                 }
139 
140                 @Override
141                 public ClosedSubscriberGroupInfo[] newArray(int size) {
142                     return new ClosedSubscriberGroupInfo[size];
143                 }
144             };
145 
146     /** @hide */
createFromParcelBody(Parcel in)147     protected static ClosedSubscriberGroupInfo createFromParcelBody(Parcel in) {
148         return new ClosedSubscriberGroupInfo(in);
149     }
150 }
151