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.mocks; 18 19import static android.telephony.SubscriptionManager.INVALID_PHONE_INDEX; 20import static android.telephony.SubscriptionManager.INVALID_SUBSCRIPTION_ID; 21import static android.telephony.SubscriptionManager.DEFAULT_SUBSCRIPTION_ID; 22 23import android.content.Context; 24import android.content.Intent; 25import android.os.UserHandle; 26import android.os.RemoteException; 27import android.telephony.SubscriptionInfo; 28import android.telephony.SubscriptionManager; 29 30import com.android.internal.telephony.CommandsInterface; 31import com.android.internal.telephony.ISub; 32import com.android.internal.telephony.ITelephonyRegistry; 33import com.android.internal.telephony.Phone; 34import com.android.internal.telephony.PhoneConstants; 35import com.android.internal.telephony.SubscriptionController; 36import com.android.internal.telephony.TelephonyIntents; 37 38import java.io.FileDescriptor; 39import java.io.PrintWriter; 40import java.util.concurrent.atomic.AtomicInteger; 41import java.util.List; 42 43// must extend SubscriptionController as some people use it directly within-process 44public class SubscriptionControllerMock extends SubscriptionController { 45 final AtomicInteger mDefaultDataSubId = new AtomicInteger(INVALID_SUBSCRIPTION_ID); 46 final ITelephonyRegistry.Stub mTelephonyRegistry; 47 final int[][] mSlotIndexToSubId; 48 49 public static SubscriptionController init(Phone phone) { 50 throw new RuntimeException("not implemented"); 51 } 52 public static SubscriptionController init(Context c, CommandsInterface[] ci) { 53 throw new RuntimeException("not implemented"); 54 } 55 public static SubscriptionController getInstance() { 56 throw new RuntimeException("not implemented"); 57 } 58 59 public SubscriptionControllerMock(Context c, ITelephonyRegistry.Stub tr, int phoneCount) { 60 super(c); 61 mTelephonyRegistry = tr; 62 mSlotIndexToSubId = new int[phoneCount][]; 63 for (int i = 0; i < phoneCount; i++) { 64 mSlotIndexToSubId[i] = new int[1]; 65 mSlotIndexToSubId[i][0] = INVALID_SUBSCRIPTION_ID; 66 } 67 } 68 69 protected void init(Context c) { 70 mContext = c; 71 } 72 73 @Override 74 public int getDefaultDataSubId() { 75 return mDefaultDataSubId.get(); 76 } 77 78 @Override 79 public void setDefaultDataSubId(int subId) { 80 if (subId == DEFAULT_SUBSCRIPTION_ID) { 81 throw new RuntimeException("setDefaultDataSubId called with DEFAULT_SUB_ID"); 82 } 83 84 mDefaultDataSubId.set(subId); 85 broadcastDefaultDataSubIdChanged(subId); 86 } 87 88 private void broadcastDefaultDataSubIdChanged(int subId) { 89 // Broadcast an Intent for default data sub change 90 Intent intent = new Intent(TelephonyIntents.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED); 91 intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING); 92 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId); 93 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL); 94 } 95 96 @Override 97 public int getSubIdUsingPhoneId(int phoneId) { 98 int[] subIds = getSubId(phoneId); 99 if (subIds == null || subIds.length == 0) { 100 return INVALID_SUBSCRIPTION_ID; 101 } 102 return subIds[0]; 103 } 104 105 @Override 106 public void notifySubscriptionInfoChanged() { 107 try { 108 mTelephonyRegistry.notifySubscriptionInfoChanged(); 109 } catch (RemoteException ex) {} 110 } 111 @Override 112 public SubscriptionInfo getActiveSubscriptionInfo(int subId, String callingPackage) { 113 throw new RuntimeException("not implemented"); 114 } 115 @Override 116 public SubscriptionInfo getActiveSubscriptionInfoForIccId(String iccId, String callingPackage) { 117 throw new RuntimeException("not implemented"); 118 } 119 @Override 120 public SubscriptionInfo getActiveSubscriptionInfoForSimSlotIndex(int slotIndex, String cp){ 121 throw new RuntimeException("not implemented"); 122 } 123 @Override 124 public List<SubscriptionInfo> getAllSubInfoList(String callingPackage) { 125 throw new RuntimeException("not implemented"); 126 } 127 @Override 128 public List<SubscriptionInfo> getActiveSubscriptionInfoList(String callingPackage) { 129 throw new RuntimeException("not implemented"); 130 } 131 @Override 132 public int getActiveSubInfoCount(String callingPackage) { 133 throw new RuntimeException("not implemented"); 134 } 135 @Override 136 public int getAllSubInfoCount(String callingPackage) { 137 throw new RuntimeException("not implemented"); 138 } 139 @Override 140 public int getActiveSubInfoCountMax() { 141 throw new RuntimeException("not implemented"); 142 } 143 @Override 144 public int addSubInfoRecord(String iccId, int slotIndex) { 145 throw new RuntimeException("not implemented"); 146 } 147 @Override 148 public boolean setPlmnSpn(int slotIndex, boolean showPlmn, String plmn, boolean showSpn, 149 String spn) { 150 throw new RuntimeException("not implemented"); 151 } 152 @Override 153 public int setIconTint(int tint, int subId) { 154 throw new RuntimeException("not implemented"); 155 } 156 @Override 157 public int setDisplayName(String displayName, int subId) { 158 throw new RuntimeException("not implemented"); 159 } 160 @Override 161 public int setDisplayNameUsingSrc(String displayName, int subId, long nameSource) { 162 throw new RuntimeException("not implemented"); 163 } 164 @Override 165 public int setDisplayNumber(String number, int subId) { 166 throw new RuntimeException("not implemented"); 167 } 168 @Override 169 public int setDataRoaming(int roaming, int subId) { 170 throw new RuntimeException("not implemented"); 171 } 172 @Override 173 public int setMccMnc(String mccMnc, int subId) { 174 throw new RuntimeException("not implemented"); 175 } 176 @Override 177 public int getSlotIndex(int subId) { 178 throw new RuntimeException("not implemented"); 179 } 180 181 private boolean isInvalidslotIndex(int slotIndex) { 182 if (slotIndex < 0 || slotIndex >= mSlotIndexToSubId.length) return true; 183 return false; 184 } 185 186 @Override 187 public int[] getSubId(int slotIndex) { 188 if (isInvalidslotIndex(slotIndex)) { 189 return null; 190 } 191 return mSlotIndexToSubId[slotIndex]; 192 } 193 public void setSlotSubId(int slotIndex, int subId) { 194 if (isInvalidslotIndex(slotIndex)) { 195 throw new RuntimeException("invalid slot specified" + slotIndex); 196 } 197 if (mSlotIndexToSubId[slotIndex][0] != subId) { 198 mSlotIndexToSubId[slotIndex][0] = subId; 199 try { 200 mTelephonyRegistry.notifySubscriptionInfoChanged(); 201 } catch (RemoteException ex) {} 202 } 203 } 204 @Override 205 public int getPhoneId(int subId) { 206 if (subId == DEFAULT_SUBSCRIPTION_ID) { 207 subId = getDefaultSubId(); 208 } 209 210 if (subId <= INVALID_SUBSCRIPTION_ID) return INVALID_PHONE_INDEX; 211 212 for (int i = 0; i < mSlotIndexToSubId.length; i++) { 213 if (mSlotIndexToSubId[i][0] == subId) return i; 214 } 215 return INVALID_PHONE_INDEX; 216 } 217 @Override 218 public int clearSubInfo() { 219 throw new RuntimeException("not implemented"); 220 } 221 @Override 222 public int getDefaultSubId() { 223 throw new RuntimeException("not implemented"); 224 } 225 @Override 226 public void setDefaultSmsSubId(int subId) { 227 throw new RuntimeException("not implemented"); 228 } 229 @Override 230 public int getDefaultSmsSubId() { 231 throw new RuntimeException("not implemented"); 232 } 233 @Override 234 public void setDefaultVoiceSubId(int subId) { 235 throw new RuntimeException("not implemented"); 236 } 237 @Override 238 public int getDefaultVoiceSubId() { 239 throw new RuntimeException("not implemented"); 240 } 241 @Override 242 public void clearDefaultsForInactiveSubIds() { 243 throw new RuntimeException("not implemented"); 244 } 245 @Override 246 public List<SubscriptionInfo> getSubInfoUsingSlotIndexWithCheck(int slotId, boolean needCheck, 247 String callingPackage) { 248 throw new RuntimeException("not implemented"); 249 } 250 @Override 251 public void updatePhonesAvailability(Phone[] phones) { 252 throw new RuntimeException("not implemented"); 253 } 254 @Override 255 public int[] getActiveSubIdList() { 256 throw new RuntimeException("not implemented"); 257 } 258 @Override 259 public boolean isActiveSubId(int subId) { 260 throw new RuntimeException("not implemented"); 261 } 262 @Override 263 public int getSimStateForSlotIndex(int slotIndex) { 264 throw new RuntimeException("not implemented"); 265 } 266 @Override 267 public void setSubscriptionProperty(int subId, String propKey, String propValue) { 268 throw new RuntimeException("not implemented"); 269 } 270 @Override 271 public String getSubscriptionProperty(int subId, String propKey, String callingPackage) { 272 throw new RuntimeException("not implemented"); 273 } 274 @Override 275 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { 276 throw new RuntimeException("not implemented"); 277 } 278} 279