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 com.android.internal.telephony;
18 
19 import android.telephony.Rlog;
20 import java.util.BitSet;
21 import android.telephony.ServiceState;
22 
23 /**
24  * {@hide}
25  *
26  * hardware configuration information reported by the ril layer and for
27  * use by the telephone framework.
28  *
29  * the hardware configuration is managed by the TelephonyDevController
30  * (aka: the 'TDC').
31  *
32  * the hardware resources are:
33  *    - modem: physical entity providing acces technology.
34  *    - sim: physicaly entity providing a slot interface.
35  */
36 public class HardwareConfig {
37     static final String LOG_TAG = "HardwareConfig";
38 
39     /**
40      * hardware configuration kind.
41      */
42     public static final int DEV_HARDWARE_TYPE_MODEM = 0;
43     public static final int DEV_HARDWARE_TYPE_SIM   = 1;
44     /**
45      * ril attachment model.  if single, there is a one-to-one
46      * relationship between a modem hardware and a ril daemon.
47      * if multiple, there is a one-to-many relatioship between a
48      * modem hardware and several ril simultaneous ril daemons.
49      */
50     public static final int DEV_MODEM_RIL_MODEL_SINGLE   = 0;
51     public static final int DEV_MODEM_RIL_MODEL_MULTIPLE = 1;
52     /**
53      * hardware state of the resource.
54      *
55      *   enabled: the resource can be used by the msim-framework,
56      *            call activity can be handled on it.
57      *   standby: the resource can be used by the msim-framework but
58      *            only for non call related activity.  as example:
59      *            reading the address book from a sim device. attempt
60      *            to use this resource for call activity leads to
61      *            undetermined results.
62      *   disabled: the resource  cannot be used and attempt to use
63      *             it leads to undetermined results.
64      *
65      * by default, all resources are 'enabled', what causes a resource
66      * to be marked otherwise is a property of the underlying hardware
67      * knowledge and implementation and it is out of scope of the TDC.
68      */
69     public static final int DEV_HARDWARE_STATE_ENABLED  = 0;
70     public static final int DEV_HARDWARE_STATE_STANDBY  = 1;
71     public static final int DEV_HARDWARE_STATE_DISABLED = 2;
72 
73     /**
74      * common hardware configuration.
75      *
76      * type - see DEV_HARDWARE_TYPE_
77      * uuid - unique identifier for this hardware.
78      * state - see DEV_HARDWARE_STATE_
79      */
80     public int type;
81     public String uuid;
82     public int state;
83     /**
84      * following is some specific hardware configuration based on the hardware type.
85      */
86     /**
87      * DEV_HARDWARE_TYPE_MODEM.
88      *
89      * rilModel - see DEV_MODEM_RIL_MODEL_
90      * rat - BitSet value, based on android.telephony.ServiceState
91      * maxActiveVoiceCall - maximum number of concurent active voice calls.
92      * maxActiveDataCall - maximum number of concurent active data calls.
93      * maxStandby - maximum number of concurent standby connections.
94      *
95      * note: the maxStandby is not necessarily an equal sum of the maxActiveVoiceCall
96      * and maxActiveDataCall (nor a derivative of it) since it really depends on the
97      * modem capability, hence it is left for the hardware to define.
98      */
99     public int rilModel;
100     public BitSet rat;
101     public int maxActiveVoiceCall;
102     public int maxActiveDataCall;
103     public int maxStandby;
104     /**
105      * DEV_HARDWARE_TYPE_SIM.
106      *
107      * modemUuid - unique association to a modem for a sim.
108      */
109     public String modemUuid;
110 
111     /**
112      * default constructor.
113      */
HardwareConfig(int type)114     public HardwareConfig(int type) {
115         type = type;
116     }
117 
118     /**
119      * create from a resource string format.
120      */
HardwareConfig(String res)121     public HardwareConfig(String res) {
122         String split[] = res.split(",");
123 
124         type = Integer.parseInt(split[0]);
125 
126         switch (type) {
127             case DEV_HARDWARE_TYPE_MODEM: {
128                 assignModem(
129                     split[1].trim(),            /* uuid */
130                     Integer.parseInt(split[2]), /* state */
131                     Integer.parseInt(split[3]), /* ril-model */
132                     Integer.parseInt(split[4]), /* rat */
133                     Integer.parseInt(split[5]), /* max-voice */
134                     Integer.parseInt(split[6]), /* max-data */
135                     Integer.parseInt(split[7])  /* max-standby */
136                 );
137                 break;
138             }
139             case DEV_HARDWARE_TYPE_SIM: {
140                 assignSim(
141                     split[1].trim(),            /* uuid */
142                     Integer.parseInt(split[2]), /* state */
143                     split[3].trim()             /* modem-uuid */
144                 );
145                 break;
146             }
147         }
148     }
149 
assignModem(String id, int state, int model, int ratBits, int maxV, int maxD, int maxS)150     public void assignModem(String id, int state, int model, int ratBits,
151         int maxV, int maxD, int maxS) {
152         if (type == DEV_HARDWARE_TYPE_MODEM) {
153             char[] bits = Integer.toBinaryString(ratBits).toCharArray();
154             uuid = id;
155             state = state;
156             rilModel = model;
157             rat = new BitSet(bits.length);
158             for (int i = 0 ; i < bits.length ; i++) {
159                 rat.set(i, (bits[i] == '1' ? true : false));
160             }
161             maxActiveVoiceCall = maxV;
162             maxActiveDataCall = maxD;
163             maxStandby = maxS;
164         }
165     }
166 
assignSim(String id, int state, String link)167     public void assignSim(String id, int state, String link) {
168         if (type == DEV_HARDWARE_TYPE_SIM) {
169             uuid = id;
170             modemUuid = link;
171             state = state;
172         }
173     }
174 
toString()175     public String toString() {
176         StringBuilder builder = new StringBuilder();
177         if (type == DEV_HARDWARE_TYPE_MODEM) {
178             builder.append("Modem ");
179             builder.append("{ uuid=" + uuid);
180             builder.append(", state=" + state);
181             builder.append(", rilModel=" + rilModel);
182             builder.append(", rat=" + rat.toString());
183             builder.append(", maxActiveVoiceCall=" + maxActiveVoiceCall);
184             builder.append(", maxActiveDataCall=" + maxActiveDataCall);
185             builder.append(", maxStandby=" + maxStandby);
186             builder.append(" }");
187         } else if (type == DEV_HARDWARE_TYPE_SIM) {
188             builder.append("Sim ");
189             builder.append("{ uuid=" + uuid);
190             builder.append(", modemUuid=" + modemUuid);
191             builder.append(", state=" + state);
192             builder.append(" }");
193         } else {
194             builder.append("Invalid Configration");
195         }
196         return builder.toString();
197     }
198 
compareTo(HardwareConfig hw)199     public int compareTo(HardwareConfig hw) {
200         String one = this.toString();
201         String two = hw.toString();
202 
203         return (one.compareTo(two));
204     }
205 }
206