1 /* 2 * Copyright (C) 2019 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.euicc.cts; 18 19 import android.annotation.NonNull; 20 import android.annotation.Nullable; 21 import android.os.Bundle; 22 import android.service.euicc.DownloadSubscriptionResult; 23 import android.service.euicc.EuiccService; 24 import android.service.euicc.GetDefaultDownloadableSubscriptionListResult; 25 import android.service.euicc.GetDownloadableSubscriptionMetadataResult; 26 import android.service.euicc.GetEuiccProfileInfoListResult; 27 import android.telephony.euicc.DownloadableSubscription; 28 import android.telephony.euicc.EuiccInfo; 29 import android.telephony.euicc.EuiccManager; 30 import android.telephony.euicc.EuiccManager.OtaStatus; 31 32 /** Dummy implementation of {@link EuiccService} for testing. */ 33 public class MockEuiccService extends EuiccService { 34 static String MOCK_EID = "89000000000000000000000000000000"; 35 static String MOCK_OS_VERSION = "1.0"; 36 37 interface IMockEuiccServiceCallback { 38 void setMethodCalled(); 39 40 boolean isMethodCalled(); 41 42 void reset(); 43 } 44 45 private static IMockEuiccServiceCallback sMockEuiccServiceCallback; 46 47 static void setCallback(IMockEuiccServiceCallback callback) { 48 sMockEuiccServiceCallback = callback; 49 } 50 51 @Override 52 public String onGetEid(int slotId) { 53 sMockEuiccServiceCallback.setMethodCalled(); 54 return MOCK_EID; 55 } 56 57 @Override 58 public @OtaStatus int onGetOtaStatus(int slotId) { 59 sMockEuiccServiceCallback.setMethodCalled(); 60 return EuiccManager.EUICC_OTA_SUCCEEDED; 61 } 62 63 @Override 64 public void onStartOtaIfNecessary(int slotId, OtaStatusChangedCallback statusChangedCallback) { 65 sMockEuiccServiceCallback.setMethodCalled(); 66 statusChangedCallback.onOtaStatusChanged(EuiccManager.EUICC_OTA_SUCCEEDED); 67 } 68 69 @Override 70 public GetDownloadableSubscriptionMetadataResult onGetDownloadableSubscriptionMetadata( 71 int slotId, DownloadableSubscription subscription, boolean forceDeactivateSim) { 72 sMockEuiccServiceCallback.setMethodCalled(); 73 74 if (subscription.getEncodedActivationCode() != null) { 75 return new GetDownloadableSubscriptionMetadataResult( 76 EuiccService.RESULT_OK, subscription); 77 } else { 78 return new GetDownloadableSubscriptionMetadataResult( 79 EuiccService.RESULT_RESOLVABLE_ERRORS, null /*subscription*/); 80 } 81 } 82 83 @Override 84 public GetDefaultDownloadableSubscriptionListResult onGetDefaultDownloadableSubscriptionList( 85 int slotId, boolean forceDeactivateSim) { 86 sMockEuiccServiceCallback.setMethodCalled(); 87 88 return new GetDefaultDownloadableSubscriptionListResult( 89 EuiccService.RESULT_RESOLVABLE_ERRORS, null /*subscriptions*/); 90 } 91 92 @Override 93 public DownloadSubscriptionResult onDownloadSubscription( 94 int slotId, 95 @NonNull DownloadableSubscription subscription, 96 boolean switchAfterDownload, 97 boolean forceDeactivateSim, 98 @Nullable Bundle resolvedBundle) { 99 sMockEuiccServiceCallback.setMethodCalled(); 100 101 int cardId = 1; 102 103 if (subscription.getEncodedActivationCode() != null) { 104 return new DownloadSubscriptionResult( 105 EuiccService.RESULT_OK, 0 /*resolvableErrors*/, cardId); 106 } else { 107 return new DownloadSubscriptionResult( 108 EuiccService.RESULT_RESOLVABLE_ERRORS, 109 EuiccService.RESULT_RESOLVABLE_ERRORS, 110 cardId); 111 } 112 } 113 114 @Override 115 public @NonNull GetEuiccProfileInfoListResult onGetEuiccProfileInfoList(int slotId) { 116 sMockEuiccServiceCallback.setMethodCalled(); 117 return new GetEuiccProfileInfoListResult( 118 EuiccService.RESULT_RESOLVABLE_ERRORS, null /*profiles*/, false /*isRemovable*/); 119 } 120 121 @Override 122 public @NonNull EuiccInfo onGetEuiccInfo(int slotId) { 123 sMockEuiccServiceCallback.setMethodCalled(); 124 return new EuiccInfo(MOCK_OS_VERSION); 125 } 126 127 @Override 128 public @Result int onDeleteSubscription(int slotId, String iccid) { 129 sMockEuiccServiceCallback.setMethodCalled(); 130 return EuiccService.RESULT_OK; 131 } 132 133 @Override 134 public @Result int onSwitchToSubscription( 135 int slotId, @Nullable String iccid, boolean forceDeactivateSim) { 136 sMockEuiccServiceCallback.setMethodCalled(); 137 return EuiccService.RESULT_OK; 138 } 139 140 @Override 141 public int onUpdateSubscriptionNickname(int slotId, String iccid, String nickname) { 142 sMockEuiccServiceCallback.setMethodCalled(); 143 return EuiccService.RESULT_OK; 144 } 145 146 @Override 147 public int onEraseSubscriptions(int slotId) { 148 sMockEuiccServiceCallback.setMethodCalled(); 149 return EuiccService.RESULT_OK; 150 } 151 152 @Override 153 public int onRetainSubscriptionsForFactoryReset(int slotId) { 154 sMockEuiccServiceCallback.setMethodCalled(); 155 return EuiccService.RESULT_OK; 156 } 157 } 158