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