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    /**
82     * See state strings defined in ril.h RIL_REQUEST_QUERY_AVAILABLE_NETWORKS
83     */
84    private static State rilStateToState(String s) {
85        if (s.equals("unknown")) {
86            return State.UNKNOWN;
87        } else if (s.equals("available")) {
88            return State.AVAILABLE;
89        } else if (s.equals("current")) {
90            return State.CURRENT;
91        } else if (s.equals("forbidden")) {
92            return State.FORBIDDEN;
93        } else {
94            throw new RuntimeException(
95                "RIL impl error: Invalid network state '" + s + "'");
96        }
97    }
98
99
100    @Override
101    public String toString() {
102        return "OperatorInfo " + mOperatorAlphaLong
103                + "/" + mOperatorAlphaShort
104                + "/" + mOperatorNumeric
105                + "/" + mState;
106    }
107
108    /**
109     * Parcelable interface implemented below.
110     * This is a simple effort to make OperatorInfo parcelable rather than
111     * trying to make the conventional containing object (AsyncResult),
112     * implement parcelable.  This functionality is needed for the
113     * NetworkQueryService to fix 1128695.
114     */
115
116    @Override
117    public int describeContents() {
118        return 0;
119    }
120
121    /**
122     * Implement the Parcelable interface.
123     * Method to serialize a OperatorInfo object.
124     */
125    @Override
126    public void writeToParcel(Parcel dest, int flags) {
127        dest.writeString(mOperatorAlphaLong);
128        dest.writeString(mOperatorAlphaShort);
129        dest.writeString(mOperatorNumeric);
130        dest.writeSerializable(mState);
131    }
132
133    /**
134     * Implement the Parcelable interface
135     * Method to deserialize a OperatorInfo object, or an array thereof.
136     */
137    public static final Creator<OperatorInfo> CREATOR =
138        new Creator<OperatorInfo>() {
139            @Override
140            public OperatorInfo createFromParcel(Parcel in) {
141                OperatorInfo opInfo = new OperatorInfo(
142                        in.readString(), /*operatorAlphaLong*/
143                        in.readString(), /*operatorAlphaShort*/
144                        in.readString(), /*operatorNumeric*/
145                        (State) in.readSerializable()); /*state*/
146                return opInfo;
147            }
148
149            @Override
150            public OperatorInfo[] newArray(int size) {
151                return new OperatorInfo[size];
152            }
153        };
154}
155