OperatorInfo.java revision d4f2bcdab5a43e6439babfd5eefeaff908b73870
1/*
2 * Copyright (C) 2006 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
17package com.android.internal.telephony;
18
19import android.os.Parcel;
20import android.os.Parcelable;
21
22/**
23 * {@hide}
24 */
25public class OperatorInfo implements Parcelable {
26    public enum State {
27        UNKNOWN,
28        AVAILABLE,
29        CURRENT,
30        FORBIDDEN;
31    }
32
33    private String mOperatorAlphaLong;
34    private String mOperatorAlphaShort;
35    private String mOperatorNumeric;
36
37    private State mState = State.UNKNOWN;
38
39
40    public String
41    getOperatorAlphaLong() {
42        return mOperatorAlphaLong;
43    }
44
45    public String
46    getOperatorAlphaShort() {
47        return mOperatorAlphaShort;
48    }
49
50    public String
51    getOperatorNumeric() {
52        return mOperatorNumeric;
53    }
54
55    public State
56    getState() {
57        return mState;
58    }
59
60    OperatorInfo(String operatorAlphaLong,
61                String operatorAlphaShort,
62                String operatorNumeric,
63                State state) {
64
65        mOperatorAlphaLong = operatorAlphaLong;
66        mOperatorAlphaShort = operatorAlphaShort;
67        mOperatorNumeric = operatorNumeric;
68
69        mState = state;
70    }
71
72
73    public OperatorInfo(String operatorAlphaLong,
74                String operatorAlphaShort,
75                String operatorNumeric,
76                String stateString) {
77        this (operatorAlphaLong, operatorAlphaShort,
78                operatorNumeric, rilStateToState(stateString));
79    }
80
81    public OperatorInfo(String operatorAlphaLong,
82            String operatorAlphaShort,
83            String operatorNumeric) {
84        this(operatorAlphaLong, operatorAlphaShort, operatorNumeric, State.UNKNOWN);
85    }
86
87    /**
88     * See state strings defined in ril.h RIL_REQUEST_QUERY_AVAILABLE_NETWORKS
89     */
90    private static State rilStateToState(String s) {
91        if (s.equals("unknown")) {
92            return State.UNKNOWN;
93        } else if (s.equals("available")) {
94            return State.AVAILABLE;
95        } else if (s.equals("current")) {
96            return State.CURRENT;
97        } else if (s.equals("forbidden")) {
98            return State.FORBIDDEN;
99        } else {
100            throw new RuntimeException(
101                "RIL impl error: Invalid network state '" + s + "'");
102        }
103    }
104
105
106    @Override
107    public String toString() {
108        return "OperatorInfo " + mOperatorAlphaLong
109                + "/" + mOperatorAlphaShort
110                + "/" + mOperatorNumeric
111                + "/" + mState;
112    }
113
114    /**
115     * Parcelable interface implemented below.
116     * This is a simple effort to make OperatorInfo parcelable rather than
117     * trying to make the conventional containing object (AsyncResult),
118     * implement parcelable.  This functionality is needed for the
119     * NetworkQueryService to fix 1128695.
120     */
121
122    @Override
123    public int describeContents() {
124        return 0;
125    }
126
127    /**
128     * Implement the Parcelable interface.
129     * Method to serialize a OperatorInfo object.
130     */
131    @Override
132    public void writeToParcel(Parcel dest, int flags) {
133        dest.writeString(mOperatorAlphaLong);
134        dest.writeString(mOperatorAlphaShort);
135        dest.writeString(mOperatorNumeric);
136        dest.writeSerializable(mState);
137    }
138
139    /**
140     * Implement the Parcelable interface
141     * Method to deserialize a OperatorInfo object, or an array thereof.
142     */
143    public static final Creator<OperatorInfo> CREATOR =
144        new Creator<OperatorInfo>() {
145            @Override
146            public OperatorInfo createFromParcel(Parcel in) {
147                OperatorInfo opInfo = new OperatorInfo(
148                        in.readString(), /*operatorAlphaLong*/
149                        in.readString(), /*operatorAlphaShort*/
150                        in.readString(), /*operatorNumeric*/
151                        (State) in.readSerializable()); /*state*/
152                return opInfo;
153            }
154
155            @Override
156            public OperatorInfo[] newArray(int size) {
157                return new OperatorInfo[size];
158            }
159        };
160}
161