1 /*
2  * Copyright (C) 2014 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.os.Bundle;
20 import android.os.Parcel;
21 import android.os.Parcelable;
22 import android.telephony.Rlog;
23 
24 /**
25  * Contains LTE network state related information.
26  *
27  * @hide
28  */
29 public final class VoLteServiceState implements Parcelable {
30 
31     private static final String LOG_TAG = "VoLteServiceState";
32     private static final boolean DBG = false;
33 
34     //Use int max, as -1 is a valid value in signal strength
35     public static final int INVALID = 0x7FFFFFFF;
36 
37     public static final int NOT_SUPPORTED = 0;
38     public static final int SUPPORTED = 1;
39 
40     // Single Radio Voice Call Continuity(SRVCC) progress state
41     public static final int HANDOVER_STARTED   = 0;
42     public static final int HANDOVER_COMPLETED = 1;
43     public static final int HANDOVER_FAILED    = 2;
44     public static final int HANDOVER_CANCELED  = 3;
45 
46     private int mSrvccState;
47 
48     /**
49      * Create a new VoLteServiceState from a intent notifier Bundle
50      *
51      * This method is used by PhoneStateIntentReceiver and maybe by
52      * external applications.
53      *
54      * @param m Bundle from intent notifier
55      * @return newly created VoLteServiceState
56      *
57      * @hide
58      */
newFromBundle(Bundle m)59     public static VoLteServiceState newFromBundle(Bundle m) {
60         VoLteServiceState ret;
61         ret = new VoLteServiceState();
62         ret.setFromNotifierBundle(m);
63         return ret;
64     }
65 
66     /**
67      * Empty constructor
68      *
69      * @hide
70      */
VoLteServiceState()71     public VoLteServiceState() {
72         initialize();
73     }
74 
75     /**
76      * Constructor
77      *
78      * @hide
79      */
VoLteServiceState(int srvccState)80     public VoLteServiceState(int srvccState) {
81         initialize();
82 
83         mSrvccState = srvccState;
84     }
85 
86     /**
87      * Copy constructors
88      *
89      * @param s Source VoLteServiceState
90      *
91      * @hide
92      */
VoLteServiceState(VoLteServiceState s)93     public VoLteServiceState(VoLteServiceState s) {
94         copyFrom(s);
95     }
96 
97     /**
98      * Initialize values to defaults.
99      *
100      * @hide
101      */
initialize()102     private void initialize() {
103         mSrvccState = INVALID;
104     }
105 
106     /**
107      * @hide
108      */
copyFrom(VoLteServiceState s)109     protected void copyFrom(VoLteServiceState s) {
110         mSrvccState = s.mSrvccState;
111     }
112 
113     /**
114      * Construct a VoLteServiceState object from the given parcel.
115      *
116      * @hide
117      */
VoLteServiceState(Parcel in)118     public VoLteServiceState(Parcel in) {
119         if (DBG) log("Size of VoLteServiceState parcel:" + in.dataSize());
120 
121         mSrvccState = in.readInt();
122     }
123 
124     /**
125      * {@link Parcelable#writeToParcel}
126      */
writeToParcel(Parcel out, int flags)127     public void writeToParcel(Parcel out, int flags) {
128         out.writeInt(mSrvccState);
129     }
130 
131     /**
132      * {@link Parcelable#describeContents}
133      */
describeContents()134     public int describeContents() {
135         return 0;
136     }
137 
138     /**
139      * {@link Parcelable.Creator}
140      *
141      * @hide
142      */
143     public static final Parcelable.Creator<VoLteServiceState> CREATOR = new Parcelable.Creator() {
144         public VoLteServiceState createFromParcel(Parcel in) {
145             return new VoLteServiceState(in);
146         }
147 
148         public VoLteServiceState[] newArray(int size) {
149             return new VoLteServiceState[size];
150         }
151     };
152 
153     /**
154      * Validate the individual fields as per the range
155      * specified in ril.h
156      * Set to invalid any field that is not in the valid range
157      *
158      * @return
159      *      Valid values for all fields
160      * @hide
161      */
validateInput()162     public void validateInput() {
163     }
164 
hashCode()165     public int hashCode() {
166         int primeNum = 31;
167         return ((mSrvccState * primeNum));
168     }
169 
170     /**
171      * @return true if the LTE network states are the same
172      */
173     @Override
equals(Object o)174     public boolean equals (Object o) {
175         VoLteServiceState s;
176 
177         try {
178             s = (VoLteServiceState) o;
179         } catch (ClassCastException ex) {
180             return false;
181         }
182 
183         if (o == null) {
184             return false;
185         }
186 
187         return (mSrvccState == s.mSrvccState);
188     }
189 
190     /**
191      * @return string representation.
192      */
193     @Override
toString()194     public String toString() {
195         return ("VoLteServiceState:"
196                 + " " + mSrvccState);
197     }
198 
199     /**
200      * Set VoLteServiceState based on intent notifier map
201      *
202      * @param m intent notifier map
203      * @hide
204      */
setFromNotifierBundle(Bundle m)205     private void setFromNotifierBundle(Bundle m) {
206         mSrvccState = m.getInt("mSrvccState");
207     }
208 
209     /**
210      * Set intent notifier Bundle based on VoLteServiceState
211      *
212      * @param m intent notifier Bundle
213      * @hide
214      */
fillInNotifierBundle(Bundle m)215     public void fillInNotifierBundle(Bundle m) {
216         m.putInt("mSrvccState", mSrvccState);
217     }
218 
getSrvccState()219     public int getSrvccState() {
220         return mSrvccState;
221     }
222 
223     /**
224      * log
225      */
log(String s)226     private static void log(String s) {
227         Rlog.w(LOG_TAG, s);
228     }
229 }
230