summaryrefslogtreecommitdiff
path: root/android/telephony/NetworkRegistrationState.java
blob: 0e2e0cea784a5f1c348e1da115d2a8c63a637421 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
/*
 * Copyright 2017 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.telephony;

import android.annotation.IntDef;
import android.annotation.Nullable;
import android.os.Parcel;
import android.os.Parcelable;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.Arrays;
import java.util.Objects;

/**
 * Description of a mobile network registration state
 * @hide
 */
public class NetworkRegistrationState implements Parcelable {
    /**
     * Network domain
     * @hide
     */
    @Retention(RetentionPolicy.SOURCE)
    @IntDef(prefix = "DOMAIN_", value = {DOMAIN_CS, DOMAIN_PS})
    public @interface Domain {}

    /** Circuit switching domain */
    public static final int DOMAIN_CS = 1;
    /** Packet switching domain */
    public static final int DOMAIN_PS = 2;

    /**
     * Registration state
     * @hide
     */
    @Retention(RetentionPolicy.SOURCE)
    @IntDef(prefix = "REG_STATE_",
            value = {REG_STATE_NOT_REG_NOT_SEARCHING, REG_STATE_HOME, REG_STATE_NOT_REG_SEARCHING,
                    REG_STATE_DENIED, REG_STATE_UNKNOWN, REG_STATE_ROAMING})
    public @interface RegState {}

    /** Not registered. The device is not currently searching a new operator to register */
    public static final int REG_STATE_NOT_REG_NOT_SEARCHING = 0;
    /** Registered on home network */
    public static final int REG_STATE_HOME = 1;
    /** Not registered. The device is currently searching a new operator to register */
    public static final int REG_STATE_NOT_REG_SEARCHING = 2;
    /** Registration denied */
    public static final int REG_STATE_DENIED = 3;
    /** Registration state is unknown */
    public static final int REG_STATE_UNKNOWN = 4;
    /** Registered on roaming network */
    public static final int REG_STATE_ROAMING = 5;

    /**
     * Supported service type
     * @hide
     */
    @Retention(RetentionPolicy.SOURCE)
    @IntDef(prefix = "SERVICE_TYPE_",
            value = {SERVICE_TYPE_VOICE, SERVICE_TYPE_DATA, SERVICE_TYPE_SMS, SERVICE_TYPE_VIDEO,
                    SERVICE_TYPE_EMERGENCY})
    public @interface ServiceType {}

    public static final int SERVICE_TYPE_VOICE = 1;
    public static final int SERVICE_TYPE_DATA = 2;
    public static final int SERVICE_TYPE_SMS = 3;
    public static final int SERVICE_TYPE_VIDEO = 4;
    public static final int SERVICE_TYPE_EMERGENCY = 5;

    /** {@link AccessNetworkConstants.TransportType}*/
    private final int mTransportType;

    @Domain
    private final int mDomain;

    @RegState
    private final int mRegState;

    private final int mAccessNetworkTechnology;

    private final int mReasonForDenial;

    private final boolean mEmergencyOnly;

    private final int[] mAvailableServices;

    @Nullable
    private final CellIdentity mCellIdentity;

    @Nullable
    private VoiceSpecificRegistrationStates mVoiceSpecificStates;

    @Nullable
    private DataSpecificRegistrationStates mDataSpecificStates;

    /**
     * @param transportType Transport type. Must be {@link AccessNetworkConstants.TransportType}
     * @param domain Network domain. Must be DOMAIN_CS or DOMAIN_PS.
     * @param regState Network registration state.
     * @param accessNetworkTechnology See TelephonyManager NETWORK_TYPE_XXXX.
     * @param reasonForDenial Reason for denial if the registration state is DENIED.
     * @param availableServices The supported service.
     * @param cellIdentity The identity representing a unique cell
     */
    public NetworkRegistrationState(int transportType, int domain, int regState,
            int accessNetworkTechnology, int reasonForDenial, boolean emergencyOnly,
            int[] availableServices, @Nullable CellIdentity cellIdentity) {
        mTransportType = transportType;
        mDomain = domain;
        mRegState = regState;
        mAccessNetworkTechnology = accessNetworkTechnology;
        mReasonForDenial = reasonForDenial;
        mAvailableServices = availableServices;
        mCellIdentity = cellIdentity;
        mEmergencyOnly = emergencyOnly;
    }

    /**
     * Constructor for voice network registration states.
     * @hide
     */
    public NetworkRegistrationState(int transportType, int domain, int regState,
            int accessNetworkTechnology, int reasonForDenial, boolean emergencyOnly,
            int[] availableServices, @Nullable CellIdentity cellIdentity, boolean cssSupported,
            int roamingIndicator, int systemIsInPrl, int defaultRoamingIndicator) {
        this(transportType, domain, regState, accessNetworkTechnology,
                reasonForDenial, emergencyOnly, availableServices, cellIdentity);

        mVoiceSpecificStates = new VoiceSpecificRegistrationStates(cssSupported, roamingIndicator,
                systemIsInPrl, defaultRoamingIndicator);
    }

    /**
     * Constructor for data network registration states.
     * @hide
     */
    public NetworkRegistrationState(int transportType, int domain, int regState,
            int accessNetworkTechnology, int reasonForDenial, boolean emergencyOnly,
            int[] availableServices, @Nullable CellIdentity cellIdentity, int maxDataCalls) {
        this(transportType, domain, regState, accessNetworkTechnology,
                reasonForDenial, emergencyOnly, availableServices, cellIdentity);

        mDataSpecificStates = new DataSpecificRegistrationStates(maxDataCalls);
    }

