CellSignalStrength.java revision 82e6ee62b2be3c716c215e4ba72c8a12c58620fb
1/*
2 * Copyright (C) 2012 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 android.telephony;
18
19import android.os.Parcel;
20import android.os.Parcelable;
21
22/**
23 * Abstract base class for cell phone signal strength related information.
24 */
25public abstract class CellSignalStrength implements Parcelable {
26
27    // Type fields for parceling
28    /** @hide */
29    protected static final int TYPE_GSM = 1;
30    /** @hide */
31    protected static final int TYPE_CDMA = 2;
32    /** @hide */
33    protected static final int TYPE_LTE = 3;
34
35
36    /** @hide */
37    public static final int SIGNAL_STRENGTH_NONE_OR_UNKNOWN = 0;
38    /** @hide */
39    public static final int SIGNAL_STRENGTH_POOR = 1;
40    /** @hide */
41    public static final int SIGNAL_STRENGTH_MODERATE = 2;
42    /** @hide */
43    public static final int SIGNAL_STRENGTH_GOOD = 3;
44    /** @hide */
45    public static final int SIGNAL_STRENGTH_GREAT = 4;
46    /** @hide */
47    public static final int NUM_SIGNAL_STRENGTH_BINS = 5;
48    /** @hide */
49    public static final String[] SIGNAL_STRENGTH_NAMES = {
50        "none", "poor", "moderate", "good", "great"
51    };
52
53    /** @hide */
54    protected CellSignalStrength() {
55    }
56
57    /** @hide */
58    public abstract void setDefaultValues();
59
60    /**
61     * Get signal level as an int from 0..4
62     */
63    public abstract int getLevel();
64
65    /**
66     * Get the signal level as an asu value between 0..31, 99 is unknown
67     */
68    public abstract int getAsuLevel();
69
70    /**
71     * Get the signal strength as dBm
72     */
73    public abstract int getDbm();
74
75    /**
76     * Copies the CellSignalStrength.
77     *
78     * @return A deep copy of this class.
79     * @hide
80     */
81    public abstract CellSignalStrength copy();
82
83    @Override
84    public abstract int hashCode();
85
86    @Override
87    public abstract boolean equals (Object o);
88
89    /** Implement the Parcelable interface */
90    @Override
91    public int describeContents() {
92        return 0;
93    }
94
95    /** Implement the Parcelable interface */
96    @Override
97    public abstract void writeToParcel(Parcel dest, int flags);
98
99    /** Implement the Parcelable interface */
100    public static final Creator<CellSignalStrength> CREATOR =
101            new Creator<CellSignalStrength>() {
102        @Override
103        public CellSignalStrength createFromParcel(Parcel in) {
104            int type = in.readInt();
105            switch (type) {
106                case TYPE_GSM: return CellSignalStrengthGsm.createFromParcelBody(in);
107                case TYPE_CDMA: return CellSignalStrengthCdma.createFromParcelBody(in);
108                case TYPE_LTE: return CellSignalStrengthLte.createFromParcelBody(in);
109                default: throw new RuntimeException("Bad CellSignalStrength Parcel");
110            }
111        }
112
113        @Override
114        public CellSignalStrength[] newArray(int size) {
115            return new CellSignalStrength[size];
116        }
117    };
118}
119