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