    protected NetworkRegistrationState(Parcel source) {
        mTransportType = source.readInt();
        mDomain = source.readInt();
        mRegState = source.readInt();
        mAccessNetworkTechnology = source.readInt();
        mReasonForDenial = source.readInt();
        mEmergencyOnly = source.readBoolean();
        mAvailableServices = source.createIntArray();
        mCellIdentity = source.readParcelable(CellIdentity.class.getClassLoader());
        mVoiceSpecificStates = source.readParcelable(
                VoiceSpecificRegistrationStates.class.getClassLoader());
        mDataSpecificStates = source.readParcelable(
                DataSpecificRegistrationStates.class.getClassLoader());
    }

    /**
     * @return The transport type.
     */
    public int getTransportType() { return mTransportType; }

    /**
     * @return The network domain.
     */
    public @Domain int getDomain() { return mDomain; }

    /**
     * @return The registration state.
     */
    public @RegState int getRegState() {
        return mRegState;
    }

    /**
     * @return Whether emergency is enabled.
     */
    public boolean isEmergencyEnabled() { return mEmergencyOnly; }

    /**
     * @return List of available service types.
     */
    public int[] getAvailableServices() { return mAvailableServices; }

    /**
     * @return The access network technology. Must be one of TelephonyManager.NETWORK_TYPE_XXXX.
     */
    public int getAccessNetworkTechnology() {
        return mAccessNetworkTechnology;
    }

    /**
     * @return Reason for denial from network.
     */
    public int getReasonForDenial() {
        return mReasonForDenial;
    }

    /**
     * @return The cell information.
     */
    public CellIdentity getCellIdentity() {
        return mCellIdentity;
    }

    /**
     * @hide
     */
    @Nullable
    public VoiceSpecificRegistrationStates getVoiceSpecificStates() {
        return mVoiceSpecificStates;
    }

    /**
     * @hide
     */
    @Nullable
    public DataSpecificRegistrationStates getDataSpecificStates() {
        return mDataSpecificStates;
    }

    @Override
    public int describeContents() {
        return 0;
    }

    private static String regStateToString(int regState) {
        switch (regState) {
            case REG_STATE_NOT_REG_NOT_SEARCHING: return "NOT_REG_NOT_SEARCHING";
            case REG_STATE_HOME: return "HOME";
            case REG_STATE_NOT_REG_SEARCHING: return "NOT_REG_SEARCHING";
            case REG_STATE_DENIED: return "DENIED";
            case REG_STATE_UNKNOWN: return "UNKNOWN";
            case REG_STATE_ROAMING: return "ROAMING";
        }
        return "Unknown reg state " + regState;
    }

    @Override
    public String toString() {
        return new StringBuilder("NetworkRegistrationState{")
                .append("transportType=").append(mTransportType)
                .append(" domain=").append((mDomain == DOMAIN_CS) ? "CS" : "PS")
                .append(" regState=").append(regStateToString(mRegState))
                .append(" accessNetworkTechnology=")
                .append(TelephonyManager.getNetworkTypeName(mAccessNetworkTechnology))
                .append(" reasonForDenial=").append(mReasonForDenial)
                .append(" emergencyEnabled=").append(mEmergencyOnly)
                .append(" supportedServices=").append(mAvailableServices)
                .append(" cellIdentity=").append(mCellIdentity)
                .append(" voiceSpecificStates=").append(mVoiceSpecificStates)
                .append(" dataSpecificStates=").append(mDataSpecificStates)
                .append("}").toString();
    }

    @Override
    public int hashCode() {
        return Objects.hash(mTransportType, mDomain, mRegState, mAccessNetworkTechnology,
                mReasonForDenial, mEmergencyOnly, mAvailableServices, mCellIdentity,
                mVoiceSpecificStates, mDataSpecificStates);
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;

        if (o == null || !(o instanceof NetworkRegistrationState)) {
            return false;
        }

        NetworkRegistrationState other = (NetworkRegistrationState) o;
        return mTransportType == other.mTransportType
                && mDomain == other.mDomain
                && mRegState == other.mRegState
                && mAccessNetworkTechnology == other.mAccessNetworkTechnology
                && mReasonForDenial == other.mReasonForDenial
                && mEmergencyOnly == other.mEmergencyOnly
                && (mAvailableServices == other.mAvailableServices
                    || Arrays.equals(mAvailableServices, other.mAvailableServices))
                && equals(mCellIdentity, other.mCellIdentity)
                && equals(mVoiceSpecificStates, other.mVoiceSpecificStates)
                && equals(mDataSpecificStates, other.mDataSpecificStates);
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(mTransportType);
        dest.writeInt(mDomain);
        dest.writeInt(mRegState);
        dest.writeInt(mAccessNetworkTechnology);
        dest.writeInt(mReasonForDenial);
        dest.writeBoolean(mEmergencyOnly);
        dest.writeIntArray(mAvailableServices);
        dest.writeParcelable(mCellIdentity, 0);
        dest.writeParcelable(mVoiceSpecificStates, 0);
        dest.writeParcelable(mDataSpecificStates, 0);
    }

    public static final Parcelable.Creator<NetworkRegistrationState> CREATOR =
            new Parcelable.Creator<NetworkRegistrationState>() {
        @Override
        public NetworkRegistrationState createFromParcel(Parcel source) {
            return new NetworkRegistrationState(source);
        }

        @Override
        public NetworkRegistrationState[] newArray(int size) {
            return new NetworkRegistrationState[size];
        }
    };

    private static boolean equals(Object o1, Object o2) {
        if (o1 == o2) {
            return true;
        } else if (o1 == null) {
            return false;
        } else {
            return o1.equals(o2);
        }
    }
}